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

File EditObjectsTest.java

 

Code metrics

0
146
9
1
350
222
9
0.06
16.22
9
1

Classes

Class Line # Actions
EditObjectsTest 45 146 0% 9 0
1.0100%
 

Contributing tests

This file is covered by 8 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 java.util.List;
23   
24    import org.junit.Assert;
25    import org.junit.Before;
26    import org.junit.Rule;
27    import org.junit.Test;
28    import org.openqa.selenium.By;
29    import org.xwiki.test.ui.browser.IgnoreBrowser;
30    import org.xwiki.test.ui.browser.IgnoreBrowsers;
31    import org.xwiki.test.ui.po.FormElement;
32    import org.xwiki.test.ui.po.ViewPage;
33    import org.xwiki.test.ui.po.editor.ClassEditPage;
34    import org.xwiki.test.ui.po.editor.ObjectEditPage;
35    import org.xwiki.test.ui.po.editor.ObjectEditPane;
36    import org.xwiki.test.ui.po.editor.StaticListClassEditElement;
37    import org.xwiki.test.ui.po.editor.WikiEditPage;
38   
39    /**
40    * Test XObject editing.
41    *
42    * @version $Id: 67dbf76166abd3035edb8c4900af1486f2e39c3f $
43    * @since 2.4M2
44    */
 
