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

File AppsLiveTableTest.java

 

Code metrics

0
63
5
1
192
113
5
0.08
12.6
5
1

Classes

Class Line # Actions
AppsLiveTableTest 43 63 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 3 tests. .

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.test.ui.appwithinminutes;
21   
22    import org.apache.commons.lang.RandomStringUtils;
23    import org.junit.Assert;
24    import org.junit.Before;
25    import org.junit.Test;
26    import org.xwiki.appwithinminutes.test.po.AppWithinMinutesHomePage;
27    import org.xwiki.appwithinminutes.test.po.ApplicationClassEditPage;
28    import org.xwiki.appwithinminutes.test.po.ApplicationCreatePage;
29    import org.xwiki.appwithinminutes.test.po.ApplicationHomeEditPage;
30    import org.xwiki.appwithinminutes.test.po.ApplicationHomePage;
31    import org.xwiki.appwithinminutes.test.po.ApplicationsLiveTableElement;
32    import org.xwiki.appwithinminutes.test.po.ClassFieldEditPane;
33    import org.xwiki.test.ui.AbstractTest;
34    import org.xwiki.test.ui.browser.IgnoreBrowser;
35    import org.xwiki.test.ui.browser.IgnoreBrowsers;
36   
37    /**
38    * Tests the live table that lists the existing applications on the AppWithinMinutes home page.
39    *
40    * @version $Id: 895d0d318d18cbf2d6958cd4b81cc109ed5a400a $
41    * @since 4.0M2
42    */
 
