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

File CreatePageNestedDocumentsTest.java

 

Code metrics

2
30
4
1
145
81
5
0.17
7.5
4
1.25

Classes

Class Line # Actions
CreatePageNestedDocumentsTest 49 30 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 2 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.flamingo.test.ui;
21   
22    import java.util.Arrays;
23    import java.util.List;
24   
25    import org.junit.Before;
26    import org.junit.Rule;
27    import org.junit.Test;
28    import org.xwiki.model.reference.DocumentReference;
29    import org.xwiki.model.reference.EntityReference;
30    import org.xwiki.model.reference.SpaceReference;
31    import org.xwiki.model.reference.WikiReference;
32    import org.xwiki.test.ui.AbstractTest;
33    import org.xwiki.test.ui.SuperAdminAuthenticationRule;
34    import org.xwiki.test.ui.po.BreadcrumbElement;
35    import org.xwiki.test.ui.po.CreatePagePage;
36    import org.xwiki.test.ui.po.DocumentDoesNotExistPage;
37    import org.xwiki.test.ui.po.ViewPage;
38    import org.xwiki.test.ui.po.editor.EditPage;
39   
40    import static org.junit.Assert.assertEquals;
41    import static org.junit.Assert.assertFalse;
42   
43    /**
44    * Tests that the create action and UI properly create Nested Documents at various levels in the hierarchy.
45    *
46    * @version $Id: b0b883463da6c4323dbf08ab8fc3aa10b24a1375 $
47    * @since 7.2RC1
48    */
 
49    public class CreatePageNestedDocumentsTest extends AbstractTest
50    {
51    @Rule
52    public SuperAdminAuthenticationRule authenticationRule = new SuperAdminAuthenticationRule(getUtil());
53   
54    // @formatter:off
55    public static List<DocumentReference> nestedDocuments = Arrays.asList(
56    // /A (Top level document)
57    new DocumentReference("xwiki", Arrays.asList("A"), "WebHome"),
58    // /A/B (Child document of a top level document, A)
59    new DocumentReference("xwiki", Arrays.asList("A", "B"), "WebHome"),
60    // /A/B/C (Child document of a child document, B)
61    new DocumentReference("xwiki", Arrays.asList("A", "B", "C"), "WebHome"),
62    // /A/B/C/D (Child of a child, of a child, C)
63    new DocumentReference("xwiki", Arrays.asList("A", "B", "C", "D"), "WebHome"),
64    // /A/B/C/D/E (etc...)
65    new DocumentReference("xwiki", Arrays.asList("A", "B", "C", "D", "E"), "WebHome"),
66    // /A/B/C/D/E/F/G (Child document of a non-existing document, i.e. hole in the hierarchy at the end)
67    new DocumentReference("xwiki", Arrays.asList("A", "B", "C", "D", "E", "F", "G"), "WebHome"),
68    // /X/Y (Child document of a non-existing top level document, i.e. hole in the hierarchy at the beginning)
69    new DocumentReference("xwiki", Arrays.asList("X", "Y"), "WebHome"));
70    // @formatter:on
71   
 
72  2 toggle @Before
73    public void setup() throws Exception
74    {
75    // Cleanup to avoid problems from previous runs.
76  2 for (DocumentReference pageReference : nestedDocuments) {
77  14 getUtil().rest().delete(pageReference);
78    }
79    }
80   
 
81  1 toggle @Test
82    public void createNestedDocumentsFromURL()
83    {
84    // Create and assert each nested document.
85  1 for (DocumentReference pageReference : nestedDocuments) {
86    // Navigate from URL to the page in view mode, using the no-WebHome URL, e.g. /A instead of /A/WebHome
87  7 SpaceReference spaceReference = pageReference.getLastSpaceReference();
88  7 ViewPage viewPage = getUtil().gotoPage(spaceReference);
89   
90    // It should not exist and we will create it.
91  7 assertFalse(String.format("Document [%s] already exists", pageReference), viewPage.exists());
92  7 new DocumentDoesNotExistPage().clickEditThisPageToCreate();
93  7 new CreatePagePage().clickCreate();
94  7 EditPage editPage = new EditPage();
95  7 viewPage = editPage.clickSaveAndView();
96   
97    // Check that we created the right page
98  7 assertCreatedNestedDocument(pageReference, viewPage);
99    }
100    }
101   
 
102  1 toggle @Test
103    public void createNestedDocumentsFromUI()
104    {
105    // Create the homepage if it does not exist and start the test from there.
106  1 DocumentReference homepage = new DocumentReference("xwiki", "Main", "WebHome");
107  1 ViewPage viewPage = getUtil().createPage(homepage, "", "Home Page");
108   
109    // Create and assert each nested document.
110  1 for (DocumentReference pageReference : nestedDocuments) {
111  7 SpaceReference spaceReference = pageReference.getLastSpaceReference();
112   
113    // Click the create button from the previous page.
114  7 CreatePagePage createPage = viewPage.createPage();
115   
116    // Determine the values to fill in the form.
117  7 WikiReference wikiReference = spaceReference.getWikiReference();
118  7 EntityReference localParentSpaceReference = spaceReference.removeParent(wikiReference).getParent();
119  7 String spaceReferenceString = getUtil().serializeReference(localParentSpaceReference);
120  7 String pageName = spaceReference.getName();
121   
122    // Fill in the form and submit it, using the space name as title.
123  7 EditPage editPage = createPage.createPage(pageName, spaceReferenceString, null, false);
124   
125    // Save the page.
126  7 viewPage = editPage.clickSaveAndView();
127   
128    // Check that we created the right page
129  7 assertCreatedNestedDocument(pageReference, viewPage);
130    }
131    }
132   
 
133  14 toggle private void assertCreatedNestedDocument(DocumentReference pageReference, ViewPage viewPage)
134    {
135  14 SpaceReference spaceReference = pageReference.getLastSpaceReference();
136   
137  14 BreadcrumbElement breadcrumb = viewPage.getBreadcrumb();
138  14 if (breadcrumb.canBeExpanded()) {
139  4 breadcrumb.expand();
140    }
141  14 assertEquals("/" + getUtil().getURLFragment(spaceReference), breadcrumb.getPathAsString());
142  14 assertEquals(spaceReference.getName(), viewPage.getDocumentTitle());
143  14 assertEquals(getUtil().serializeReference(pageReference), viewPage.getMetaDataValue("reference"));
144    }
145    }