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

File CurrentUserAndGroupDocumentReferenceResolverTest.java

 

Code metrics

0
8
2
1
76
44
2
0.25
4
2
1

Classes

Class Line # Actions
CurrentUserAndGroupDocumentReferenceResolverTest 44 8 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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.security.authorization.internal.resolver;
21   
22    import org.junit.Rule;
23    import org.junit.Test;
24    import org.xwiki.component.manager.ComponentLookupException;
25    import org.xwiki.model.EntityType;
26    import org.xwiki.model.reference.DocumentReference;
27    import org.xwiki.model.reference.DocumentReferenceResolver;
28    import org.xwiki.model.reference.EntityReferenceProvider;
29    import org.xwiki.model.reference.WikiReference;
30    import org.xwiki.test.annotation.AfterComponent;
31    import org.xwiki.test.annotation.AllComponents;
32    import org.xwiki.test.mockito.MockitoComponentMockingRule;
33   
34    import static org.junit.Assert.assertEquals;
35    import static org.junit.Assert.assertNull;
36    import static org.mockito.Mockito.when;
37   
38    /**
39    * Validate {@link CurrentUserAndGroupDocumentReferenceResolver}.
40    *
41    * @version $Id: 67e167aa731149f12e6368430250456cb64f4eaa $
42    */
43    @AllComponents
 
44    public class CurrentUserAndGroupDocumentReferenceResolverTest
45    {
46    @Rule
47    public MockitoComponentMockingRule<DocumentReferenceResolver<String>> mocker =
48    new MockitoComponentMockingRule<DocumentReferenceResolver<String>>(
49    CurrentUserAndGroupDocumentReferenceResolver.class);
50   
 
51  1 toggle @AfterComponent
52    public void afterComponent() throws Exception
53    {
54  1 EntityReferenceProvider provider = this.mocker.registerMockComponent(EntityReferenceProvider.class, "current");
55   
56  1 when(provider.getDefaultReference(EntityType.WIKI)).thenReturn(new WikiReference("currentwiki"));
57    }
58   
 
59  1 toggle @Test
60    public void testResolver() throws ComponentLookupException
61    {
62  1 assertEquals(new DocumentReference("currentwiki", "XWiki", "Bosse"), this.mocker.getComponentUnderTest()
63    .resolve("Bosse"));
64  1 assertEquals(new DocumentReference("currentwiki", "bossesSpace", "Bosse"), this.mocker.getComponentUnderTest()
65    .resolve("bossesSpace.Bosse"));
66  1 assertEquals(new DocumentReference("bossesWiki", "XWiki", "Bosse"), this.mocker.getComponentUnderTest()
67    .resolve("Bosse", new WikiReference("bossesWiki")));
68  1 assertEquals(new DocumentReference("bossesWiki", "bossesSpace", "Bosse"), this.mocker.getComponentUnderTest()
69    .resolve("bossesSpace.Bosse", new WikiReference("bossesWiki")));
70  1 assertEquals(new DocumentReference("bossesWiki", "bossesSpace", "Bosse"), this.mocker.getComponentUnderTest()
71    .resolve("bossesWiki:bossesSpace.Bosse"));
72   
73    // If null is passed we expect no reference (i.e. the guest user).
74  1 assertNull(this.mocker.getComponentUnderTest().resolve(null));
75    }
76    }