45    public class EditObjectsTest extends AbstractTest
46    {
47    @Rule
48    public AdminAuthenticationRule adminAuthenticationRule = new AdminAuthenticationRule(getUtil());
49   
 
50  8 toggle @Before
51    public void setUp() throws Exception
52    {
53  8 getUtil().rest().deletePage("Test", "EditObjectsTestClass");
54  8 getUtil().rest().deletePage("Test", "EditObjectsTestObject");
55    }
56   
57    /**
58    * XWIKI-5832: Cannot create groups or add members to existing groups using the object editor.
59    */
 
60  1 toggle @Test
61    public void testEmptyGroupObjects()
62    {
63    // Create a doc
64  1 WikiEditPage wep = WikiEditPage.gotoPage("Test", "EditObjectsTestObject");
65  1 wep.setContent("this is the content");
66  1 ViewPage vp = wep.clickSaveAndView();
67   
68    // Add an XWikiGroups object
69  1 ObjectEditPage oep = vp.editObjects();
70  1 oep.addObject("XWiki.XWikiGroups");
71  1 vp = oep.clickSaveAndView();
72   
73  1 oep = vp.editObjects();
74  1 Assert.assertEquals(1, oep.getObjectsOfClass("XWiki.XWikiGroups").size());
75    }
76   
77    /**
78    * Tests that XWIKI-1621 remains fixed.
79    */
 
80  1 toggle @Test
81    @IgnoreBrowsers({
82    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
83    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
84    })
85    public void testChangeMultiselectProperty()
86    {
87    // Create a class with a database list property set to return all documents
88  1 ClassEditPage cep = ClassEditPage.gotoPage("Test", "EditObjectsTestClass");
89  1 cep.addProperty("prop", "DBList");
90  1 cep.getDatabaseListClassEditElement("prop").setHibernateQuery(
91    "select doc.fullName from XWikiDocument doc where doc.space = 'Test'");
92  1 cep.clickSaveAndView();
93   
94    // Create a second page to hold the Object and set its content
95  1 WikiEditPage wep = WikiEditPage.gotoPage("Test", "EditObjectsTestObject");
96  1 wep.setContent("this is the content");
97  1 ViewPage vp = wep.clickSaveAndView();
98   
99    // Add an object of the class created and set the value to be the test page
100  1 ObjectEditPage oep = vp.editObjects();
101  1 FormElement objectForm = oep.addObject("Test.EditObjectsTestClass");
102  1 objectForm.setFieldValue(By.id("Test.EditObjectsTestClass_0_prop"), "Test.EditObjectsTestClass");
103  1 oep.clickSaveAndView();
104   
105    // Set multiselect to true
106  1 cep = ClassEditPage.gotoPage("Test", "EditObjectsTestClass");
107  1 cep.getDatabaseListClassEditElement("prop").setMultiSelect(true);
108  1 cep.clickSaveAndView();
109   
110    // Select a second document in the DB list select field.
111  1 oep = ObjectEditPage.gotoPage("Test", "EditObjectsTestObject");
112  1 oep.getObjectsOfClass("Test.EditObjectsTestClass").get(0).setFieldValue(
113    By.id("Test.EditObjectsTestClass_0_prop"), "Test.EditObjectsTestObject");
114  1 vp = oep.clickSaveAndView();
115   
116  1 Assert.assertEquals("this is the content", vp.getContent());
117    }
118   
119    /**
120    * Tests that XWIKI-2214 remains fixed.
121    */
 
122  1 toggle @Test
123    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146")
124    public void testChangeNumberType()
125    {
126    // Create class page
127  1 WikiEditPage wep = WikiEditPage.gotoPage("Test", "EditObjectsTestClass");
128  1 wep.setContent("this is the content");
129  1 ViewPage vp = wep.clickSaveAndView();
130   
131    // Add class
132  1 ClassEditPage cep = vp.editClass();
133  1 cep.addProperty("prop", "Number");
134  1 cep.getNumberClassEditElement("prop").setNumberType("integer");
135  1 vp = cep.clickSaveAndView();
136  1 Assert.assertEquals("this is the content", vp.getContent());
137   
138    // Create object page
139  1 wep = WikiEditPage.gotoPage("Test", "EditObjectsTestObject");
140  1 wep.setContent("this is the content: {{velocity}}$doc.display('prop'){{/velocity}}");
141  1 vp = wep.clickSaveAndView();
142   
143    // Add object
144  1 ObjectEditPage oep = vp.editObjects();
145  1 FormElement objectForm = oep.addObject("Test.EditObjectsTestClass");
146  1 objectForm.setFieldValue(By.id("Test.EditObjectsTestClass_0_prop"), "3");
147  1 vp = oep.clickSaveAndView();
148  1 Assert.assertEquals("this is the content: 3", vp.getContent());
149   
150    // Change number to double type
151  1 cep = ClassEditPage.gotoPage("Test", "EditObjectsTestClass");
152  1 cep.getNumberClassEditElement("prop").setNumberType("double");
153  1 vp = cep.clickSaveAndView();
154  1 Assert.assertEquals("this is the content", vp.getContent());
155   
156    // Verify conversion
157  1 oep = ObjectEditPage.gotoPage("Test", "EditObjectsTestObject");
158  1 oep.getObjectsOfClass("Test.EditObjectsTestClass").get(0).setFieldValue(
159    By.id("Test.EditObjectsTestClass_0_prop"), "2.5");
160  1 vp = oep.clickSaveAndView();
161  1 Assert.assertEquals("this is the content: 2.5", vp.getContent());
162   
163    // Change number to long type
164  1 cep = ClassEditPage.gotoPage("Test", "EditObjectsTestClass");
165  1 cep.getNumberClassEditElement("prop").setNumberType("long");
166  1 vp = cep.clickSaveAndView();
167  1 Assert.assertEquals("this is the content", vp.getContent());
168   
169    // Verify conversion
170  1 oep = ObjectEditPage.gotoPage("Test", "EditObjectsTestObject");
171  1 vp = oep.clickSaveAndView();
172  1 Assert.assertEquals("this is the content: 2", vp.getContent());
173    }
174   
175    /**
176    * Prove that a list can be changed from relational storage to plain storage and back without database corruption.
177    * XWIKI-299 test
178    */
 
179  1 toggle @Test
180    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146")
181    public void testChangeListMultipleSelect()
182    {
183    // Create class page
184  1 WikiEditPage wep = WikiEditPage.gotoPage("Test", "EditObjectsTestClass");
185  1 wep.setContent("this is the content");
186  1 ViewPage vp = wep.clickSaveAndView();
187   
188    // Add class
189  1 ClassEditPage cep = vp.editClass();
190  1 cep.addProperty("prop", "StaticList");
191  1 StaticListClassEditElement slcee = cep.getStaticListClassEditElement("prop");
192  1 slcee.setMultiSelect(false);
193  1 slcee.setValues("choice 1|choice 2|choice 3|choice 4|choice 5");
194  1 vp = cep.clickSaveAndView();
195  1 Assert.assertEquals("this is the content", vp.getContent());
196   
197    // Create object page
198  1 wep = WikiEditPage.gotoPage("Test", "EditObjectsTestObject");
199  1 wep.setContent("this is the content: {{velocity}}$doc.display('prop'){{/velocity}}");
200  1 vp = wep.clickSaveAndView();
201   
202    // Add object
203  1 ObjectEditPage oep = vp.editObjects();
204  1 FormElement objectForm = oep.addObject("Test.EditObjectsTestClass");
205  1 objectForm.setFieldValue(By.id("Test.EditObjectsTestClass_0_prop"), "choice 3");
206  1 vp = oep.clickSaveAndView();
207  1 Assert.assertEquals("this is the content: choice 3", vp.getContent());
208   
209    // Change list to a multiple select.
210  1 cep = ClassEditPage.gotoPage("Test", "EditObjectsTestClass");
211  1 cep.getStaticListClassEditElement("prop").setMultiSelect(true);
212  1 vp = cep.clickSaveAndView();
213  1 Assert.assertEquals("this is the content", vp.getContent());
214   
215    // Verify conversion
216  1 oep = ObjectEditPage.gotoPage("Test", "EditObjectsTestObject");
217  1 oep.getObjectsOfClass("Test.EditObjectsTestClass").get(0).setFieldValue(
218    By.id("Test.EditObjectsTestClass_0_prop"), "choice 3");
219  1 oep.getObjectsOfClass("Test.EditObjectsTestClass").get(0).setFieldValue(
220    By.id("Test.EditObjectsTestClass_0_prop"), "choice 4");
221  1 vp = oep.clickSaveAndView();
222  1 Assert.assertEquals("this is the content: choice 3 choice 4", vp.getContent());
223    }
224   
225    /**
226    * Prove that a list can be changed from relational storage to plain storage and back without database corruption.
227    * XWIKI-1621: Changing parameters of list properties fails
228    */
 
229  1 toggle @Test
230    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146")
231    public void testChangeListTypeRelationalStorage()
232    {
233    // Create class page
234  1 WikiEditPage wep = WikiEditPage.gotoPage("Test", "EditObjectsTestClass");
235  1 wep.setContent("this is the content");
236  1 ViewPage vp = wep.clickSaveAndView();
237   
238    // Add class
239  1 ClassEditPage cep = vp.editClass();
240  1 cep.addProperty("prop", "StaticList");
241  1 StaticListClassEditElement slcee = cep.getStaticListClassEditElement("prop");
242  1 slcee.setMultiSelect(true);
243  1 slcee.setDisplayType(StaticListClassEditElement.DisplayType.INPUT);
244  1 vp = cep.clickSaveAndView();
245  1 Assert.assertEquals("this is the content", vp.getContent());
246   
247    // Create object page
248  1 wep = WikiEditPage.gotoPage("Test", "EditObjectsTestObject");
249  1 wep.setContent("this is the content: {{velocity}}$doc.display('prop'){{/velocity}}");
250  1 vp = wep.clickSaveAndView();
251   
252    // Add object
253  1 ObjectEditPage oep = vp.editObjects();
254  1 FormElement objectForm = oep.addObject("Test.EditObjectsTestClass");
255  1 objectForm.setFieldValue(By.id("Test.EditObjectsTestClass_0_prop"), "this|that|other");
256  1 vp = oep.clickSaveAndView();
257  1 Assert.assertEquals("this is the content: this that other", vp.getContent());
258   
259    // Change list to relational storage.
260  1 cep = ClassEditPage.gotoPage("Test", "EditObjectsTestClass");
261  1 cep.getStaticListClassEditElement("prop").setRelationalStorage(true);
262  1 vp = cep.clickSaveAndView();
263  1 Assert.assertEquals("this is the content", vp.getContent());
264   
265    // Make sure we can still edit the object.
266  1 oep = ObjectEditPage.gotoPage("Test", "EditObjectsTestObject");
267  1 oep.getObjectsOfClass("Test.EditObjectsTestClass").get(0).setFieldValue(
268    By.id("Test.EditObjectsTestClass_0_prop"), "this|other");
269  1 vp = oep.clickSaveAndView();
270  1 Assert.assertEquals("this is the content: this other", vp.getContent());
271   
272    // Change list to non-relational storage.
273  1 cep = ClassEditPage.gotoPage("Test", "EditObjectsTestClass");
274  1 cep.getStaticListClassEditElement("prop").setRelationalStorage(false);
275  1 vp = cep.clickSaveAndView();
276  1 Assert.assertEquals("this is the content", vp.getContent());
277   
278    // Make sure we can still edit the object.
279  1 oep = ObjectEditPage.gotoPage("Test", "EditObjectsTestObject");
280  1 oep.getObjectsOfClass("Test.EditObjectsTestClass").get(0).setFieldValue(
281    By.id("Test.EditObjectsTestClass_0_prop"), "that|other");
282  1 vp = oep.clickSaveAndView();
283  1 Assert.assertEquals("this is the content: that other", vp.getContent());
284    }
285   
 
286  1 toggle @Test
287    @IgnoreBrowsers({
288    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
289    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
290    })
291    public void testObjectAddAndRemove()
292    {
293  1 ObjectEditPage oep = ObjectEditPage.gotoPage("Test", "EditObjectsTestObject");
294  1 FormElement object = oep.addObject("XWiki.XWikiUsers");
295  1 object.setFieldValue(By.id("XWiki.XWikiUsers_0_first_name"), "John");
296   
297    // Add another object
298  1 FormElement object2 = oep.addObject("XWiki.XWikiUsers");
299   
300    // Check that the unsaved value from the first object wasn't lost
301  1 Assert.assertEquals("John", object.getFieldValue(By.id("XWiki.XWikiUsers_0_first_name")));
302    // Check that the value from the second object is unset
303  1 Assert.assertEquals("", object2.getFieldValue(By.id("XWiki.XWikiUsers_1_first_name")));
304   
305    // Delete the second object
306  1 oep.deleteObject("XWiki.XWikiUsers", 1);
307   
308    // Let's save the form and check that changes were persisted.
309  1 oep = oep.clickSaveAndView().editObjects();
310  1 List<ObjectEditPane> xwikiUsersForms = oep.getObjectsOfClass("XWiki.XWikiUsers");
311  1 Assert.assertEquals(1, xwikiUsersForms.size());
312  1 Assert.assertEquals("John", xwikiUsersForms.get(0).getFieldValue(By.id("XWiki.XWikiUsers_0_first_name")));
313    }
314   
 
315  1 toggle @Test
316    public void testInlineObjectAddButton()
317    {
318  1 ObjectEditPage oep = ObjectEditPage.gotoPage("Test", "EditObjectsTestObject");
319  1 oep.addObject("XWiki.XWikiUsers");
320  1 oep.addObjectFromInlineLink("XWiki.XWikiUsers");
321    }
322   
323    /**
324    * @see <a href="http://jira.xwiki.org/browse/XWIKI-9061">XWIKI-9061</a>: Property displayers don't work in the
325    * object editor for objects that have just been added
326    */
 
327  1 toggle @Test
328    public void testPropertyDisplayersForNewObjects() throws Exception
329    {
330  1 getUtil().rest().deletePage(getTestClassName(), getTestMethodName());
331   
332    // Create a class with two properties: a date and a list of users.
333  1 ClassEditPage classEditor = ClassEditPage.gotoPage(getTestClassName(), getTestMethodName());
334  1 classEditor.addProperty("date", "Date");
335  1 classEditor.addProperty("author", "Users");
336   
337    // Add an object of this class and set its properties.
338  1 String className = getTestClassName() + "." + getTestMethodName();
339  1 ObjectEditPage objectEditor = ObjectEditPage.gotoPage(getTestClassName(), getTestMethodName());
340  1 ObjectEditPane object = objectEditor.addObject(className);
341  1 object.openDatePicker("date").setDay("15");
342  1 object.getUserPicker("author").sendKeys("ad").waitForSuggestions().select("Admin");
343   
344    // Save, edit again and check the values.
345  1 object = objectEditor.clickSaveAndView().editObjects().getObjectsOfClass(className).get(0);
346  1 Assert.assertEquals("15", object.openDatePicker("date").getDay());
347  1 Assert.assertEquals("Administrator", object.getUserPicker("author").waitToLoad().getAcceptedSuggestions()
348    .get(0).getName());
349    }
350    }