43    public class AppsLiveTableTest extends AbstractTest
44    {
45    /**
46    * The page being tested.
47    */
48    private AppWithinMinutesHomePage homePage;
49   
 
50  3 toggle @Before
51    public void setUp()
52    {
53    // Register a simple user, login and go to the AppWithinMinutes home page.
54  3 String userName = RandomStringUtils.randomAlphanumeric(5);
55  3 String password = RandomStringUtils.randomAlphanumeric(6);
56  3 getUtil().createUserAndLogin(userName, password);
57  3 homePage = AppWithinMinutesHomePage.gotoPage();
58    }
59   
60    /**
61    * Creates an application and deletes it using the Actions column from the applications live table.
62    */
 
63  1 toggle @Test
64    @IgnoreBrowsers({
65    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
66    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
67    })
68    public void testDeleteApplication()
69    {
70    // Create the application.
71  1 String appName = RandomStringUtils.randomAlphabetic(6);
72  1 createApplication(appName);
73   
74    // Check the the applications live table lists the created application.
75  1 ApplicationsLiveTableElement appsLiveTable = homePage.getAppsLiveTable();
76  1 appsLiveTable.waitUntilReady();
77  1 Assert.assertTrue(appsLiveTable.hasColumn("Actions"));
78  1 appsLiveTable.filterApplicationName(appName.substring(0, 3));
79  1 Assert.assertTrue(appsLiveTable.isApplicationListed(appName));
80   
81    // Click the delete icon then cancel the confirmation.
82  1 appsLiveTable.clickDeleteApplication(appName).clickNo();
83    // We should be taken back to the AppWithinMinutes home page.
84  1 homePage = new AppWithinMinutesHomePage();
85  1 appsLiveTable = homePage.getAppsLiveTable();
86  1 appsLiveTable.waitUntilReady();
87    // The application name filter should've been preserved.
88  1 Assert.assertEquals(appName.substring(0, 3), appsLiveTable.getApplicationNameFilter());
89   
90    // Click the delete icon again and this confirm the action.
91  1 appsLiveTable.clickDeleteApplication(appName).clickYes();
92    // We should be taken back to the AppWithinMinutes home page.
93  1 homePage = new AppWithinMinutesHomePage();
94  1 appsLiveTable = homePage.getAppsLiveTable();
95  1 appsLiveTable.waitUntilReady();
96    // The application name filter should've been preserved.
97  1 Assert.assertEquals(appName.substring(0, 3), appsLiveTable.getApplicationNameFilter());
98    // And the deleted application shouldn't be listed anymore.
99  1 Assert.assertFalse(appsLiveTable.isApplicationListed(appName));
100    }
101   
102    /**
103    * Creates an application and edits it using the Actions column from the applications live table.
104    */
 
105  1 toggle @Test
106    @IgnoreBrowsers({
107    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
108    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
109    })
110    public void testEditApplication()
111    {
112    // Create the application.
113  1 String appName = RandomStringUtils.randomAlphabetic(6);
114  1 createApplication(appName);
115   
116    // Edit the application.
117  1 ApplicationsLiveTableElement appsLiveTable = homePage.getAppsLiveTable();
118  1 appsLiveTable.waitUntilReady();
119  1 ApplicationClassEditPage classEditor = appsLiveTable.clickEditApplication(appName);
120   
121    // Edit the existing class field.
122  1 ClassFieldEditPane fieldEditPane = new ClassFieldEditPane("shortText1");
123  1 fieldEditPane.setPrettyName("City Name");
124  1 fieldEditPane.openConfigPanel();
125  1 fieldEditPane.setName("cityName");
126   
127    // Move to the next step.
128  1 ApplicationHomeEditPage homeEditPage = classEditor.clickNextStep().clickNextStep();
129  1 homeEditPage.setDescription("demo");
130   
131    // Finish editing.
132  1 ApplicationHomePage homePage = homeEditPage.clickFinish();
133  1 Assert.assertTrue(homePage.getContent().contains("demo"));
134    }
135   
136    /**
137    * Tests that the actions are displayed only when the current user has the right to perform them.
138    */
 
139  1 toggle @Test
140    @IgnoreBrowsers({
141    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
142    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
143    })
144    public void testActionRights()
145    {
146    // Create the application.
147  1 String appName = RandomStringUtils.randomAlphabetic(6);
148  1 createApplication(appName);
149   
150    // The application author should be able to edit and delete the application.
151  1 ApplicationsLiveTableElement appsLiveTable = homePage.getAppsLiveTable();
152  1 appsLiveTable.waitUntilReady();
153  1 appsLiveTable.filterApplicationName(appName);
154  1 Assert.assertTrue(appsLiveTable.canEditApplication(appName));
155  1 Assert.assertTrue(appsLiveTable.canDeleteApplication(appName));
156   
157    // Logout. Guests shouldn't be able to edit nor delete the application.
158  1 homePage.logout();
159  1 getUtil().recacheSecretToken();
160  1 homePage = new AppWithinMinutesHomePage();
161  1 appsLiveTable = homePage.getAppsLiveTable();
162  1 appsLiveTable.waitUntilReady();
163  1 appsLiveTable.filterApplicationName(appName);
164  1 Assert.assertFalse(appsLiveTable.canEditApplication(appName));
165  1 Assert.assertFalse(appsLiveTable.canDeleteApplication(appName));
166   
167    // Login with a different user. The new user shouldn't be able to delete the application.
168  1 getUtil().createUserAndLogin("someOtherUser", "somePassword");
169  1 appsLiveTable = AppWithinMinutesHomePage.gotoPage().getAppsLiveTable();
170  1 appsLiveTable.waitUntilReady();
171  1 appsLiveTable.filterApplicationName(appName);
172  1 Assert.assertTrue(appsLiveTable.canEditApplication(appName));
173  1 Assert.assertFalse(appsLiveTable.canDeleteApplication(appName));
174    }
175   
176    /**
177    * Creates an application with the specified name. The application class will have just one field.
178    *
179    * @param appName the name of the application to create
180    */
 
181  3 toggle private void createApplication(String appName)
182    {
183  3 ApplicationCreatePage appCreatePage = homePage.clickCreateApplication();
184  3 appCreatePage.setApplicationName(appName);
185  3 appCreatePage.waitForApplicationNamePreview();
186  3 ApplicationClassEditPage classEditPage = appCreatePage.clickNextStep();
187  3 classEditPage.addField("Short Text");
188    // Wait for the application home edit page to load before clicking finish to be sure the page layout is stable.
189  3 classEditPage.clickNextStep().clickNextStep().waitUntilPageIsLoaded().clickFinish();
190  3 homePage = AppWithinMinutesHomePage.gotoPage();
191    }
192    }