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  
24  import de.agilecoders.wicket.core.markup.html.bootstrap.dialog.Modal;
25  import org.apache.syncope.client.console.pages.Security;
26  import org.apache.syncope.client.ui.commons.Constants;
27  import org.apache.wicket.Component;
28  import org.apache.wicket.util.tester.FormTester;
29  import org.junit.jupiter.api.BeforeEach;
30  import org.junit.jupiter.api.Test;
31  
32  public class RolesITCase extends AbstractConsoleITCase {
33  
34      @BeforeEach
35      public void login() {
36          doLogin(ADMIN_UNAME, ADMIN_PWD);
37          TESTER.clickLink("body:configurationLI:configurationUL:securityLI:security", false);
38          TESTER.assertRenderedPage(Security.class);
39      }
40  
41      private static void createRole(final String name) {
42          TESTER.clickLink("body:content:tabbedPanel:panel:container:content:add");
43  
44          TESTER.assertComponent("body:content:tabbedPanel:panel:outerObjectsRepeater:0:outer", Modal.class);
45  
46          FormTester formTester = TESTER.newFormTester(
47                  "body:content:tabbedPanel:panel:outerObjectsRepeater:0:outer:form");
48          formTester.setValue("content:form:view:key:textField", name);
49          formTester.submit("content:form:buttons:next");
50  
51          formTester = TESTER.newFormTester(
52                  "body:content:tabbedPanel:panel:outerObjectsRepeater:0:outer:form");
53          formTester.setValue("content:form:view:entitlements:paletteField:recorder",
54                  "WORKFLOW_DEF_READ,NOTIFICATION_UPDATE,RELATIONSHIPTYPE_READ,RELATIONSHIPTYPE_LIST");
55          formTester.submit("content:form:buttons:next");
56  
57          formTester = TESTER.newFormTester(
58                  "body:content:tabbedPanel:panel:outerObjectsRepeater:0:outer:form");
59          formTester.submit("content:form:buttons:next");
60  
61          formTester = TESTER.newFormTester(
62                  "body:content:tabbedPanel:panel:outerObjectsRepeater:0:outer:form");
63          formTester.submit("content:form:buttons:next");
64  
65          formTester = TESTER.newFormTester(
66                  "body:content:tabbedPanel:panel:outerObjectsRepeater:0:outer:form");
67          formTester.submit("content:form:buttons:finish");
68  
69          assertSuccessMessage();
70          TESTER.cleanupFeedbackMessages();
71  
72          TESTER.clickLink("body:configurationLI:configurationUL:securityLI:security", false);
73      }
74  
75      @Test
76      public void read() {
77          Component result = findComponentByProp(KEY,
78                  "body:content:tabbedPanel:panel:container:content:searchContainer:"
79                  + "resultTable:tablePanel:groupForm:checkgroup:dataTable", "Other");
80          assertNotNull(result);
81  
82          TESTER.executeAjaxEvent(result.getPageRelativePath(), Constants.ON_CLICK);
83          TESTER.clickLink(
84                  "body:content:tabbedPanel:panel:outerObjectsRepeater:1:outer:container:content:"
85                  + "togglePanelContainer:container:actions:actions:actionRepeater:2:action:action");
86  
87          TESTER.assertModelValue(
88                  "body:content:tabbedPanel:panel:outerObjectsRepeater:5:outer:dialog:header:header-label",
89                  "Role 'Other' members");
90  
91          assertNotNull(findComponentByProp("username",
92                  "body:content:tabbedPanel:panel:outerObjectsRepeater:5:outer:form:"
93                  + "content:searchResult:container:content:searchContainer:resultTable:tablePanel:groupForm:"
94                  + "checkgroup:dataTable", "rossini"));
95  
96          TESTER.executeAjaxEvent(
97                  "body:content:tabbedPanel:panel:outerObjectsRepeater:5:outer:dialog:footer:buttons:0:button",
98                  Constants.ON_CLICK);
99      }
100 
101     @Test
102     public void create() {
103         createRole("testRole");
104     }
105 
106     @Test
107     public void update() {
108         createRole("updateRole");
109         Component result = findComponentByProp(KEY,
110                 "body:content:tabbedPanel:panel:container:content:searchContainer:"
111                 + "resultTable:tablePanel:groupForm:checkgroup:dataTable", "updateRole");
112 
113         assertNotNull(result);
114 
115         TESTER.executeAjaxEvent(result.getPageRelativePath(), Constants.ON_CLICK);
116         TESTER.clickLink(
117                 "body:content:tabbedPanel:panel:outerObjectsRepeater:1:outer:container:content:togglePanelContainer:"
118                 + "container:actions:actions:actionRepeater:0:action:action");
119 
120         FormTester formTester = TESTER.newFormTester(
121                 "body:content:tabbedPanel:panel:outerObjectsRepeater:0:outer:form");
122         formTester.setValue("content:form:view:key:textField", "updateRole");
123         formTester.submit("content:form:buttons:next");
124 
125         formTester = TESTER.newFormTester(
126                 "body:content:tabbedPanel:panel:outerObjectsRepeater:0:outer:form");
127         formTester.setValue("content:form:view:entitlements:paletteField:recorder",
128                 "WORKFLOW_DEF_READ,NOTIFICATION_UPDATE");
129         formTester.submit("content:form:buttons:next");
130 
131         formTester = TESTER.newFormTester(
132                 "body:content:tabbedPanel:panel:outerObjectsRepeater:0:outer:form");
133         formTester.submit("content:form:buttons:finish");
134 
135         assertSuccessMessage();
136         TESTER.cleanupFeedbackMessages();
137     }
138 
139     @Test
140     public void delete() {
141         createRole("deleteRole");
142         Component result = findComponentByProp(KEY,
143                 "body:content:tabbedPanel:panel:container:content:searchContainer:"
144                 + "resultTable:tablePanel:groupForm:checkgroup:dataTable", "deleteRole");
145 
146         assertNotNull(result);
147 
148         TESTER.executeAjaxEvent(result.getPageRelativePath(), Constants.ON_CLICK);
149 
150         TESTER.getRequest().addParameter("confirm", "true");
151         TESTER.clickLink(TESTER.getComponentFromLastRenderedPage(
152                 "body:content:tabbedPanel:panel:outerObjectsRepeater:1:outer:container:content:togglePanelContainer:"
153                 + "container:actions:actions:actionRepeater:4:action:action"));
154 
155         TESTER.executeAjaxEvent(TESTER.getComponentFromLastRenderedPage(
156                 "body:content:tabbedPanel:panel:outerObjectsRepeater:1:outer:container:content:togglePanelContainer:"
157                 + "container:actions:actions:actionRepeater:4:action:action"), "onclick");
158 
159         assertSuccessMessage();
160         TESTER.cleanupFeedbackMessages();
161 
162         assertNull(findComponentByProp(KEY,
163                 "body:content:tabbedPanel:panel:container:content:searchContainer:"
164                 + "resultTable:tablePanel:groupForm:checkgroup:dataTable", "deleteRole"));
165     }
166 }