View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.fit.console;
20  
21  import static org.junit.jupiter.api.Assertions.assertNotNull;
22  import static org.junit.jupiter.api.Assertions.assertNull;
23  import static org.junit.jupiter.api.Assertions.assertTrue;
24  
25  import de.agilecoders.wicket.core.markup.html.bootstrap.dialog.Modal;
26  import org.apache.syncope.client.console.pages.Security;
27  import org.apache.syncope.client.ui.commons.Constants;
28  import org.apache.wicket.Component;
29  import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink;
30  import org.apache.wicket.markup.html.basic.Label;
31  import org.apache.wicket.util.tester.FormTester;
32  import org.junit.jupiter.api.BeforeEach;
33  import org.junit.jupiter.api.Test;
34  
35  public class SecurityQuestionsITCase extends AbstractConsoleITCase {
36  
37      @BeforeEach
38      public void login() {
39          doLogin(ADMIN_UNAME, ADMIN_PWD);
40          TESTER.clickLink("body:configurationLI:configurationUL:securityLI:security", false);
41          TESTER.assertRenderedPage(Security.class);
42          TESTER.clickLink("body:content:tabbedPanel:tabs-container:tabs:4:link");
43      }
44  
45      private static void createSecurityQuestion(final String name) {
46          TESTER.clickLink("body:content:tabbedPanel:panel:container:content:add");
47  
48          TESTER.assertComponent(
49                  "body:content:tabbedPanel:panel:outerObjectsRepeater:0:outer", Modal.class);
50  
51          FormTester formTester = TESTER.newFormTester(
52                  "body:content:tabbedPanel:panel:outerObjectsRepeater:0:outer:form");
53          formTester.setValue("content:securityQuestionDetailsPanel:container:form:content:textField",
54                  name);
55  
56          TESTER.clickLink(
57                  "body:content:tabbedPanel:panel:outerObjectsRepeater:0:outer:dialog:footer:inputs:0:submit");
58  
59          assertSuccessMessage();
60          TESTER.cleanupFeedbackMessages();
61  
62          TESTER.clickLink("body:configurationLI:configurationUL:securityLI:security", false);
63          TESTER.clickLink("body:content:tabbedPanel:tabs-container:tabs:4:link");
64      }
65  
66      @Test
67      public void read() {
68          Label label = (Label) TESTER.getComponentFromLastRenderedPage(
69                  "body:content:tabbedPanel:panel:container:content:searchContainer:resultTable:"
70                  + "tablePanel:groupForm:checkgroup:dataTable:body:rows:1:cells:2:cell");
71          assertTrue(label.getDefaultModelObjectAsString().startsWith("What's your "));
72  
73          TESTER.executeAjaxEvent(
74                  "body:content:tabbedPanel:panel:container:content:searchContainer:resultTable:"
75                  + "tablePanel:groupForm:checkgroup:dataTable:body:rows:1", Constants.ON_CLICK);
76  
77          TESTER.assertComponent(
78                  "body:content:tabbedPanel:panel:outerObjectsRepeater:1:outer:container:content:"
79                  + "togglePanelContainer:container:actions:actions:actionRepeater:0:action:action",
80                  IndicatingAjaxLink.class);
81      }
82  
83      @Test
84      public void create() {
85          createSecurityQuestion("What's your preferred team?");
86      }
87  
88      @Test
89      public void update() {
90          createSecurityQuestion("What's your preferred color?");
91          Component result = findComponentByProp("content", "body:content:tabbedPanel:panel:container:content:"
92                  + "searchContainer:resultTable:tablePanel:groupForm:checkgroup:dataTable",
93                  "What's your preferred color?");
94  
95          assertNotNull(result);
96  
97          TESTER.executeAjaxEvent(result.getPageRelativePath(), Constants.ON_CLICK);
98          TESTER.clickLink(
99                  "body:content:tabbedPanel:panel:outerObjectsRepeater:1:outer:container:content:"
100                 + "togglePanelContainer:container:actions:actions:actionRepeater:0:action:action");
101 
102         FormTester formTester = TESTER.newFormTester(
103                 "body:content:tabbedPanel:panel:outerObjectsRepeater:0:outer:form");
104         formTester.setValue("content:securityQuestionDetailsPanel:container:form:content:textField",
105                 "What's your preferred car?");
106 
107         TESTER.clickLink(
108                 "body:content:tabbedPanel:panel:outerObjectsRepeater:0:outer:dialog:footer:inputs:0:submit");
109 
110         assertSuccessMessage();
111         TESTER.cleanupFeedbackMessages();
112     }
113 
114     @Test
115     public void delete() {
116         String name = "What's your preferred color?";
117         createSecurityQuestion(name);
118 
119         Component result = findComponentByProp("content", "body:content:tabbedPanel:panel:container:content:"
120                 + "searchContainer:resultTable:tablePanel:groupForm:checkgroup:dataTable",
121                 name);
122         assertNotNull(result);
123 
124         TESTER.executeAjaxEvent(result.getPageRelativePath(), Constants.ON_CLICK);
125         TESTER.getRequest().addParameter("confirm", "true");
126         TESTER.clickLink(
127                 "body:content:tabbedPanel:panel:outerObjectsRepeater:1:outer:container:content:"
128                 + "togglePanelContainer:container:actions:actions:actionRepeater:1:action:action");
129 
130         TESTER.executeAjaxEvent(TESTER.getComponentFromLastRenderedPage(
131                 "body:content:tabbedPanel:panel:outerObjectsRepeater:1:outer:container:content:"
132                 + "togglePanelContainer:container:actions:actions:actionRepeater:1:action:action"), "onclick");
133 
134         assertSuccessMessage();
135         TESTER.cleanupFeedbackMessages();
136 
137         assertNull(findComponentByProp("content",
138                 "body:content:tabbedPanel:panel:container:content:"
139                 + "searchContainer:resultTable:"
140                 + "tablePanel:groupForm:checkgroup:dataTable", name));
141     }
142 }