1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.panels.test.ui

File ApplicationsPanelAdministrationTest.java

 

Code metrics

0
70
8
1
193
123
8
0.11
8.75
8
1

Classes

Class Line # Actions
ApplicationsPanelAdministrationTest 50 70 0% 8 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.panels.test.ui;
21   
22    import java.util.Arrays;
23    import java.util.Iterator;
24    import java.util.List;
25   
26    import org.junit.Rule;
27    import org.junit.Test;
28    import org.openqa.selenium.WebElement;
29    import org.xwiki.model.reference.LocalDocumentReference;
30    import org.xwiki.panels.test.po.ApplicationsPanel;
31    import org.xwiki.panels.test.po.ApplicationsPanelAdministrationPage;
32    import org.xwiki.test.ui.AbstractTest;
33    import org.xwiki.test.ui.SuperAdminAuthenticationRule;
34    import org.xwiki.test.ui.po.ViewPage;
35    import org.xwiki.test.ui.po.editor.ObjectEditPage;
36    import org.xwiki.test.ui.po.editor.ObjectEditPane;
37   
38    import static org.junit.Assert.assertEquals;
39    import static org.junit.Assert.assertFalse;
40    import static org.junit.Assert.assertTrue;
41   
42    /**
43    * Tests related to the ApplicationsPanel Administration
44    *
45    * @version $Id: 258320705ad26dec9117b40abd714998e6b2f3f1 $
46    * @since 7.1M1
47    * @since 7.0.1
48    * @since 6.4.4
49    */
 
