Skip to content

Commit

Permalink
Add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
koda-masaru committed Oct 4, 2017
1 parent cc3ae09 commit 48b59fb
Show file tree
Hide file tree
Showing 5 changed files with 352 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ public Boundary likecomment() throws InvalidParamException {
* @return
* @throws ParseException
*/
@Post
@Post(subscribeToken = "")
public Boundary escape(KnowledgesEntity entity) throws ParseException {
super.setSendEscapeHtml(false);
entity.setTitle(sanitize(entity.getTitle()));
Expand All @@ -706,7 +706,7 @@ public Boundary escape(KnowledgesEntity entity) throws ParseException {
* @return
* @throws ParseException
*/
@Post
@Post(subscribeToken = "")
public Boundary marked(KnowledgesEntity entity) throws ParseException {
super.setSendEscapeHtml(false);
entity.setTitle(sanitize(entity.getTitle()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class NotificationControl extends Control {

@Get
@Get(publishToken = "knowledge")
public Boundary list() throws InvalidParamException {
int offset = getPathInteger(0);
boolean all = "true".equals(getAttribute("all", "false"));
Expand All @@ -39,6 +39,7 @@ public Boundary view() throws InvalidParamException {
return sendError(HttpStatus.SC_403_FORBIDDEN, "FORBIDDEN");
}
NotificationLogic.get().setStatus(getLoginUserId(), no, NotificationLogic.STATUS_READED);
notification.setStatus(NotificationLogic.STATUS_READED);
setAttributeOnProperty(notification);
setAttribute("no", no);
return forward("view.jsp");
Expand All @@ -56,6 +57,7 @@ public Boundary previous() throws InvalidParamException {
}
no = notification.getNo();
NotificationLogic.get().setStatus(getLoginUserId(), no, NotificationLogic.STATUS_READED);
notification.setStatus(NotificationLogic.STATUS_READED);
setAttributeOnProperty(notification);
setAttribute("no", no);
return forward("view.jsp");
Expand All @@ -72,12 +74,13 @@ public Boundary next() throws InvalidParamException {
}
no = notification.getNo();
NotificationLogic.get().setStatus(getLoginUserId(), no, NotificationLogic.STATUS_READED);
notification.setStatus(NotificationLogic.STATUS_READED);
setAttributeOnProperty(notification);
setAttribute("no", no);
return forward("view.jsp");
}

@Post
@Post(subscribeToken = "knowledge")
public Boundary markread() {
String no = getAttribute("no", "");
NotificationLogic.get().markAllAsRead(no, getLoginUserId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,23 @@
import org.support.project.knowledge.config.AppConfig;
import org.support.project.knowledge.config.AuthType;
import org.support.project.knowledge.dao.NotifyQueuesDao;
import org.support.project.knowledge.dao.TemplateItemsDao;
import org.support.project.knowledge.entity.CommentsEntity;
import org.support.project.knowledge.entity.NotifyQueuesEntity;
import org.support.project.knowledge.logic.EventsLogic;
import org.support.project.knowledge.logic.KnowledgeLogic;
import org.support.project.knowledge.logic.TargetLogic;
import org.support.project.knowledge.logic.TemplateLogic;
import org.support.project.knowledge.vo.LikeCount;
import org.support.project.knowledge.vo.api.Knowledge;
import org.support.project.web.bean.LoginedUser;
import org.support.project.web.bean.MessageResult;
import org.support.project.web.bean.Msg;
import org.support.project.web.bean.NameId;
import org.support.project.web.boundary.ForwardBoundary;
import org.support.project.web.boundary.JsonBoundary;
import org.support.project.web.boundary.RedirectBoundary;
import org.support.project.web.boundary.SendMessageBoundary;
import org.support.project.web.common.HttpStatus;
import org.support.project.web.common.InvokeTarget;
import org.support.project.web.dao.MailConfigsDao;
import org.support.project.web.entity.MailConfigsEntity;
Expand Down Expand Up @@ -104,6 +109,62 @@ protected <T> T invoke(HttpServletRequest request, HttpServletResponse response,
}
return (T) result;
}


/**
* 投稿
* @return
* @throws Exception
* @throws NoSuchFieldException
* @throws IllegalAccessException
*/
protected MessageResult postKnowledge(String userKey, int publicFlag, int typeId, String viewers) throws Exception, NoSuchFieldException, IllegalAccessException {
// 登録画面へアクセスできること(パスのルーティングのみ確認)
StubHttpServletRequest request = new StubHttpServletRequest();
StubHttpServletResponse response = new StubHttpServletResponse(request);
request.setServletPath("protect.knowledge/view_add");
request.setMethod("get");
DefaultAuthenticationLogicImpl auth = org.support.project.di.Container.getComp(DefaultAuthenticationLogicImpl.class);
auth.setSession(userKey, request, response);

ForwardBoundary boundary = invoke(request, response, ForwardBoundary.class);
Assert.assertEquals("/WEB-INF/views/protect/knowledge/edit.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, boundary, "path"));

String csrfToken = (String) request.getAttribute(HttpRequestCheckLogic.REQ_ID_KEY);
Assert.assertNotNull(csrfToken);

// 保存
request.setServletPath("protect.knowledge/save");
request.setMethod("post");
request.addParameter(HttpRequestCheckLogic.REQ_ID_KEY, csrfToken);
request.addParameter("title", "タイトル");
request.addParameter("content", "内容");
request.addParameter("publicFlag", String.valueOf(publicFlag));
request.addParameter("typeId", String.valueOf(typeId));

if (typeId == TemplateLogic.TYPE_ID_BOOKMARK) {
request.addParameter("item_" + TemplateItemsDao.ITEM_ID_BOOKMARK_URL, "https://information-supportproject.org/");
} else if (typeId == TemplateLogic.TYPE_ID_EVENT) {
request.addParameter("item_" + EventsLogic.ITEM_NO_DATE, "2017-10-01");
request.addParameter("item_" + EventsLogic.ITEM_NO_START, "10:00");
request.addParameter("item_" + EventsLogic.ITEM_NO_END, "12:00");
request.addParameter("item_" + EventsLogic.ITEM_NO_TIMEZONE, "Asia/Tokyo");
request.addParameter("item_" + EventsLogic.ITEM_NO_THE_NUMBER_TO_BE_ACCEPTED, "10");
}

if (publicFlag == KnowledgeLogic.PUBLIC_FLAG_PROTECT) {
if (StringUtils.isNotEmpty(viewers)) {
request.addParameter("groups", viewers);
}
}

JsonBoundary jsonBoundary = invoke(request, response, JsonBoundary.class);
MessageResult sendObject = (MessageResult) jsonBoundary.getObj();
LOG.info(sendObject);
Assert.assertEquals(200, sendObject.getCode().intValue());
return sendObject;
}

/**
* CP確認
* @param userKey
Expand Down Expand Up @@ -386,7 +447,7 @@ protected CommentsEntity getLatestComment(String userKey, long knowledgeId) thro
*/
protected void execNotificationQueue() throws Exception {
List<NotifyQueuesEntity> list = NotifyQueuesDao.get().selectAll();
Assert.assertEquals(1, list.size());
Assert.assertTrue(0 < list.size());
NotifyMailBat.main(null);
list = NotifyQueuesDao.get().selectAll();
Assert.assertEquals(0, list.size());
Expand Down
Loading

0 comments on commit 48b59fb

Please sign in to comment.