1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.security.authorization.testwikis.internal.entities

File DefaultTestWiki.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

10
27
13
1
163
103
18
0.67
2.08
13
1.38

Classes

Class Line # Actions
DefaultTestWiki 44 27 0% 18 5
0.990%
 

Contributing tests

This file is covered by 15 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   
21    package org.xwiki.security.authorization.testwikis.internal.entities;
22   
23    import java.util.Collection;
24   
25    import org.xwiki.model.EntityType;
26    import org.xwiki.model.reference.DocumentReference;
27    import org.xwiki.model.reference.EntityReference;
28    import org.xwiki.model.reference.SpaceReference;
29    import org.xwiki.model.reference.WikiReference;
30    import org.xwiki.security.authorization.testwikis.TestDocument;
31    import org.xwiki.security.authorization.testwikis.TestEntity;
32    import org.xwiki.security.authorization.testwikis.TestGroupDocument;
33    import org.xwiki.security.authorization.testwikis.TestSpace;
34    import org.xwiki.security.authorization.testwikis.TestUserDocument;
35    import org.xwiki.security.authorization.testwikis.TestWiki;
36    import org.xwiki.security.authorization.testwikis.internal.parser.XWikiConstants;
37   
38    /**
39    * Entity representing a wiki.
40    *
41    * @version $Id: a81d913332f2e2317be8ab59a08ca85568ba0eb5 $
42    * @since 5.0M2
43    */
 
44    public class DefaultTestWiki extends AbstractSecureTestEntity implements TestWiki
45    {
46    /** The type of reference used by this class. */
47    public static final EntityType TYPE = EntityType.WIKI;
48   
49    /** When true, this entity represent the main wiki. */
50    private final boolean isMainWiki;
51   
52    /** The owner of this wiki. */
53    private final DocumentReference owner;
54   
55    /** The alternate description of this entity. */
56    private final String description;
57   
58    /**
59    * Create a new wiki entity.
60    * @param reference reference of document represented by this entity.
61    * @param isMainWiki true if this entity represent the main wiki.
62    * @param owner owner of this wiki.
63    * @param description alternate description of this entity.
64    * @param parent parent entity of this entity.
65    */
 
66  55 toggle public DefaultTestWiki(EntityReference reference, boolean isMainWiki, EntityReference owner, String description,
67    TestEntity parent) {
68  55 super(reference, parent);
69   
70  55 this.isMainWiki = isMainWiki;
71  55 this.owner = (owner != null) ? new DocumentReference(owner)
72    : new DocumentReference(XWikiConstants.SUPERADMIN, new SpaceReference(XWikiConstants.XWIKI_SPACE,
73    getWikiReference()));
74  55 ;
75  55 this.description = description;
76   
77  55 if (isMainWiki) {
78  15 ((DefaultTestDefinition) parent).setMainWiki(this);
79    }
80    }
81   
 
82  42 toggle @Override
83    public EntityType getType()
84    {
85  42 return TYPE;
86    }
87   
 
88  322 toggle @Override
89    public WikiReference getWikiReference()
90    {
91  322 return new WikiReference(getReference());
92    }
93   
 
94  97 toggle @Override
95    public DocumentReference getOwner()
96    {
97  97 return owner;
98    }
99   
 
100  43 toggle @Override
101    public boolean isMainWiki()
102    {
103  43 return isMainWiki;
104    }
105   
 
106  1 toggle @Override
107    public TestSpace getSpace(String name)
108    {
109  1 return getSpace(new SpaceReference(name, getWikiReference()));
110    }
111   
 
112  87 toggle @Override
113    public TestSpace getSpace(SpaceReference reference)
114    {
115  87 return (TestSpace) getEntity(reference);
116    }
117   
 
118  1 toggle @Override
119    public Collection<TestSpace> getSpaces()
120    {
121  1 return TypeFilteredCollection.getNewInstance(getEntities(), TestSpace.class);
122    }
123   
 
124  0 toggle @Override
125    public String getDescription()
126    {
127  0 return description;
128    }
129   
 
130  84 toggle @Override
131    public TestUserDocument getUser(String name)
132    {
133  84 SpaceReference spaceRef = new SpaceReference(XWikiConstants.XWIKI_SPACE, getWikiReference());
134  84 TestSpace space = getSpace(spaceRef);
135  84 if (space == null) {
136  0 return null;
137    }
138  84 TestDocument user = space.getDocument(new DocumentReference(name, spaceRef));
139  84 return (user instanceof TestUserDocument) ? (TestUserDocument) user : null;
140    }
141   
 
142  1 toggle @Override
143    public TestGroupDocument getGroup(String name)
144    {
145  1 TestDocument group = getUser(name);
146  1 return (group instanceof TestGroupDocument) ? (TestGroupDocument) group : null;
147    }
148   
 
149  1 toggle @Override
150    public Collection<TestUserDocument> getUsers()
151    {
152  1 TestSpace space = getSpace(new SpaceReference(XWikiConstants.XWIKI_SPACE, getWikiReference()));
153  1 return TypeFilteredCollection.getNewInstance(space.getEntities(), TestUserDocument.class);
154    }
155   
 
156  1 toggle @Override
157    public Collection<TestGroupDocument> getGroups()
158    {
159  1 TestSpace space = getSpace(new SpaceReference(XWikiConstants.XWIKI_SPACE, getWikiReference()));
160  1 return TypeFilteredCollection.getNewInstance(space.getEntities(), TestGroupDocument.class);
161    }
162   
163    }