50    public class ApplicationsPanelAdministrationTest extends AbstractTest
51    {
52    @Rule
53    public SuperAdminAuthenticationRule authenticationRule = new SuperAdminAuthenticationRule(getUtil());
54   
 
55  1 toggle @Test
56    public void testApplicationsPanelAdministration() throws Exception
57    {
58  1 createApplicationUIXs();
59   
60    // First: check that the panel displays everything in the right order
61  1 checkInitialState(ApplicationsPanel.gotoPage());
62   
63    // No go to the administration
64  1 ApplicationsPanelAdministrationPage appPanelAdminPage = ApplicationsPanelAdministrationPage.gotoPage();
65   
66    // Check that everything is as expected
67  1 checkInitialState(appPanelAdminPage);
68   
69    // Make changes and revert them, check that it works
70  1 applyChanges(appPanelAdminPage);
71  1 appPanelAdminPage.revert();
72  1 checkInitialState(appPanelAdminPage);
73   
74    // Do the changes again, and save them
75  1 applyChanges(appPanelAdminPage);
76  1 appPanelAdminPage.save();
77  1 assertTrue(appPanelAdminPage.hasSuccessNotification());
78   
79    // Go to the panel and see what are the new results
80  1 ApplicationsPanel applicationsPanel = ApplicationsPanel.gotoPage();
81  1 List<String> applications = applicationsPanel.getApplications();
82  1 assertEquals(3, applications.size());
83  1 Iterator<String> iterator = applications.iterator();
84  1 assertEquals("App3", iterator.next());
85  1 assertEquals("App1", iterator.next());
86  1 assertEquals("App2", iterator.next());
87   
88    // Go back to the app panel admin page and verify that the settings are well displayed
89  1 appPanelAdminPage = ApplicationsPanelAdministrationPage.gotoPage();
90  1 assertFalse(appPanelAdminPage.getApplicationsInBar().contains("Panels"));
91  1 assertTrue(appPanelAdminPage.getApplicationsNotInBar().contains("Panels"));
92  1 iterator = appPanelAdminPage.getApplicationsInBar().iterator();
93  1 assertEquals("App3", iterator.next());
94  1 assertEquals("App1", iterator.next());
95  1 assertEquals("App2", iterator.next());
96   
97    // Put the application back to the bar
98  1 appPanelAdminPage.addApplicationInBar("Panels");
99  1 assertTrue(appPanelAdminPage.getApplicationsInBar().contains("Panels"));
100  1 assertFalse(appPanelAdminPage.getApplicationsNotInBar().contains("Panels"));
101   
102    // Put back the initial order
103  1 appPanelAdminPage.moveAppBefore("App1", appPanelAdminPage.getApplicationsInBar().get(0));
104  1 appPanelAdminPage.moveAppBefore("App2", appPanelAdminPage.getApplicationsInBar().get(1));
105  1 appPanelAdminPage.moveAppBefore("App3", appPanelAdminPage.getApplicationsInBar().get(2));
106   
107    // Save again
108  1 appPanelAdminPage.save();
109  1 assertTrue(appPanelAdminPage.hasSuccessNotification());
110   
111    // Go back to the panel and check everything is good
112  1 checkInitialState(ApplicationsPanel.gotoPage());
113   
114    // Verify that the settings have been saved
115  1 checkInitialState(ApplicationsPanelAdministrationPage.gotoPage());
116   
117    // Cleanup
118  1 cleanUp();
119    }
120   
 
121  1 toggle private void createApplicationUIXs()
122    {
123  1 createApplicationUIX("App1");
124  1 createApplicationUIX("App2");
125  1 createApplicationUIX("App3");
126    }
127   
 
128  3 toggle private void createApplicationUIX(String applicationName)
129    {
130  3 ViewPage page = getUtil().gotoPage("Apps", applicationName);
131  3 ObjectEditPage editPage = page.editObjects();
132  3 ObjectEditPane object = editPage.addObject("XWiki.UIExtensionClass");
133  3 fillField(object, "extensionPointId", "org.xwiki.platform.panels.Applications");
134  3 fillField(object, "name", applicationName);
135  3 fillField(object, "parameters",
136    String.format("label=%s\ntarget=Apps.%s\nicon=icon:home", applicationName, applicationName));
137  3 editPage.clickSaveAndView();
138    }
139   
 
140  3 toggle private void checkInitialState(ApplicationsPanelAdministrationPage appPanelAdminPage) throws Exception
141    {
142  3 assertEquals(4, appPanelAdminPage.getApplicationsInBar().size());
143  3 assertTrue(appPanelAdminPage.getApplicationsNotInBar().isEmpty());
144   
145    // Verify the order
146  3 Iterator<String> iterator = appPanelAdminPage.getApplicationsInBar().iterator();
147  3 assertEquals("App1", iterator.next());
148  3 assertEquals("App2", iterator.next());
149  3 assertEquals("App3", iterator.next());
150  3 assertEquals("Panels", iterator.next());
151    }
152   
 
153  2 toggle private void checkInitialState(ApplicationsPanel applicationsPanel) throws Exception
154    {
155  2 List<String> applications = applicationsPanel.getApplications();
156  2 assertEquals(4, applications.size());
157  2 Iterator<String> iterator = applications.iterator();
158  2 assertEquals("App1", iterator.next());
159  2 assertEquals("App2", iterator.next());
160  2 assertEquals("App3", iterator.next());
161  2 assertEquals("Panels", iterator.next());
162    }
163   
 
164  2 toggle private void applyChanges(ApplicationsPanelAdministrationPage appPanelAdminPage) throws Exception
165    {
166    // Remove an app from the bar
167  2 appPanelAdminPage.removeApplicationFromBar("Panels");
168  2 assertFalse(appPanelAdminPage.getApplicationsInBar().contains("Panels"));
169  2 assertTrue(appPanelAdminPage.getApplicationsNotInBar().contains("Panels"));
170   
171    // Change the order
172  2 appPanelAdminPage.moveAppBefore("App3", "App1");
173    }
174   
 
175  9 toggle private void fillField(ObjectEditPane object, String propertyName, String value)
176    {
177  9 WebElement field = getDriver().findElement(object.byPropertyName(propertyName));
178  9 field.clear();
179  9 field.sendKeys(value);
180    }
181   
 
182  1 toggle private void cleanUp() throws Exception
183    {
184  1 getUtil().rest().delete(
185    new LocalDocumentReference(Arrays.asList("Apps", "App1"), "WebHome"));
186  1 getUtil().rest().delete(
187    new LocalDocumentReference(Arrays.asList("Apps", "App2"), "WebHome"));
188  1 getUtil().rest().delete(
189    new LocalDocumentReference(Arrays.asList("Apps", "App3"), "WebHome"));
190  1 getUtil().rest().delete(
191    new LocalDocumentReference(Arrays.asList("PanelsCode"), "ApplicationsPanelConfiguration"));
192    }
193    }