2020import org .support .project .knowledge .config .AppConfig ;
2121import org .support .project .knowledge .config .AuthType ;
2222import org .support .project .knowledge .dao .NotifyQueuesDao ;
23+ import org .support .project .knowledge .dao .TemplateItemsDao ;
2324import org .support .project .knowledge .entity .CommentsEntity ;
2425import org .support .project .knowledge .entity .NotifyQueuesEntity ;
26+ import org .support .project .knowledge .logic .EventsLogic ;
27+ import org .support .project .knowledge .logic .KnowledgeLogic ;
28+ import org .support .project .knowledge .logic .TemplateLogic ;
29+ import org .support .project .knowledge .vo .ActivityHistory ;
2530import org .support .project .knowledge .vo .LikeCount ;
2631import org .support .project .knowledge .vo .api .Knowledge ;
2732import org .support .project .web .bean .LoginedUser ;
33+ import org .support .project .web .bean .MessageResult ;
2834import org .support .project .web .bean .Msg ;
2935import org .support .project .web .bean .NameId ;
3036import org .support .project .web .boundary .ForwardBoundary ;
3137import org .support .project .web .boundary .JsonBoundary ;
3238import org .support .project .web .boundary .RedirectBoundary ;
3339import org .support .project .web .boundary .SendMessageBoundary ;
34- import org .support .project .web .common .HttpStatus ;
3540import org .support .project .web .common .InvokeTarget ;
3641import org .support .project .web .dao .MailConfigsDao ;
3742import org .support .project .web .entity .MailConfigsEntity ;
@@ -90,6 +95,7 @@ public static void setUpBeforeClass() throws Exception {
9095 * @return
9196 * @throws Exception
9297 */
98+ @ SuppressWarnings ("unchecked" )
9399 protected <T > T invoke (HttpServletRequest request , HttpServletResponse response , Class <T > clazz ) throws Exception {
94100 InvokeTarget invoke = CallControlLogic .get ().searchInvokeTarget (request , response );
95101 if (invoke == null ) {
@@ -104,6 +110,62 @@ protected <T> T invoke(HttpServletRequest request, HttpServletResponse response,
104110 }
105111 return (T ) result ;
106112 }
113+
114+
115+ /**
116+ * 投稿
117+ * @return
118+ * @throws Exception
119+ * @throws NoSuchFieldException
120+ * @throws IllegalAccessException
121+ */
122+ protected MessageResult postKnowledge (String userKey , int publicFlag , int typeId , String viewers ) throws Exception , NoSuchFieldException , IllegalAccessException {
123+ // 登録画面へアクセスできること(パスのルーティングのみ確認)
124+ StubHttpServletRequest request = new StubHttpServletRequest ();
125+ StubHttpServletResponse response = new StubHttpServletResponse (request );
126+ request .setServletPath ("protect.knowledge/view_add" );
127+ request .setMethod ("get" );
128+ DefaultAuthenticationLogicImpl auth = org .support .project .di .Container .getComp (DefaultAuthenticationLogicImpl .class );
129+ auth .setSession (userKey , request , response );
130+
131+ ForwardBoundary boundary = invoke (request , response , ForwardBoundary .class );
132+ Assert .assertEquals ("/WEB-INF/views/protect/knowledge/edit.jsp" , PropertyUtil .getPrivateFeildOnReflection (String .class , boundary , "path" ));
133+
134+ String csrfToken = (String ) request .getAttribute (HttpRequestCheckLogic .REQ_ID_KEY );
135+ Assert .assertNotNull (csrfToken );
136+
137+ // 保存
138+ request .setServletPath ("protect.knowledge/save" );
139+ request .setMethod ("post" );
140+ request .addParameter (HttpRequestCheckLogic .REQ_ID_KEY , csrfToken );
141+ request .addParameter ("title" , "タイトル" );
142+ request .addParameter ("content" , "内容" );
143+ request .addParameter ("publicFlag" , String .valueOf (publicFlag ));
144+ request .addParameter ("typeId" , String .valueOf (typeId ));
145+
146+ if (typeId == TemplateLogic .TYPE_ID_BOOKMARK ) {
147+ request .addParameter ("item_" + TemplateItemsDao .ITEM_ID_BOOKMARK_URL , "https://information-supportproject.org/" );
148+ } else if (typeId == TemplateLogic .TYPE_ID_EVENT ) {
149+ request .addParameter ("item_" + EventsLogic .ITEM_NO_DATE , "2017-10-01" );
150+ request .addParameter ("item_" + EventsLogic .ITEM_NO_START , "10:00" );
151+ request .addParameter ("item_" + EventsLogic .ITEM_NO_END , "12:00" );
152+ request .addParameter ("item_" + EventsLogic .ITEM_NO_TIMEZONE , "Asia/Tokyo" );
153+ request .addParameter ("item_" + EventsLogic .ITEM_NO_THE_NUMBER_TO_BE_ACCEPTED , "10" );
154+ }
155+
156+ if (publicFlag == KnowledgeLogic .PUBLIC_FLAG_PROTECT ) {
157+ if (StringUtils .isNotEmpty (viewers )) {
158+ request .addParameter ("groups" , viewers );
159+ }
160+ }
161+
162+ JsonBoundary jsonBoundary = invoke (request , response , JsonBoundary .class );
163+ MessageResult sendObject = (MessageResult ) jsonBoundary .getObj ();
164+ LOG .info (sendObject );
165+ Assert .assertEquals (200 , sendObject .getCode ().intValue ());
166+ return sendObject ;
167+ }
168+
107169 /**
108170 * CP確認
109171 * @param userKey
@@ -171,6 +233,7 @@ protected void assertNotificationCount(String userKey, int add) throws Exception
171233 * @return
172234 * @throws Exception
173235 */
236+ @ SuppressWarnings ("unchecked" )
174237 protected List <NotificationsEntity > getNotification (String userKey ) throws Exception {
175238 StubHttpServletRequest request = new StubHttpServletRequest ();
176239 StubHttpServletResponse response = new StubHttpServletResponse (request );
@@ -339,6 +402,7 @@ protected void addLatestLikeComment(String userKey, long knowledgeId) throws Exc
339402 * @param comment
340403 * @throws Exception
341404 */
405+ @ SuppressWarnings ("unchecked" )
342406 protected void comment (String userKey , long knowledgeId , String comment ) throws Exception {
343407 if (userKey == null ) {
344408 Assert .fail ("post comment must be logined" );
@@ -372,6 +436,7 @@ protected void comment(String userKey, long knowledgeId, String comment) throws
372436 * @return
373437 * @throws Exception
374438 */
439+ @ SuppressWarnings ("unchecked" )
375440 protected CommentsEntity getLatestComment (String userKey , long knowledgeId ) throws Exception {
376441 StubHttpServletRequest request = openKnowledge (userKey , knowledgeId );
377442 List <CommentsEntity > comments = (List <CommentsEntity >) request .getAttribute ("comments" );
@@ -386,7 +451,7 @@ protected CommentsEntity getLatestComment(String userKey, long knowledgeId) thro
386451 */
387452 protected void execNotificationQueue () throws Exception {
388453 List <NotifyQueuesEntity > list = NotifyQueuesDao .get ().selectAll ();
389- Assert .assertEquals ( 1 , list .size ());
454+ Assert .assertTrue ( 0 < list .size ());
390455 NotifyMailBat .main (null );
391456 list = NotifyQueuesDao .get ().selectAll ();
392457 Assert .assertEquals (0 , list .size ());
@@ -480,6 +545,7 @@ protected void knowledgeDeleteOnAPI(String userKey, long knowledgeId) throws Exc
480545 * @return
481546 * @throws Exception
482547 */
548+ @ SuppressWarnings ("unchecked" )
483549 protected Knowledge knowledgeGetOnAPI (String userKey , int count ) throws Exception {
484550 StubHttpServletRequest request = new StubHttpServletRequest ();
485551 StubHttpServletResponse response = new StubHttpServletResponse (request );
@@ -515,6 +581,24 @@ protected Knowledge knowledgeGetOnAPI(String userKey, int count) throws Exceptio
515581 return null ;
516582 }
517583
518-
584+ /**
585+ * CPの獲得履歴の件数確認
586+ * @param userKey
587+ * @throws Exception
588+ */
589+ @ SuppressWarnings ("unchecked" )
590+ protected void assertPointHistoryCount (String userKey , int count ) throws Exception {
591+ StubHttpServletRequest request = new StubHttpServletRequest ();
592+ StubHttpServletResponse response = new StubHttpServletResponse (request );
593+ DefaultAuthenticationLogicImpl auth = org .support .project .di .Container .getComp (DefaultAuthenticationLogicImpl .class );
594+ auth .setSession (userKey , request , response );
595+
596+ LoginedUser user = getLoginUser (userKey );
597+ request .setServletPath ("open.account/activity/" + user .getUserId ());
598+ request .setMethod ("get" );
599+ JsonBoundary jsonBoundary = invoke (request , response , JsonBoundary .class );
600+ List <ActivityHistory > list = (List <ActivityHistory >) jsonBoundary .getObj ();
601+ Assert .assertEquals (count , list .size ());
602+ }
519603
520604}
0 commit comments