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

File AbstractTestEntity.java

 

Coverage histogram

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

Code metrics

8
24
9
1
126
71
15
0.62
2.67
9
1.67

Classes

Class Line # Actions
AbstractTestEntity 36 24 0% 15 4
0.90243990.2%
 

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    import java.util.HashMap;
25    import java.util.Map;
26   
27    import org.xwiki.model.reference.EntityReference;
28    import org.xwiki.security.authorization.testwikis.TestEntity;
29   
30    /**
31    * Base class for all test entities.
32    *
33    * @version $Id: 851e589a70f65d135df1894eb4056fdbbe211e62 $
34    * @since 5.0M2
35    */
 
36    public abstract class AbstractTestEntity implements TestEntity
37    {
38    /** Reference of this entity. */
39    private final EntityReference reference;
40   
41    /** Parent entity of this entity. */
42    private final TestEntity parent;
43   
44    /** Map of children entities. */
45    private final Map<EntityReference, TestEntity> entities = new HashMap<EntityReference, TestEntity>();
46   
47    /** Create a new root entity (wikis). */
 
48  15 toggle AbstractTestEntity() {
49  15 reference = null;
50  15 parent = null;
51    }
52   
53    /**
54    * Create a new entity.
55    * @param reference reference for this entity.
56    * @param parent the parent entity of this entity.
57    */
 
58  1209 toggle AbstractTestEntity(EntityReference reference, TestEntity parent) {
59  1209 this.parent = parent;
60  1209 this.reference = reference;
61   
62  1209 addToParent(parent);
63    }
64   
65    /**
66    * Add the current entity to his parent. Called by the constructor, overridden in subclasses to attach to
67    * another collection of the parent then the default one.
68    * @param parent the parent to attach to.
69    */
 
70  340 toggle protected void addToParent(TestEntity parent) {
71  340 parent.add(this);
72    }
73   
 
74  3156 toggle @Override
75    public EntityReference getReference()
76    {
77  3156 return reference;
78    }
79   
 
80  340 toggle @Override
81    public void add(TestEntity entity)
82    {
83  340 entities.put(entity.getReference(), entity);
84    }
85   
 
86  459 toggle @Override
87    public TestEntity getEntity(EntityReference reference)
88    {
89  459 return entities.get(reference);
90    }
91   
 
92  84 toggle @Override
93    public Collection<TestEntity> getEntities()
94    {
95  84 return entities.values();
96    }
97   
 
98  766 toggle @Override
99    public TestEntity searchEntity(EntityReference reference)
100    {
101  766 EntityReference parentRef;
102  766 EntityReference currentRef = reference;
103  766 do {
104  1413 parentRef = currentRef.getParent();
105  1413 if (this.reference == parentRef || (this.reference != null && this.reference.equals(parentRef))) {
106  766 if (currentRef == reference) {
107  309 return entities.get(reference);
108    } else {
109  457 TestEntity child = entities.get(currentRef);
110  457 if (child == null) {
111  6 return null;
112    }
113  451 return child.searchEntity(reference);
114    }
115    }
116  647 currentRef = parentRef;
117  647 } while(currentRef != null);
118  0 return null;
119    }
120   
 
121  0 toggle @Override
122    public TestEntity getParent()
123    {
124  0 return parent;
125    }
126    }