Skip to content

Commit

Permalink
Merge pull request #883 from support-project/test6
Browse files Browse the repository at this point in the history
Test6
  • Loading branch information
koda-masaru authored Oct 4, 2017
2 parents cc3ae09 + 17bdbe7 commit b821a07
Show file tree
Hide file tree
Showing 13 changed files with 877 additions and 22 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 @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

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 @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

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.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;
Expand Down Expand Up @@ -90,6 +95,7 @@ public static void setUpBeforeClass() throws Exception {
* @return
* @throws Exception
*/
@SuppressWarnings("unchecked")
protected <T> T invoke(HttpServletRequest request, HttpServletResponse response, Class<T> clazz) throws Exception {
InvokeTarget invoke = CallControlLogic.get().searchInvokeTarget(request, response);
if (invoke == null) {
Expand All @@ -104,6 +110,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 @@ -171,6 +233,7 @@ protected void assertNotificationCount(String userKey, int add) throws Exception
* @return
* @throws Exception
*/
@SuppressWarnings("unchecked")
protected List<NotificationsEntity> getNotification(String userKey) throws Exception {
StubHttpServletRequest request = new StubHttpServletRequest();
StubHttpServletResponse response = new StubHttpServletResponse(request);
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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<CommentsEntity> comments = (List<CommentsEntity>) request.getAttribute("comments");
Expand All @@ -386,7 +451,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 Expand Up @@ -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);
Expand Down Expand Up @@ -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<ActivityHistory> list = (List<ActivityHistory>) jsonBoundary.getObj();
Assert.assertEquals(count, list.size());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<KnowledgesEntity> knowledges = (List<KnowledgesEntity>) request.getAttribute("knowledges");
long knowledgeId = knowledges.get(0).getKnowledgeId();
request = openKnowledge(JOIN_USER, knowledgeId);
Expand Down Expand Up @@ -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<KnowledgesEntity> knowledges = (List<KnowledgesEntity>) request.getAttribute("knowledges");
long knowledgeId = knowledges.get(0).getKnowledgeId();
request = openKnowledge(JOIN_USER, knowledgeId);
Expand Down Expand Up @@ -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<KnowledgesEntity> knowledges = (List<KnowledgesEntity>) request.getAttribute("knowledges");
long knowledgeId = knowledges.get(0).getKnowledgeId();
request = openKnowledge(JOIN_USER, knowledgeId);
Expand Down Expand Up @@ -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<KnowledgesEntity> knowledges = (List<KnowledgesEntity>) request.getAttribute("knowledges");
long knowledgeId = knowledges.get(0).getKnowledgeId();
request = openKnowledge(POST_USER, knowledgeId);
Expand All @@ -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);
}
}
Loading

0 comments on commit b821a07

Please sign in to comment.