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

File TestGroupUserFactory.java

 

Coverage histogram

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

Code metrics

2
8
3
1
69
34
4
0.5
2.67
3
1.33

Classes

Class Line # Actions
TestGroupUserFactory 39 8 0% 4 2
0.8461538684.6%
 

Contributing tests

This file is covered by 6 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.parser;
22   
23    import java.util.Arrays;
24    import java.util.List;
25   
26    import org.xml.sax.Attributes;
27    import org.xml.sax.SAXException;
28    import org.xwiki.model.reference.EntityReference;
29    import org.xwiki.security.authorization.testwikis.TestEntity;
30    import org.xwiki.security.authorization.testwikis.TestGroup;
31    import org.xwiki.security.authorization.testwikis.internal.entities.DefaultTestGroup;
32   
33    /**
34    * Factory creating links between user and their groups.
35    *
36    * @version $Id: 3eb3659875ba96e6e59c1e22d7d882fff9e8ae17 $
37    * @since 5.0M2
38    */
 
39    public class TestGroupUserFactory extends AbstractEntityFactory<TestGroup>
40    {
41    /**
42    * Create a new factory for link between user (the parent) and groups.
43    * @param parent parent entity to used by this factory.
44    */
 
45  26 toggle TestGroupUserFactory(TestEntity parent)
46    {
47  26 setParent(parent);
48    }
49   
 
50  26 toggle @Override
51    public List<String> getTagNames()
52    {
53  26 return Arrays.asList("user", "group");
54    }
55   
 
56  32 toggle @Override
57    TestGroup getNewInstance(ElementParser parser, String name, TestEntity parent, Attributes attributes)
58    throws SAXException
59    {
60  32 EntityReference reference = parser.getResolver().resolve(attributes.getValue("name"), parent.getType(),
61    parent.getReference());
62  32 TestEntity entity = parser.getWikis().searchEntity(reference);
63  32 if (entity == null) {
64  0 throw new SAXException(parser.getLocatedMessage("User/Group [%s] is undefined.", reference));
65    }
66  32 new DefaultTestGroup(parser.getSerializer().serialize(parent.getReference()), parent.getReference(), entity);
67  32 return null;
68    }
69    }