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

File ClassSheetTest.java

 

Code metrics

0
53
1
1
135
78
1
0.02
53
1
1

Classes

Class Line # Actions
ClassSheetTest 40 53 0% 1 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.xclass.test.ui;
21   
22    import org.apache.commons.lang3.RandomStringUtils;
23    import org.junit.Assert;
24    import org.junit.Rule;
25    import org.junit.Test;
26    import org.xwiki.test.ui.AbstractTest;
27    import org.xwiki.test.ui.SuperAdminAuthenticationRule;
28    import org.xwiki.test.ui.po.InlinePage;
29    import org.xwiki.test.ui.po.ViewPage;
30    import org.xwiki.test.ui.po.editor.ClassEditPage;
31    import org.xwiki.xclass.test.po.ClassSheetPage;
32    import org.xwiki.xclass.test.po.DataTypesPage;
33   
34    /**
35    * Tests the default class sheet (XWiki.ClassSheet).
36    *
37    * @version $Id: 666af02947a0ba932ac2327b7b631240874e2c92 $
38    * @since 4.5
39    */
 
40    public class ClassSheetTest extends AbstractTest
41    {
42    @Rule
43    public SuperAdminAuthenticationRule authenticationRule = new SuperAdminAuthenticationRule(getUtil());
44   
45    /**
46    * Tests the process of creating a class, its template, its sheet and an instance.
47    */
 
48  1 toggle @Test
49    public void createClass()
50    {
51    //TODO: rewrite the test to not rely on the breadcrumb based on parent/child mechanism.
52  1 getUtil().setHierarchyMode("parentchild");
53  1 try {
54  1 String spaceName = getTestClassName();
55  1 String className = RandomStringUtils.randomAlphabetic(5);
56  1 String classDocName = className + "Class";
57  1 String classTitle = className + " Class";
58  1 String pageName = getTestMethodName();
59    // Make sure the document doesn't exist.
60  1 getUtil().deletePage(spaceName, pageName);
61   
62    // Create the class document.
63  1 DataTypesPage dataTypesPage = DataTypesPage.gotoPage().waitUntilPageIsLoaded();
64  1 String dataTypesPageTitle = dataTypesPage.getDocumentTitle();
65  1 Assert.assertTrue(dataTypesPage.isClassListed("XWiki", "XWikiRights"));
66  1 Assert.assertFalse(dataTypesPage.isClassListed(spaceName, classDocName));
67  1 ClassSheetPage classSheetPage = dataTypesPage.createClass(spaceName, className).waitUntilPageIsLoaded();
68  1 Assert.assertEquals(classTitle, classSheetPage.getDocumentTitle());
69  1 Assert.assertTrue(classSheetPage.hasBreadcrumbContent(dataTypesPageTitle, false));
70   
71    // Add a property.
72  1 ClassEditPage classEditor = classSheetPage.clickDefineClassLink();
73  1 classEditor.addProperty("color", "String").setPrettyName("Your favorite color");
74  1 classEditor.clickSaveAndView();
75   
76    // Add a new property.
77  1 classEditor = classSheetPage.waitUntilPageIsLoaded().clickEditClassLink();
78  1 classEditor.addProperty("age", "Number").setPrettyName("Your current age");
79  1 classEditor.clickSaveAndView();
80   
81    // We have to wait for the page to load because Selenium doesn't do it all the time when we click on Save & View
82    // (even if the Save & View button triggers a plain form submit; there must be something with the JavaScript
83    // code that is executed on submit that interferes with Selenium).
84  1 classSheetPage.waitUntilPageIsLoaded();
85   
86    // Assert that the properties are listed.
87  1 Assert.assertTrue(classSheetPage.hasProperty("color", "Your favorite color", "String"));
88  1 Assert.assertTrue(classSheetPage.hasProperty("age", "Your current age", "Number"));
89   
90    // Create and bind a sheet.
91  1 classSheetPage = classSheetPage.clickCreateSheetButton().waitUntilPageIsLoaded()
92    .clickBindSheetLink().waitUntilPageIsLoaded();
93  1 ViewPage sheetPage = classSheetPage.clickSheetLink();
94  1 Assert.assertEquals(className + " Sheet", sheetPage.getDocumentTitle());
95  1 sheetPage.clickBreadcrumbLink(classTitle);
96  1 classSheetPage.waitUntilPageIsLoaded();
97   
98    // Create the template.
99  1 classSheetPage = classSheetPage.clickCreateTemplateButton().waitUntilPageIsLoaded()
100    .clickAddObjectToTemplateLink().waitUntilPageIsLoaded();
101  1 ViewPage templatePage = classSheetPage.clickTemplateLink();
102  1 Assert.assertEquals(className + " Template", templatePage.getDocumentTitle());
103    // The default edit button should take us to the In-line edit mode.
104  1 templatePage.edit();
105  1 InlinePage editPage = new InlinePage();
106  1 editPage.setValue("color", "red");
107  1 editPage.setValue("age", "13");
108  1 editPage.clickSaveAndContinue();
109  1 editPage.clickBreadcrumbLink(classTitle);
110  1 classSheetPage.waitUntilPageIsLoaded();
111   
112    // Create a document based on the class template.
113  1 Assert.assertEquals(spaceName, classSheetPage.getNewPagePicker().getParentInput().getAttribute("value"));
114  1 editPage = classSheetPage.createNewDocument(spaceName, pageName);
115   
116  1 Assert.assertEquals(pageName, editPage.getDocumentTitle());
117  1 Assert.assertEquals("red", editPage.getValue("color"));
118  1 Assert.assertEquals("13", editPage.getValue("age"));
119   
120  1 editPage.setValue("color", "blue");
121  1 editPage.setValue("age", "27");
122  1 ViewPage viewPage = editPage.clickSaveAndView();
123   
124  1 Assert.assertEquals(pageName, viewPage.getDocumentTitle());
125  1 Assert.assertEquals("Your favorite color\nblue\nYour current age\n27", viewPage.getContent());
126  1 viewPage.clickBreadcrumbLink(classTitle);
127  1 classSheetPage.waitUntilPageIsLoaded();
128   
129    // Assert the created document is listed.
130  1 Assert.assertTrue(classSheetPage.hasDocument(pageName));
131    } finally {
132  1 getUtil().setHierarchyMode("reference");
133    }
134    }
135    }