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:2: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", name);
54  
55          TESTER.clickLink(
56                  "body:content:tabbedPanel:panel:outerObjectsRepeater:0:outer:dialog:footer:inputs:0:submit");
57  
58          assertSuccessMessage();
59          TESTER.cleanupFeedbackMessages();
60  
61          TESTER.clickLink("body:configurationLI:configurationUL:securityLI:security", false);
62          TESTER.clickLink("body:content:tabbedPanel:tabs-container:tabs:2:link");
63      }
64  
65      @Test
66      public void read() {
67          Label label = (Label) TESTER.getComponentFromLastRenderedPage(
68                  "body:content:tabbedPanel:panel:container:content:searchContainer:resultTable:"
69                  + "tablePanel:groupForm:checkgroup:dataTable:body:rows:1:cells:2:cell");
70          assertTrue(label.getDefaultModelObjectAsString().startsWith("What's your "));
71  
72          TESTER.executeAjaxEvent(
73                  "body:content:tabbedPanel:panel:container:content:searchContainer:resultTable:"
74                  + "tablePanel:groupForm:checkgroup:dataTable:body:rows:1", Constants.ON_CLICK);
75  
76          TESTER.assertComponent(
77                  "body:content:tabbedPanel:panel:outerObjectsRepeater:1:outer:container:content:"
78                  + "togglePanelContainer:container:actions:actions:actionRepeater:0:action:action",
79                  IndicatingAjaxLink.class);
80      }
81  
82      @Test
83      public void create() {
84          createSecurityQuestion("What's your preferred team?");
85      }
86  
87      @Test
88      public void update() {
89          createSecurityQuestion("What's your preferred color?");
90          Component result = findComponentByProp("content", "body:content:tabbedPanel:panel:container:content:"
91                  + "searchContainer:resultTable:tablePanel:groupForm:checkgroup:dataTable",
92                  "What's your preferred color?");
93  
94          assertNotNull(result);
95  
96          TESTER.executeAjaxEvent(result.getPageRelativePath(), Constants.ON_CLICK);
97          TESTER.clickLink(
98                  "body:content:tabbedPanel:panel:outerObjectsRepeater:1:outer:container:content:"
99                  + "togglePanelContainer:container:actions:actions:actionRepeater:0:action:action");
100 
101         FormTester formTester = TESTER.newFormTester(
102                 "body:content:tabbedPanel:panel:outerObjectsRepeater:0:outer:form");
103         formTester.setValue("content:securityQuestionDetailsPanel:container:form:content:textField",
104                 "What's your preferred car?");
105 
106         TESTER.clickLink(
107                 "body:content:tabbedPanel:panel:outerObjectsRepeater:0:outer:dialog:footer:inputs:0:submit");
108 
109         assertSuccessMessage();
110         TESTER.cleanupFeedbackMessages();
111     }
112 
113     @Test
114     public void delete() {
115         String name = "What's your preferred color?";
116         createSecurityQuestion(name);
117 
118         Component result = findComponentByProp("content", "body:content:tabbedPanel:panel:container:content:"
119                 + "searchContainer:resultTable:tablePanel:groupForm:checkgroup:dataTable",
120                 name);
121         assertNotNull(result);
122 
123         TESTER.executeAjaxEvent(result.getPageRelativePath(), Constants.ON_CLICK);
124         TESTER.getRequest().addParameter("confirm", "true");
125         TESTER.clickLink(
126                 "body:content:tabbedPanel:panel:outerObjectsRepeater:1:outer:container:content:"
127                 + "togglePanelContainer:container:actions:actions:actionRepeater:1:action:action");
128 
129         TESTER.executeAjaxEvent(TESTER.getComponentFromLastRenderedPage(
130                 "body:content:tabbedPanel:panel:outerObjectsRepeater:1:outer:container:content:"
131                 + "togglePanelContainer:container:actions:actions:actionRepeater:1:action:action"), "onclick");
132 
133         assertSuccessMessage();
134         TESTER.cleanupFeedbackMessages();
135 
136         assertNull(findComponentByProp("content",
137                 "body:content:tabbedPanel:panel:container:content:"
138                 + "searchContainer:resultTable:"
139                 + "tablePanel:groupForm:checkgroup:dataTable", name));
140     }
141 }