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

File EditClassTest.java

 

Code metrics

0
36
4
1
126
74
4
0.11
9
4
1

Classes

Class Line # Actions
EditClassTest 39 36 0% 4 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;
21   
22    import org.junit.Assert;
23    import org.junit.Before;
24    import org.junit.Rule;
25    import org.junit.Test;
26    import org.openqa.selenium.By;
27    import org.xwiki.test.ui.browser.IgnoreBrowser;
28    import org.xwiki.test.ui.po.FormElement;
29    import org.xwiki.test.ui.po.ViewPage;
30    import org.xwiki.test.ui.po.editor.ClassEditPage;
31    import org.xwiki.test.ui.po.editor.ObjectEditPage;
32   
33    /**
34    * Test XClass editing.
35    *
36    * @version $Id: c6dde9215a8e71fa2aefa45b32eb009853e41423 $
37    * @since 2.4RC1
38    */
 
39    public class EditClassTest extends AbstractTest
40    {
41    @Rule
42    public AdminAuthenticationRule adminAuthenticationRule = new AdminAuthenticationRule(getUtil());
43   
 
44  3 toggle @Before
45    public void setUp() throws Exception
46    {
47  3 getUtil().rest().deletePage("Test", "EditObjectsTestClass");
48  3 getUtil().rest().deletePage("Test", "EditObjectsTestObject");
49    }
50   
 
51  1 toggle @Test
52    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146")
53    public void testAddProperty()
54    {
55    // We verify that we can click on Edit Class from View Page (we need to test this at
56    // least once to ensure the UI works).
57  1 getUtil().gotoPage("Test", "EditObjectsTestClass", "view", "spaceRedirect=false");
58  1 ClassEditPage cep = new ViewPage().editClass();
59   
60    // Create a class with a string property
61  1 cep.addProperty("prop", "String");
62  1 cep.clickSaveAndView();
63   
64    // Create object page
65  1 ViewPage vp = getUtil().createPage("Test", "EditObjectsTestObject",
66    "this is the content: {{velocity}}$doc.display('prop'){{/velocity}}", getTestMethodName());
67   
68    // Add an object of the class created
69  1 ObjectEditPage oep = vp.editObjects();
70  1 FormElement objectForm = oep.addObject("Test.EditObjectsTestClass");
71  1 objectForm.setFieldValue(By.id("Test.EditObjectsTestClass_0_prop"), "testing value");
72  1 vp = oep.clickSaveAndView();
73   
74  1 Assert.assertEquals("this is the content: testing value", vp.getContent());
75    }
76   
 
77  1 toggle @Test
78    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146")
79    public void testDeleteProperty()
80    {
81    // Create a class with two string properties
82  1 getUtil().addClassProperty("Test", "EditObjectsTestClass", "prop1", "String");
83  1 getUtil().addClassProperty("Test", "EditObjectsTestClass", "prop2", "String");
84   
85    // Create object page
86  1 ViewPage vp = getUtil().createPage("Test", "EditObjectsTestObject",
87    "this is the content: {{velocity}}$doc.display('prop1')/$doc.display('prop2')/" +
88    "$!doc.getObject('Test.EditObjectsTestClass').getProperty('prop1').value{{/velocity}}",
89    getTestMethodName());
90   
91    // Add an object of the class created
92  1 ObjectEditPage oep = vp.editObjects();
93  1 FormElement objectForm = oep.addObject("Test.EditObjectsTestClass");
94  1 objectForm.setFieldValue(By.id("Test.EditObjectsTestClass_0_prop1"), "testing value 1");
95  1 objectForm.setFieldValue(By.id("Test.EditObjectsTestClass_0_prop2"), "testing value 2");
96  1 vp = oep.clickSaveAndView();
97   
98  1 Assert.assertEquals("this is the content: testing value 1/testing value 2/testing value 1", vp.getContent());
99   
100    // Delete the first property from the class
101  1 ClassEditPage cep = getUtil().editClass("Test", "EditObjectsTestClass");
102  1 cep.deleteProperty("prop1");
103  1 cep.clickSaveAndView();
104   
105  1 vp = getUtil().gotoPage("Test", "EditObjectsTestObject");
106  1 Assert.assertEquals("this is the content: /testing value 2/testing value 1", vp.getContent());
107   
108  1 oep = vp.editObjects();
109  1 Assert.assertNotNull(getDriver().findElement(By.className("deprecatedProperties")));
110  1 Assert.assertNotNull(getDriver().findElement(By.cssSelector(".deprecatedProperties label")));
111  1 Assert.assertEquals("prop1:", getDriver().findElement(By.cssSelector(".deprecatedProperties label")).getText());
112   
113    // Remove deprecated properties
114  1 oep.removeAllDeprecatedProperties();
115  1 vp = oep.clickSaveAndView();
116  1 Assert.assertEquals("this is the content: /testing value 2/", vp.getContent());
117    }
118   
 
119  1 toggle @Test
120    public void addInvalidProperty()
121    {
122  1 ClassEditPage cep = getUtil().editClass("Test", "EditObjectsTestClass");
123  1 cep.addPropertyWithoutWaiting("a<b c", "String");
124  1 cep.waitForNotificationErrorMessage("Failed: Property names must follow these naming rules:");
125    }
126    }