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

File DocumentTreeElement.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

6
32
18
1
211
111
21
0.66
1.78
18
1.17

Classes

Class Line # Actions
DocumentTreeElement 40 32 0% 21 19
0.6607142766.1%
 

Contributing tests

This file is covered by 5 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.index.tree.test.po;
21   
22    import java.util.Arrays;
23    import java.util.List;
24   
25    import org.openqa.selenium.WebElement;
26    import org.xwiki.model.internal.reference.DefaultStringEntityReferenceSerializer;
27    import org.xwiki.model.internal.reference.DefaultSymbolScheme;
28    import org.xwiki.model.reference.AttachmentReference;
29    import org.xwiki.model.reference.DocumentReference;
30    import org.xwiki.model.reference.EntityReference;
31    import org.xwiki.tree.test.po.TreeElement;
32    import org.xwiki.tree.test.po.TreeNodeElement;
33   
34    /**
35    * Page object used to interact with the document tree.
36    *
37    * @version $Id: e36c32693f4c685dda1921f1d8fd0080cacc6793 $
38    * @since 6.3RC1
39    */
 
40    public class DocumentTreeElement extends TreeElement
41    {
42    private DefaultStringEntityReferenceSerializer entityReferenceSerializer =
43    new DefaultStringEntityReferenceSerializer(new DefaultSymbolScheme());
44   
45    /**
46    * Creates a new instance that can be used to interact with the document tree represented by the given element.
47    *
48    * @param element the element that represents the document tree
49    */
 
50  6 toggle public DocumentTreeElement(WebElement element)
51    {
52  6 super(element);
53    }
54   
 
55  5 toggle @Override
56    public DocumentTreeElement openTo(String nodeId)
57    {
58  5 return (DocumentTreeElement) super.openTo(nodeId);
59    }
60   
 
61  4 toggle @Override
62    public DocumentTreeElement clearSelection()
63    {
64  4 return (DocumentTreeElement) super.clearSelection();
65    }
66   
67    /**
68    * Opens the tree to the specified space.
69    *
70    * @param path the path used to locate the space
71    * @return this tree
72    */
 
73  0 toggle public DocumentTreeElement openToSpace(String... path)
74    {
75  0 return openTo(getSpaceNodeId(path));
76    }
77   
78    /**
79    * Opens the tree to the specified document.
80    *
81    * @param path the path used to locate the document
82    * @return this tree
83    */
 
84  5 toggle public DocumentTreeElement openToDocument(String... path)
85    {
86  5 return openTo(getDocumentNodeId(path));
87    }
88   
89    /**
90    * Opens the tree to the specified attachment.
91    *
92    * @param path the path used to locate the attachment
93    * @return this tree
94    */
 
95  0 toggle public DocumentTreeElement openToAttachment(String... path)
96    {
97  0 return openTo(getAttachmentNodeId(path));
98    }
99   
 
100  8 toggle @Override
101    public DocumentTreeElement waitForIt()
102    {
103  8 return (DocumentTreeElement) super.waitForIt();
104    }
105   
106    /**
107    * Waits for the specified document to be selected.
108    *
109    * @param path the path used to locate the document to wait for
110    * @return this tree
111    * @since 7.2
112    */
 
113  1 toggle public DocumentTreeElement waitForDocumentSelected(String... path)
114    {
115  1 return (DocumentTreeElement) super.waitForNodeSelected(getDocumentNodeId(path));
116    }
117   
118    /**
119    * @param path the path used to locate the space
120    * @return {@code true} if the specified space appears in the tree
121    */
 
122  0 toggle public boolean hasSpace(String... path)
123    {
124  0 return hasNode(getSpaceNodeId(path));
125    }
126   
127    /**
128    * @param path the path used to locate the document
129    * @return {@code true} if the specified document appears in the tree
130    */
 
131  6 toggle public boolean hasDocument(String... path)
132    {
133  6 return hasNode(getDocumentNodeId(path));
134    }
135   
136    /**
137    * @param path the path used to locate the attachment
138    * @return {@code true} if the specified attachment is present in the tree
139    */
 
140  1 toggle public boolean hasAttachment(String... path)
141    {
142  1 return hasNode(getAttachmentNodeId(path));
143    }
144   
145    /**
146    * @param path the path used to locate the space
147    * @return the corresponding space node
148    */
 
149  0 toggle public TreeNodeElement getSpaceNode(String... path)
150    {
151  0 return getNode(getSpaceNodeId(path));
152    }
153   
154    /**
155    * @param path the path used to locate the document
156    * @return the corresponding document node
157    */
 
158  4 toggle public TreeNodeElement getDocumentNode(String... path)
159    {
160  4 return getNode(getDocumentNodeId(path));
161    }
162   
163    /**
164    * @param path the path used to locate the attachment
165    * @return the corresponding attachment node
166    */
 
167  1 toggle public TreeNodeElement getAttachmentNode(String... path)
168    {
169  1 return getNode(getAttachmentNodeId(path));
170    }
171   
 
172  18 toggle private String getNodeId(EntityReference reference)
173    {
174  18 return reference.getType().getLowerCase() + ":" + this.entityReferenceSerializer.serialize(reference);
175    }
176   
 
177  0 toggle private String getSpaceNodeId(String... path)
178    {
179  0 if (path.length > 0) {
180  0 DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList(path), "WebHome");
181  0 return getNodeId(documentReference.getParent());
182    } else {
183  0 throw new IllegalArgumentException("Incomplete path: it should have at least 1 element (space)");
184    }
185    }
186   
 
187  16 toggle private String getDocumentNodeId(String... path)
188    {
189  16 if (path.length > 1) {
190  16 List<String> pathElements = Arrays.asList(path);
191  16 List<String> spaces = pathElements.subList(0, path.length - 1);
192  16 String document = path[path.length - 1];
193  16 return getNodeId(new DocumentReference("xwiki", spaces, document));
194    } else {
195  0 throw new IllegalArgumentException("Incomplete path: it should have at least 2 elements (space/page)");
196    }
197    }
198   
 
199  2 toggle private String getAttachmentNodeId(String... path)
200    {
201  2 if (path.length > 2) {
202  2 List<String> pathElements = Arrays.asList(path);
203  2 List<String> spaces = pathElements.subList(0, path.length - 2);
204  2 String document = path[path.length - 2];
205  2 String fileName = path[path.length - 1];
206  2 return getNodeId(new AttachmentReference(fileName, new DocumentReference("xwiki", spaces, document)));
207    } else {
208  0 throw new IllegalArgumentException("Incomplete path: it should have at least 3 elements (space/page/file)");
209    }
210    }
211    }