diff --git a/src/main/java/org/support/project/knowledge/control/open/KnowledgeControl.java b/src/main/java/org/support/project/knowledge/control/open/KnowledgeControl.java index f26c4a341..f05558c33 100644 --- a/src/main/java/org/support/project/knowledge/control/open/KnowledgeControl.java +++ b/src/main/java/org/support/project/knowledge/control/open/KnowledgeControl.java @@ -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())); @@ -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())); diff --git a/src/main/java/org/support/project/knowledge/control/protect/GroupControl.java b/src/main/java/org/support/project/knowledge/control/protect/GroupControl.java index 1708e5625..2b372511a 100644 --- a/src/main/java/org/support/project/knowledge/control/protect/GroupControl.java +++ b/src/main/java/org/support/project/knowledge/control/protect/GroupControl.java @@ -16,7 +16,6 @@ import org.support.project.knowledge.logic.GroupLogic; import org.support.project.knowledge.vo.GroupUser; import org.support.project.knowledge.vo.StringList; -import org.support.project.web.annotation.Auth; import org.support.project.web.bean.LabelValue; import org.support.project.web.bean.LoginedUser; import org.support.project.web.bean.MessageResult; diff --git a/src/main/java/org/support/project/knowledge/control/protect/KnowledgeControl.java b/src/main/java/org/support/project/knowledge/control/protect/KnowledgeControl.java index 31686311c..ca718c00c 100644 --- a/src/main/java/org/support/project/knowledge/control/protect/KnowledgeControl.java +++ b/src/main/java/org/support/project/knowledge/control/protect/KnowledgeControl.java @@ -487,12 +487,9 @@ public Boundary comment() throws Exception { } } setAttribute("comment_files", files); - return super.devolution(HttpMethod.get, "open.Knowledge/view", String.valueOf(knowledgeId)); } - - CommentsEntity commentsEntity = KnowledgeLogic.get().saveComment(knowledgeId, comment, fileNos, getLoginedUser()); - + KnowledgeLogic.get().saveComment(knowledgeId, comment, fileNos, getLoginedUser()); return super.redirect(getRequest().getContextPath() + "/open.knowledge/view/" + knowledgeId + params); } diff --git a/src/main/java/org/support/project/knowledge/control/protect/NotificationControl.java b/src/main/java/org/support/project/knowledge/control/protect/NotificationControl.java index 1714078ec..02d22b122 100644 --- a/src/main/java/org/support/project/knowledge/control/protect/NotificationControl.java +++ b/src/main/java/org/support/project/knowledge/control/protect/NotificationControl.java @@ -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")); @@ -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"); @@ -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"); @@ -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()); diff --git a/src/main/java/org/support/project/knowledge/logic/activity/KnowledgeAnswerActivity.java b/src/main/java/org/support/project/knowledge/logic/activity/KnowledgeAnswerActivity.java index ad01b0bf3..773c3240c 100644 --- a/src/main/java/org/support/project/knowledge/logic/activity/KnowledgeAnswerActivity.java +++ b/src/main/java/org/support/project/knowledge/logic/activity/KnowledgeAnswerActivity.java @@ -28,8 +28,8 @@ private int getPoint() { } //int[] points = {1,1,2,2,2,2,3,3,3,4}; //this.point = points[RandomUtil.randamNum(0, 10)]; // ランダムで値を増減してみた - //return point; - return 3; + this.point = 3; + return point; } @Override diff --git a/src/main/java/org/support/project/knowledge/logic/activity/KnowledgeStockActivity.java b/src/main/java/org/support/project/knowledge/logic/activity/KnowledgeStockActivity.java index 7e54fe9c3..200078cb6 100644 --- a/src/main/java/org/support/project/knowledge/logic/activity/KnowledgeStockActivity.java +++ b/src/main/java/org/support/project/knowledge/logic/activity/KnowledgeStockActivity.java @@ -2,7 +2,6 @@ import org.support.project.common.log.Log; import org.support.project.common.log.LogFactory; -import org.support.project.common.util.RandomUtil; import org.support.project.di.Container; import org.support.project.di.DI; import org.support.project.di.Instance; @@ -28,8 +27,9 @@ private int getPoint() { if (point != 0) { return point; } - int[] points = {1,1,1,1,1,2,2,2,2,3}; - this.point = points[RandomUtil.randamNum(0, 10)]; // ランダムで値を増減してみた +// int[] points = {1,1,1,1,1,2,2,2,2,3}; +// this.point = points[RandomUtil.randamNum(0, 10)]; // ランダムで値を増減してみた + this.point = 2; return point; } diff --git a/src/test/java/org/support/project/knowledge/integration/IntegrationCommon.java b/src/test/java/org/support/project/knowledge/integration/IntegrationCommon.java index 2637ca3f2..2374a1337 100644 --- a/src/test/java/org/support/project/knowledge/integration/IntegrationCommon.java +++ b/src/test/java/org/support/project/knowledge/integration/IntegrationCommon.java @@ -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.TemplateLogic; +import org.support.project.knowledge.vo.ActivityHistory; 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; @@ -90,6 +95,7 @@ public static void setUpBeforeClass() throws Exception { * @return * @throws Exception */ + @SuppressWarnings("unchecked") protected T invoke(HttpServletRequest request, HttpServletResponse response, Class clazz) throws Exception { InvokeTarget invoke = CallControlLogic.get().searchInvokeTarget(request, response); if (invoke == null) { @@ -104,6 +110,62 @@ protected 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 @@ -171,6 +233,7 @@ protected void assertNotificationCount(String userKey, int add) throws Exception * @return * @throws Exception */ + @SuppressWarnings("unchecked") protected List getNotification(String userKey) throws Exception { StubHttpServletRequest request = new StubHttpServletRequest(); StubHttpServletResponse response = new StubHttpServletResponse(request); @@ -339,6 +402,7 @@ protected void addLatestLikeComment(String userKey, long knowledgeId) throws Exc * @param comment * @throws Exception */ + @SuppressWarnings("unchecked") protected void comment(String userKey, long knowledgeId, String comment) throws Exception { if (userKey == null) { Assert.fail("post comment must be logined"); @@ -372,6 +436,7 @@ protected void comment(String userKey, long knowledgeId, String comment) throws * @return * @throws Exception */ + @SuppressWarnings("unchecked") protected CommentsEntity getLatestComment(String userKey, long knowledgeId) throws Exception { StubHttpServletRequest request = openKnowledge(userKey, knowledgeId); List comments = (List) request.getAttribute("comments"); @@ -386,7 +451,7 @@ protected CommentsEntity getLatestComment(String userKey, long knowledgeId) thro */ protected void execNotificationQueue() throws Exception { List 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()); @@ -480,6 +545,7 @@ protected void knowledgeDeleteOnAPI(String userKey, long knowledgeId) throws Exc * @return * @throws Exception */ + @SuppressWarnings("unchecked") protected Knowledge knowledgeGetOnAPI(String userKey, int count) throws Exception { StubHttpServletRequest request = new StubHttpServletRequest(); StubHttpServletResponse response = new StubHttpServletResponse(request); @@ -515,6 +581,24 @@ protected Knowledge knowledgeGetOnAPI(String userKey, int count) throws Exceptio return null; } - + /** + * CPの獲得履歴の件数確認 + * @param userKey + * @throws Exception + */ + @SuppressWarnings("unchecked") + protected void assertPointHistoryCount(String userKey, int count) throws Exception { + StubHttpServletRequest request = new StubHttpServletRequest(); + StubHttpServletResponse response = new StubHttpServletResponse(request); + DefaultAuthenticationLogicImpl auth = org.support.project.di.Container.getComp(DefaultAuthenticationLogicImpl.class); + auth.setSession(userKey, request, response); + + LoginedUser user = getLoginUser(userKey); + request.setServletPath("open.account/activity/" + user.getUserId()); + request.setMethod("get"); + JsonBoundary jsonBoundary = invoke(request, response, JsonBoundary.class); + List list = (List) jsonBoundary.getObj(); + Assert.assertEquals(count, list.size()); + } } diff --git a/src/test/java/org/support/project/knowledge/integration/IntegrationEventTest.java b/src/test/java/org/support/project/knowledge/integration/IntegrationEventTest.java index 14a7184cb..6bad318ab 100644 --- a/src/test/java/org/support/project/knowledge/integration/IntegrationEventTest.java +++ b/src/test/java/org/support/project/knowledge/integration/IntegrationEventTest.java @@ -117,6 +117,7 @@ public void testAssertAfterPost() throws Exception { public void testJoinByJoinUser() throws Exception { StubHttpServletRequest request = openKnowledges(JOIN_USER); StubHttpServletResponse response = new StubHttpServletResponse(request); + @SuppressWarnings("unchecked") List knowledges = (List) request.getAttribute("knowledges"); long knowledgeId = knowledges.get(0).getKnowledgeId(); request = openKnowledge(JOIN_USER, knowledgeId); @@ -153,6 +154,7 @@ public void testAssertAfterJoinbyJoinUser() throws Exception { public void testReaveByJoinUser() throws Exception { StubHttpServletRequest request = openKnowledges(JOIN_USER); StubHttpServletResponse response = new StubHttpServletResponse(request); + @SuppressWarnings("unchecked") List knowledges = (List) request.getAttribute("knowledges"); long knowledgeId = knowledges.get(0).getKnowledgeId(); request = openKnowledge(JOIN_USER, knowledgeId); @@ -190,6 +192,7 @@ public void testAssertAfterReavebyJoinUser() throws Exception { public void testReJoinByJoinUser() throws Exception { StubHttpServletRequest request = openKnowledges(JOIN_USER); StubHttpServletResponse response = new StubHttpServletResponse(request); + @SuppressWarnings("unchecked") List knowledges = (List) request.getAttribute("knowledges"); long knowledgeId = knowledges.get(0).getKnowledgeId(); request = openKnowledge(JOIN_USER, knowledgeId); @@ -226,6 +229,7 @@ public void testAssertAfterReJoinbyJoinUser() throws Exception { public void testJoinByPostUser() throws Exception { StubHttpServletRequest request = openKnowledges(POST_USER); StubHttpServletResponse response = new StubHttpServletResponse(request); + @SuppressWarnings("unchecked") List knowledges = (List) request.getAttribute("knowledges"); long knowledgeId = knowledges.get(0).getKnowledgeId(); request = openKnowledge(POST_USER, knowledgeId); @@ -252,5 +256,17 @@ public void testAssertAfterJoinbyPostUser() throws Exception { assertNotificationCount(POST_USER, 2); assertNotificationCount(JOIN_USER, 0); } - + + + + /** + * CP獲得履歴 + * @throws Exception + */ + @Test + @Order(order = 600) + public void testActivityHistory() throws Exception { + assertPointHistoryCount(POST_USER, 4); + assertPointHistoryCount(JOIN_USER, 2); + } } diff --git a/src/test/java/org/support/project/knowledge/integration/IntegrationNotificationTest.java b/src/test/java/org/support/project/knowledge/integration/IntegrationNotificationTest.java new file mode 100644 index 000000000..3fd9297ff --- /dev/null +++ b/src/test/java/org/support/project/knowledge/integration/IntegrationNotificationTest.java @@ -0,0 +1,282 @@ +package org.support.project.knowledge.integration; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.support.project.common.log.Log; +import org.support.project.common.log.LogFactory; +import org.support.project.common.test.Order; +import org.support.project.common.util.PropertyUtil; +import org.support.project.common.util.StringJoinBuilder; +import org.support.project.knowledge.logic.KnowledgeLogic; +import org.support.project.knowledge.logic.TemplateLogic; +import org.support.project.web.boundary.ForwardBoundary; +import org.support.project.web.boundary.JsonBoundary; +import org.support.project.web.entity.NotificationsEntity; +import org.support.project.web.logic.impl.DefaultAuthenticationLogicImpl; +import org.support.project.web.test.stub.StubHttpServletRequest; +import org.support.project.web.test.stub.StubHttpServletResponse; + +/** + * + * @author koda + */ +public class IntegrationNotificationTest extends IntegrationCommon { + /** ログ */ + private static final Log LOG = LogFactory.getLog(IntegrationNotificationTest.class); + + private static final String POST_USER = "integration-test-user-01"; + private static final String READ_USER = "integration-test-user-02"; + + private List getList(String userKey, StubHttpServletRequest request, StubHttpServletResponse response, boolean all) throws Exception { + request.setServletPath("protect.notification/list"); + request.setMethod("get"); + DefaultAuthenticationLogicImpl auth = org.support.project.di.Container.getComp(DefaultAuthenticationLogicImpl.class); + auth.setSession(userKey, request, response); + if (all) { + request.addParameter("all", "true"); + } + + ForwardBoundary boundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/notification/list.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, boundary, "path")); + + @SuppressWarnings("unchecked") + List notifications = (List) request.getAttribute("notifications"); + return notifications; + } + + /** + * ユーザを登録 + * + * @throws Exception + */ + @Test + @Order(order = 1) + public void testUserInsert() throws Exception { + LOG.info("ユーザ登録"); + addUser(POST_USER); + addUser(READ_USER); + } + + /** + * 「公開」の記事登録(通知の登録) + * @throws Exception + */ + @Test + @Order(order = 100) + public void testNotification() throws Exception { + // 投稿 + postKnowledge( + POST_USER, + KnowledgeLogic.PUBLIC_FLAG_PUBLIC, + TemplateLogic.TYPE_ID_KNOWLEDGE, + null); + // 通知 + execNotificationQueue(); + + // 通知にアクセス(List) + StubHttpServletRequest request = new StubHttpServletRequest(); + StubHttpServletResponse response = new StubHttpServletResponse(request); + List notifications = getList(READ_USER, request, response, false); + Assert.assertEquals(1, notifications.size()); + + NotificationsEntity notification = notifications.get(0); + Assert.assertEquals(0, notification.getStatus()); + + // 通知を表示 + request.setServletPath("protect.notification/view/" + notification.getNo()); + ForwardBoundary boundary2 = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/notification/view.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, boundary2, "path")); + + Assert.assertEquals(1, request.getAttribute("status")); + } + + + /** + * 「公開」の記事登録(通知の登録) + * @throws Exception + */ + @Test + @Order(order = 101) + public void testReadAll() throws Exception { + // 投稿 + for (int i = 0; i < 10; i++) { + postKnowledge( + POST_USER, + KnowledgeLogic.PUBLIC_FLAG_PUBLIC, + TemplateLogic.TYPE_ID_KNOWLEDGE, + null); + } + // 通知 + execNotificationQueue(); + + // 通知にアクセス(List) + StubHttpServletRequest request = new StubHttpServletRequest(); + StubHttpServletResponse response = new StubHttpServletResponse(request); + List notifications = getList(READ_USER, request, response, false); + Assert.assertEquals(10, notifications.size()); + + // 全て既読へ + StringJoinBuilder builder = new StringJoinBuilder<>(); + for (NotificationsEntity notificationsEntity : notifications) { + builder.append(notificationsEntity.getNo()); + } + + request.setServletPath("protect.notification/markread"); + request.setMethod("post"); + request.addParameter("no", builder.join(",")); + JsonBoundary jsonBoundary = invoke(request, response, JsonBoundary.class); + Assert.assertEquals("OK", jsonBoundary.getObj()); + + // 通知にアクセス(List) + notifications = getList(READ_USER, request, response, false); + Assert.assertEquals(0, notifications.size()); + + // 通知にアクセス(List) + notifications = getList(READ_USER, request, response, true); + Assert.assertEquals(11, notifications.size()); + } + + + /** + * 次へのボタンの操作 + * @throws Exception + */ + @Test + @Order(order = 102) + public void testNext() throws Exception { + // 投稿 + for (int i = 0; i < 3; i++) { + postKnowledge( + POST_USER, + KnowledgeLogic.PUBLIC_FLAG_PUBLIC, + TemplateLogic.TYPE_ID_KNOWLEDGE, + null); + } + // 通知 + execNotificationQueue(); + + // 通知にアクセス(List) + StubHttpServletRequest request = new StubHttpServletRequest(); + StubHttpServletResponse response = new StubHttpServletResponse(request); + List notifications = getList(READ_USER, request, response, false); + Assert.assertEquals(3, notifications.size()); + + // 通知を表示 + NotificationsEntity notification = notifications.get(2); + request.setServletPath("protect.notification/view/" + notification.getNo()); + ForwardBoundary boundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/notification/view.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, boundary, "path")); + Assert.assertEquals(1, request.getAttribute("status")); + Assert.assertEquals(notification.getNo(), request.getAttribute("no")); + + // Nextをクリック + request.setServletPath("protect.notification/next/" + notification.getNo()); + boundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/notification/view.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, boundary, "path")); + Assert.assertEquals(1, request.getAttribute("status")); + notification = notifications.get(1); + Assert.assertEquals(notification.getNo(), request.getAttribute("no")); + + // Nextをクリック + request.setServletPath("protect.notification/next/" + notification.getNo()); + boundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/notification/view.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, boundary, "path")); + Assert.assertEquals(1, request.getAttribute("status")); + notification = notifications.get(0); + Assert.assertEquals(notification.getNo(), request.getAttribute("no")); + + // Nextをクリック + request.setServletPath("protect.notification/next/" + notification.getNo()); + boundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/notification/not_found.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, boundary, "path")); + + // リストの先頭に戻ってNextをクリック + notification = notifications.get(2); + request.setServletPath("protect.notification/next/" + notification.getNo()); + boundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/notification/not_found.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, boundary, "path")); + + // 全てを表示のモードでNextをクリック + request.setServletPath("protect.notification/next/" + notification.getNo()); + request.addParameter("all", "true"); + boundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/notification/view.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, boundary, "path")); + Assert.assertEquals(1, request.getAttribute("status")); + notification = notifications.get(1); + Assert.assertEquals(notification.getNo(), request.getAttribute("no")); + } + + + /** + * 前へのボタンの操作 + * @throws Exception + */ + @Test + @Order(order = 103) + public void testPrevious() throws Exception { + // 投稿 + for (int i = 0; i < 3; i++) { + postKnowledge( + POST_USER, + KnowledgeLogic.PUBLIC_FLAG_PUBLIC, + TemplateLogic.TYPE_ID_KNOWLEDGE, + null); + } + // 通知 + execNotificationQueue(); + + // 通知にアクセス(List) + StubHttpServletRequest request = new StubHttpServletRequest(); + StubHttpServletResponse response = new StubHttpServletResponse(request); + List notifications = getList(READ_USER, request, response, false); + Assert.assertEquals(3, notifications.size()); + + // 通知を表示 + NotificationsEntity notification = notifications.get(0); + request.setServletPath("protect.notification/view/" + notification.getNo()); + ForwardBoundary boundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/notification/view.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, boundary, "path")); + Assert.assertEquals(1, request.getAttribute("status")); + Assert.assertEquals(notification.getNo(), request.getAttribute("no")); + + // previousをクリック + request.setServletPath("protect.notification/previous/" + notification.getNo()); + boundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/notification/view.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, boundary, "path")); + Assert.assertEquals(1, request.getAttribute("status")); + notification = notifications.get(1); + Assert.assertEquals(notification.getNo(), request.getAttribute("no")); + + // previousをクリック + request.setServletPath("protect.notification/previous/" + notification.getNo()); + boundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/notification/view.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, boundary, "path")); + Assert.assertEquals(1, request.getAttribute("status")); + notification = notifications.get(2); + Assert.assertEquals(notification.getNo(), request.getAttribute("no")); + + // previousをクリック + request.setServletPath("protect.notification/previous/" + notification.getNo()); + boundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/notification/not_found.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, boundary, "path")); + + // リストの先頭に戻ってpreviousをクリック + notification = notifications.get(0); + request.setServletPath("protect.notification/previous/" + notification.getNo()); + boundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/notification/not_found.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, boundary, "path")); + + // 全てを表示のモードでpreviousをクリック + request.setServletPath("protect.notification/previous/" + notification.getNo()); + request.addParameter("all", "true"); + boundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/notification/view.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, boundary, "path")); + Assert.assertEquals(1, request.getAttribute("status")); + notification = notifications.get(1); + Assert.assertEquals(notification.getNo(), request.getAttribute("no")); + } + + +} diff --git a/src/test/java/org/support/project/knowledge/integration/IntegrationPostTest.java b/src/test/java/org/support/project/knowledge/integration/IntegrationPostTest.java index e93f68c88..c39e628c3 100644 --- a/src/test/java/org/support/project/knowledge/integration/IntegrationPostTest.java +++ b/src/test/java/org/support/project/knowledge/integration/IntegrationPostTest.java @@ -57,6 +57,7 @@ public void testUserInsert() throws Exception { @Order(order = 2) public void testAccessListByNoLoginUser() throws Exception { StubHttpServletRequest request = openKnowledges(null); + @SuppressWarnings("unchecked") List knowledges = (List) request.getAttribute("knowledges"); Assert.assertNotNull(knowledges); Assert.assertEquals(0, knowledges.size()); @@ -71,6 +72,7 @@ public void testAccessListByNoLoginUser() throws Exception { @Order(order = 3) public void testAccessListByLoginedUser() throws Exception { StubHttpServletRequest request = openKnowledges(COMMENT_POST_USER); + @SuppressWarnings("unchecked") List knowledges = (List) request.getAttribute("knowledges"); Assert.assertNotNull(knowledges); Assert.assertEquals(0, knowledges.size()); @@ -93,6 +95,7 @@ public void testInitNotificationByLoginedUser() throws Exception { ForwardBoundary boundary = invoke(request, response, ForwardBoundary.class); Assert.assertEquals("/WEB-INF/views/protect/notification/list.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, boundary, "path")); + @SuppressWarnings("unchecked") List notifications = (List) request.getAttribute("notifications"); Assert.assertNotNull(notifications); Assert.assertEquals(0, notifications.size()); @@ -177,6 +180,7 @@ public void testCPAfterPost() throws Exception { public void testAccessListByNoLoginUser2() throws Exception { // 一覧表示画面を開き、 StubHttpServletRequest request = openKnowledges(null); + @SuppressWarnings("unchecked") List knowledges = (List) request.getAttribute("knowledges"); Assert.assertNotNull(knowledges); Assert.assertEquals(1, knowledges.size()); @@ -201,6 +205,7 @@ public void testAccessListByNoLoginUser2() throws Exception { public void testAccessListByLoginedUser2() throws Exception { // 一覧表示画面を開き、 StubHttpServletRequest request = openKnowledges(COMMENT_POST_USER); + @SuppressWarnings("unchecked") List knowledges = (List) request.getAttribute("knowledges"); Assert.assertNotNull(knowledges); Assert.assertEquals(1, knowledges.size()); @@ -237,6 +242,7 @@ public void testCPAfterRead() throws Exception { public void testReAccessListByLoginedUser2() throws Exception { // 一覧表示画面を開き、 StubHttpServletRequest request = openKnowledges(COMMENT_POST_USER); + @SuppressWarnings("unchecked") List knowledges = (List) request.getAttribute("knowledges"); Assert.assertNotNull(knowledges); Assert.assertEquals(1, knowledges.size()); @@ -447,6 +453,7 @@ public void testReLikeByLoginUser1() throws Exception { * コメント登録者でコメント登録 * @throws Exception */ + @SuppressWarnings("unchecked") @Test @Order(order = 400) public void testPostCommentByLoginUser1() throws Exception { @@ -648,5 +655,15 @@ public void testLikeCommentByNotLoginToKnowledgeUser() throws Exception { assertNotificationCount(KNOWLEDGE_POST_USER, 1); } + /** + * CP獲得履歴 + * @throws Exception + */ + @Test + @Order(order = 600) + public void testActivityHistory() throws Exception { + assertPointHistoryCount(KNOWLEDGE_POST_USER, 9); + assertPointHistoryCount(COMMENT_POST_USER, 6); + } } diff --git a/src/test/java/org/support/project/knowledge/integration/IntegrationStockTest.java b/src/test/java/org/support/project/knowledge/integration/IntegrationStockTest.java new file mode 100644 index 000000000..2d88bfce5 --- /dev/null +++ b/src/test/java/org/support/project/knowledge/integration/IntegrationStockTest.java @@ -0,0 +1,398 @@ +package org.support.project.knowledge.integration; + +import java.io.ByteArrayInputStream; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.support.project.common.log.Log; +import org.support.project.common.log.LogFactory; +import org.support.project.common.test.Order; +import org.support.project.common.util.PropertyUtil; +import org.support.project.knowledge.dao.NotifyQueuesDao; +import org.support.project.knowledge.entity.NotifyQueuesEntity; +import org.support.project.knowledge.entity.StockKnowledgesEntity; +import org.support.project.knowledge.entity.StocksEntity; +import org.support.project.knowledge.logic.KnowledgeLogic; +import org.support.project.knowledge.logic.TemplateLogic; +import org.support.project.knowledge.vo.Stock; +import org.support.project.web.bean.MessageResult; +import org.support.project.web.boundary.ForwardBoundary; +import org.support.project.web.boundary.JsonBoundary; +import org.support.project.web.logic.impl.DefaultAuthenticationLogicImpl; +import org.support.project.web.test.stub.StubHttpServletRequest; +import org.support.project.web.test.stub.StubHttpServletResponse; + + +/** + * + * @author koda + */ +public class IntegrationStockTest extends IntegrationCommon { + /** ログ */ + private static final Log LOG = LogFactory.getLog(IntegrationStockTest.class); + + private static final String POST_USER = "integration-test-user-01"; + private static final String STOCK_USER = "integration-test-user-02"; + + private static long knowledgeId; + private static long stockId; + + /** + * ユーザを登録 + * + * @throws Exception + */ + @Test + @Order(order = 1) + public void testUserInsert() throws Exception { + LOG.info("ユーザ登録"); + addUser(POST_USER); + addUser(STOCK_USER); + } + + /** + * 記事登録 + * @throws Exception + */ + @Test + @Order(order = 100) + public void testPost() throws Exception { + MessageResult msg = postKnowledge( + POST_USER, + KnowledgeLogic.PUBLIC_FLAG_PUBLIC, + TemplateLogic.TYPE_ID_KNOWLEDGE, + null); + + knowledgeId = new Long(msg.getResult()); + + assertKnowledgeCP(POST_USER, knowledgeId, 50); + assertKnowledgeCP(STOCK_USER, knowledgeId, 1); + assertCP(POST_USER, 51); + assertCP(STOCK_USER, 1); + execNotificationQueue(); + assertNotificationCount(POST_USER, 1); + assertNotificationCount(STOCK_USER, 1); + } + + /** + * ストックが無いことを確認 + * @throws Exception + */ + @SuppressWarnings("unchecked") + @Test + @Order(order = 101) + public void testCheckListEmpty() throws Exception { + StubHttpServletRequest request = new StubHttpServletRequest(); + StubHttpServletResponse response = new StubHttpServletResponse(request); + DefaultAuthenticationLogicImpl auth = org.support.project.di.Container.getComp(DefaultAuthenticationLogicImpl.class); + auth.setSession(STOCK_USER, request, response); + + // ストック一覧は無い + request.setServletPath("protect.stock/mylist"); + request.setMethod("get"); + ForwardBoundary forwardBoundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/stock/list.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, forwardBoundary, "path")); + List stocks = (List) request.getAttribute("stocks"); + Assert.assertEquals(0, stocks.size()); + } + + + /** + * ストックを作成 + * @throws Exception + */ + @SuppressWarnings("unchecked") + @Test + @Order(order = 200) + public void testCreateStock() throws Exception { + StubHttpServletRequest request = new StubHttpServletRequest(); + StubHttpServletResponse response = new StubHttpServletResponse(request); + DefaultAuthenticationLogicImpl auth = org.support.project.di.Container.getComp(DefaultAuthenticationLogicImpl.class); + auth.setSession(STOCK_USER, request, response); + + // Stock一覧を取得 + request.setServletPath("protect.stock/chooselist"); + request.setMethod("get"); + JsonBoundary jsonBoundary = invoke(request, response, JsonBoundary.class); + List stocks = (List) jsonBoundary.getObj(); + Assert.assertEquals(0, stocks.size()); + + // Stock登録画面を表示 + request.setServletPath("protect.stock/add"); + request.setMethod("get"); + ForwardBoundary forwardBoundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/stock/add.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, forwardBoundary, "path")); + + // Stock登録 + request = new StubHttpServletRequest(request); + response = new StubHttpServletResponse(request); + request.setServletPath("protect.stock/insert"); + request.setMethod("post"); + request.addParameter("stockName", "Stock"); + forwardBoundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/stock/edit.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, forwardBoundary, "path")); + + // 一覧再取得 + request.setServletPath("protect.stock/chooselist"); + request.setMethod("get"); + jsonBoundary = invoke(request, response, JsonBoundary.class); + stocks = (List) jsonBoundary.getObj(); + Assert.assertEquals(1, stocks.size()); + stockId = stocks.get(0).getStockId(); + } + + /** + * ストックに何も登録していないことを確認 + * @throws Exception + */ + @SuppressWarnings("unchecked") + @Test + @Order(order = 201) + public void testCheckStockEmpty() throws Exception { + StubHttpServletRequest request = new StubHttpServletRequest(); + StubHttpServletResponse response = new StubHttpServletResponse(request); + DefaultAuthenticationLogicImpl auth = org.support.project.di.Container.getComp(DefaultAuthenticationLogicImpl.class); + auth.setSession(STOCK_USER, request, response); + + // ストック一覧は無い + request.setServletPath("protect.stock/knowledge"); + request.setMethod("get"); + request.setAttribute("stockId", String.valueOf(stockId)); + request.setAttribute("offset", "0"); + ForwardBoundary forwardBoundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/stock/knowledge.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, forwardBoundary, "path")); + List knowledges = (List) request.getAttribute("knowledges"); + Assert.assertEquals(0, knowledges.size()); + } + + + /** + * ストックに入れる + * @throws Exception + */ + @SuppressWarnings("unchecked") + @Test + @Order(order = 300) + public void testStock() throws Exception { + // 記事を開く + StubHttpServletRequest request = openKnowledge(STOCK_USER, knowledgeId); + StubHttpServletResponse response = new StubHttpServletResponse(request); + + // Stockの一覧を取得 + request = new StubHttpServletRequest(request); + response = new StubHttpServletResponse(request); + request.setServletPath("protect.stock/chooselist"); + request.setMethod("get"); + JsonBoundary jsonBoundary = invoke(request, response, JsonBoundary.class); + List stocks = (List) jsonBoundary.getObj(); + Assert.assertEquals(1, stocks.size()); + + // 記事をStock + request.setServletPath("protect.knowledge/stock/" + knowledgeId); + request.setMethod("Post"); + String json = "[{\"description\":\"\",\"stockId\":" + + stocks.get(0).getStockId() + + ",\"stockName\":\"Stock\",\"stockType\":0,\"stocked\":true}]"; + request.setInputstream(new ByteArrayInputStream(json.getBytes())); + jsonBoundary = invoke(request, response, JsonBoundary.class); + LOG.info(jsonBoundary.getObj()); + } + + /** + * ストックに入ったことを確認 + * @throws Exception + */ + @SuppressWarnings("unchecked") + @Test + @Order(order = 301) + public void testCheckStockStored() throws Exception { + StubHttpServletRequest request = new StubHttpServletRequest(); + StubHttpServletResponse response = new StubHttpServletResponse(request); + DefaultAuthenticationLogicImpl auth = org.support.project.di.Container.getComp(DefaultAuthenticationLogicImpl.class); + auth.setSession(STOCK_USER, request, response); + + // ストック一覧は無い + request.setServletPath("protect.stock/knowledge"); + request.setMethod("get"); + request.setAttribute("stockId", String.valueOf(stockId)); + request.setAttribute("offset", "0"); + ForwardBoundary forwardBoundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/stock/knowledge.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, forwardBoundary, "path")); + List knowledges = (List) request.getAttribute("knowledges"); + Assert.assertEquals(1, knowledges.size()); + } + + + /** + * ストック後の状態確認 + * @throws Exception + */ + @Test + @Order(order = 302) + public void testAssertAfterStock() throws Exception { + assertKnowledgeCP(POST_USER, knowledgeId, 2); + assertCP(POST_USER, 2); + assertCP(STOCK_USER, 0); + List list = NotifyQueuesDao.get().selectAll(); + Assert.assertEquals(0, list.size()); + assertNotificationCount(POST_USER, 0); + assertNotificationCount(STOCK_USER, 0); + } + + + + /** + * ストックから外す + * @throws Exception + */ + @SuppressWarnings("unchecked") + @Test + @Order(order = 400) + public void testRemoveStock() throws Exception { + // 記事を開く + StubHttpServletRequest request = openKnowledge(STOCK_USER, knowledgeId); + StubHttpServletResponse response = new StubHttpServletResponse(request); + + // Stockの一覧を取得 + request = new StubHttpServletRequest(request); + response = new StubHttpServletResponse(request); + request.setServletPath("protect.stock/chooselist"); + request.setMethod("get"); + JsonBoundary jsonBoundary = invoke(request, response, JsonBoundary.class); + List stocks = (List) jsonBoundary.getObj(); + Assert.assertEquals(1, stocks.size()); + + // 記事をStock + request.setServletPath("protect.knowledge/stock/" + knowledgeId); + request.setMethod("Post"); + String json = "[{\"description\":\"\",\"stockId\":" + + stocks.get(0).getStockId() + + ",\"stockName\":\"Stock\",\"stockType\":0,\"stocked\":false}]"; + request.setInputstream(new ByteArrayInputStream(json.getBytes())); + jsonBoundary = invoke(request, response, JsonBoundary.class); + LOG.info(jsonBoundary.getObj()); + } + + /** + * ストックに入ったことを確認 + * @throws Exception + */ + @SuppressWarnings("unchecked") + @Test + @Order(order = 401) + public void testCheckStockRemoved() throws Exception { + StubHttpServletRequest request = new StubHttpServletRequest(); + StubHttpServletResponse response = new StubHttpServletResponse(request); + DefaultAuthenticationLogicImpl auth = org.support.project.di.Container.getComp(DefaultAuthenticationLogicImpl.class); + auth.setSession(STOCK_USER, request, response); + + // ストック一覧は無い + request.setServletPath("protect.stock/knowledge"); + request.setMethod("get"); + request.setAttribute("stockId", String.valueOf(stockId)); + request.setAttribute("offset", "0"); + ForwardBoundary forwardBoundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/stock/knowledge.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, forwardBoundary, "path")); + List knowledges = (List) request.getAttribute("knowledges"); + Assert.assertEquals(0, knowledges.size()); + } + + /** + * ストックから削除後の状態確認 + * @throws Exception + */ + @Test + @Order(order = 402) + public void testAssertAfterRemove() throws Exception { + assertKnowledgeCP(POST_USER, knowledgeId, 0); + assertCP(POST_USER, 0); + assertCP(STOCK_USER, 0); + List list = NotifyQueuesDao.get().selectAll(); + Assert.assertEquals(0, list.size()); + assertNotificationCount(POST_USER, 0); + assertNotificationCount(STOCK_USER, 0); + } + + /** + * ストックを更新 + * @throws Exception + */ + @SuppressWarnings("unchecked") + @Test + @Order(order = 500) + public void testUpdateStock() throws Exception { + StubHttpServletRequest request = new StubHttpServletRequest(); + StubHttpServletResponse response = new StubHttpServletResponse(request); + DefaultAuthenticationLogicImpl auth = org.support.project.di.Container.getComp(DefaultAuthenticationLogicImpl.class); + auth.setSession(STOCK_USER, request, response); + + // Stock登録画面を表示 + request.setServletPath("protect.stock/edit/" + stockId); + request.setMethod("get"); + ForwardBoundary forwardBoundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/stock/edit.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, forwardBoundary, "path")); + + // Stock更新 + request = new StubHttpServletRequest(request); + response = new StubHttpServletResponse(request); + request.setServletPath("protect.stock/update"); + request.setMethod("post"); + request.addParameter("stockId", String.valueOf(stockId)); + request.addParameter("stockName", "StockUpdate"); + forwardBoundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/stock/edit.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, forwardBoundary, "path")); + + // 一覧再取得 + request.setServletPath("protect.stock/chooselist"); + request.setMethod("get"); + JsonBoundary jsonBoundary = invoke(request, response, JsonBoundary.class); + List stocks = (List) jsonBoundary.getObj(); + Assert.assertEquals(1, stocks.size()); + } + + /** + * ストックを更新 + * @throws Exception + */ + @SuppressWarnings("unchecked") + @Test + @Order(order = 600) + public void testDeleteStock() throws Exception { + StubHttpServletRequest request = new StubHttpServletRequest(); + StubHttpServletResponse response = new StubHttpServletResponse(request); + DefaultAuthenticationLogicImpl auth = org.support.project.di.Container.getComp(DefaultAuthenticationLogicImpl.class); + auth.setSession(STOCK_USER, request, response); + + // Stock登録画面を表示 + request.setServletPath("protect.stock/edit/" + stockId); + request.setMethod("get"); + ForwardBoundary forwardBoundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/stock/edit.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, forwardBoundary, "path")); + + // Stock更新 + request = new StubHttpServletRequest(request); + response = new StubHttpServletResponse(request); + request.setServletPath("protect.stock/delete"); + request.setMethod("post"); + request.addParameter("stockId", String.valueOf(stockId)); + request.addParameter("stockName", "StockUpdate"); + forwardBoundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/protect/stock/list.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, forwardBoundary, "path")); + List stocks = (List) request.getAttribute("stocks"); + Assert.assertEquals(0, stocks.size()); + } + + + /** + * CP獲得履歴 + * @throws Exception + */ + @Test + @Order(order = 700) + public void testActivityHistory() throws Exception { + assertPointHistoryCount(POST_USER, 3); + assertPointHistoryCount(STOCK_USER, 1); + } + +} diff --git a/src/test/java/org/support/project/knowledge/integration/IntegrationSurveyTest.java b/src/test/java/org/support/project/knowledge/integration/IntegrationSurveyTest.java index 73235a362..da132f391 100644 --- a/src/test/java/org/support/project/knowledge/integration/IntegrationSurveyTest.java +++ b/src/test/java/org/support/project/knowledge/integration/IntegrationSurveyTest.java @@ -16,7 +16,6 @@ import org.support.project.web.bean.Msg; import org.support.project.web.boundary.ForwardBoundary; import org.support.project.web.boundary.JsonBoundary; -import org.support.project.web.boundary.SendMessageBoundary; import org.support.project.web.common.HttpStatus; import org.support.project.web.logic.HttpRequestCheckLogic; import org.support.project.web.logic.impl.DefaultAuthenticationLogicImpl; @@ -55,7 +54,7 @@ public void testUserInsert() throws Exception { */ @Test @Order(order = 100) - public void testPostEventPublic() throws Exception { + public void testPostPublic() throws Exception { // 登録画面へアクセスできること(パスのルーティングのみ確認) StubHttpServletRequest request = new StubHttpServletRequest(); StubHttpServletResponse response = new StubHttpServletResponse(request); @@ -205,6 +204,15 @@ public void testAssertAfterAnswer() throws Exception { assertNotificationCount(ANSWER_USER, 0); } - + /** + * CP獲得履歴 + * @throws Exception + */ + @Test + @Order(order = 600) + public void testActivityHistory() throws Exception { + assertPointHistoryCount(POST_USER, 3); + assertPointHistoryCount(ANSWER_USER, 2); + } } diff --git a/src/test/java/org/support/project/knowledge/integration/IntegrationUpdateTest.java b/src/test/java/org/support/project/knowledge/integration/IntegrationUpdateTest.java index 53972a8f9..ebe2656e5 100644 --- a/src/test/java/org/support/project/knowledge/integration/IntegrationUpdateTest.java +++ b/src/test/java/org/support/project/knowledge/integration/IntegrationUpdateTest.java @@ -9,6 +9,7 @@ import org.support.project.common.test.Order; import org.support.project.common.util.PropertyUtil; import org.support.project.knowledge.dao.NotifyQueuesDao; +import org.support.project.knowledge.entity.KnowledgesEntity; import org.support.project.knowledge.entity.NotifyQueuesEntity; import org.support.project.knowledge.logic.KnowledgeLogic; import org.support.project.knowledge.logic.TemplateLogic; @@ -41,7 +42,7 @@ private void doUpdate(int publicflag, boolean updateContent) throws Exception { // 編集画面を開く StubHttpServletRequest request = new StubHttpServletRequest(); StubHttpServletResponse response = new StubHttpServletResponse(request); - request.setServletPath("protect.knowledge/view_add"); + request.setServletPath("protect.knowledge/view_edit/" + knowledgeId); request.setMethod("get"); DefaultAuthenticationLogicImpl auth = org.support.project.di.Container.getComp(DefaultAuthenticationLogicImpl.class); auth.setSession(POST_USER, request, response); @@ -51,6 +52,8 @@ private void doUpdate(int publicflag, boolean updateContent) throws Exception { Assert.assertNotNull(csrfToken); // 保存 + request = new StubHttpServletRequest(request); + response = new StubHttpServletResponse(request); request.setServletPath("protect.knowledge/save"); request.setMethod("post"); request.addParameter("knowledgeId", String.valueOf(1)); @@ -273,4 +276,52 @@ public void testAssertAfterUpdateNotNotify() throws Exception { assertNotificationCount(POST_USER, 0); assertNotificationCount(USER1, 0); } + + + /** + * 記事を削除 + * @throws Exception + */ + @Test + @Order(order = 900) + public void testDelete() throws Exception { + // 編集画面を開く + StubHttpServletRequest request = new StubHttpServletRequest(); + StubHttpServletResponse response = new StubHttpServletResponse(request); + request.setServletPath("protect.knowledge/view_edit/" + knowledgeId); + request.setMethod("get"); + DefaultAuthenticationLogicImpl auth = org.support.project.di.Container.getComp(DefaultAuthenticationLogicImpl.class); + auth.setSession(POST_USER, 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 = new StubHttpServletRequest(request); + response = new StubHttpServletResponse(request); + request.setServletPath("protect.knowledge/delete"); + request.setMethod("post"); + request.addParameter("knowledgeId", String.valueOf(1)); + request.addParameter(HttpRequestCheckLogic.REQ_ID_KEY, csrfToken); + boundary = invoke(request, response, ForwardBoundary.class); + Assert.assertEquals("/WEB-INF/views/open/knowledge/list.jsp", PropertyUtil.getPrivateFeildOnReflection(String.class, boundary, "path")); + @SuppressWarnings("unchecked") + List knowledges = (List) request.getAttribute("knowledges"); + Assert.assertNotNull(knowledges); + Assert.assertEquals(0, knowledges.size()); + } + + + /** + * CP獲得履歴 + * @throws Exception + */ + @Test + @Order(order = 1000) + public void testActivityHistory() throws Exception { + assertPointHistoryCount(POST_USER, 6); + assertPointHistoryCount(USER1, 1); + } + }