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/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 a8ba89052..2374a1337 100644 --- a/src/test/java/org/support/project/knowledge/integration/IntegrationCommon.java +++ b/src/test/java/org/support/project/knowledge/integration/IntegrationCommon.java @@ -25,8 +25,8 @@ 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.ActivityHistory; import org.support.project.knowledge.vo.LikeCount; import org.support.project.knowledge.vo.api.Knowledge; import org.support.project.web.bean.LoginedUser; @@ -95,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) { @@ -232,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); @@ -400,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"); @@ -433,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"); @@ -541,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); @@ -576,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 index 4b56d3955..3fd9297ff 100644 --- a/src/test/java/org/support/project/knowledge/integration/IntegrationNotificationTest.java +++ b/src/test/java/org/support/project/knowledge/integration/IntegrationNotificationTest.java @@ -41,6 +41,7 @@ private List getList(String userKey, StubHttpServletRequest 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; } 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 0df049c6a..da132f391 100644 --- a/src/test/java/org/support/project/knowledge/integration/IntegrationSurveyTest.java +++ b/src/test/java/org/support/project/knowledge/integration/IntegrationSurveyTest.java @@ -204,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); + } + }