1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.model.internal.reference

File ExplicitReferenceEntityReferenceResolverTest.java

 

Code metrics

0
48
9
1
151
110
12
0.25
5.33
9
1.33

Classes

Class Line # Actions
ExplicitReferenceEntityReferenceResolverTest 36 48 0% 12 3
0.9473684494.7%
 

Contributing tests

This file is covered by 8 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.model.internal.reference;
21   
22    import org.junit.Assert;
23    import org.junit.Before;
24    import org.junit.Test;
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.EntityReferenceResolver;
29   
30    /**
31    * Unit tests for {@link org.xwiki.model.internal.reference.ExplicitReferenceEntityReferenceResolver}.
32    *
33    * @version $Id: e46e53c76db6565e77f77a6e8cc7c989b2a582d7 $
34    * @since 2.2.3
35    */
 
36    public class ExplicitReferenceEntityReferenceResolverTest
37    {
38    private EntityReferenceResolver<EntityReference> resolver;
39   
 
40  8 toggle @Before
41    public void setUp() throws Exception
42    {
43  8 this.resolver = new ExplicitReferenceEntityReferenceResolver();
44    }
45   
 
46  1 toggle @Test
47    public void testResolveWithExplicitDocumentReference()
48    {
49  1 EntityReference reference =
50    this.resolver.resolve(null, EntityType.DOCUMENT, new DocumentReference("wiki", "space", "page"));
51   
52  1 Assert.assertEquals("page", reference.getName());
53  1 Assert.assertEquals(EntityType.DOCUMENT, reference.getType());
54  1 Assert.assertEquals("space", reference.getParent().getName());
55  1 Assert.assertEquals(EntityType.SPACE, reference.getParent().getType());
56  1 Assert.assertEquals("wiki", reference.getParent().getParent().getName());
57  1 Assert.assertEquals(EntityType.WIKI, reference.getParent().getParent().getType());
58    }
59   
 
60  1 toggle @Test
61    public void testResolveWithExplicitEntityReference()
62    {
63  1 EntityReference reference =
64    this.resolver.resolve(new EntityReference("page", EntityType.DOCUMENT, new EntityReference("space", EntityType.SPACE)), EntityType.DOCUMENT, new EntityReference("wiki", EntityType.WIKI));
65   
66  1 Assert.assertEquals("page", reference.getName());
67  1 Assert.assertEquals(EntityType.DOCUMENT, reference.getType());
68  1 Assert.assertEquals("space", reference.getParent().getName());
69  1 Assert.assertEquals(EntityType.SPACE, reference.getParent().getType());
70  1 Assert.assertEquals("wiki", reference.getParent().getParent().getName());
71  1 Assert.assertEquals(EntityType.WIKI, reference.getParent().getParent().getType());
72    }
73   
 
74  1 toggle @Test
75    public void testResolveWithAbsoluteReferenceAndNoExplicitReference()
76    {
77  1 EntityReference reference = this.resolver.resolve(new EntityReference("page", EntityType.DOCUMENT, new EntityReference("space", EntityType.SPACE, new EntityReference("wiki", EntityType.WIKI))), EntityType.DOCUMENT);
78   
79  1 Assert.assertEquals("page", reference.getName());
80  1 Assert.assertEquals(EntityType.DOCUMENT, reference.getType());
81  1 Assert.assertEquals("space", reference.getParent().getName());
82  1 Assert.assertEquals(EntityType.SPACE, reference.getParent().getType());
83  1 Assert.assertEquals("wiki", reference.getParent().getParent().getName());
84  1 Assert.assertEquals(EntityType.WIKI, reference.getParent().getParent().getType());
85    }
86   
 
87  1 toggle @Test
88    public void testResolveWithExplicitReferenceWithHoles()
89    {
90  1 EntityReference reference = this.resolver.resolve(new EntityReference("page", EntityType.DOCUMENT, new EntityReference("space", EntityType.SPACE)), EntityType.DOCUMENT,
91    new EntityReference("page", EntityType.DOCUMENT, new EntityReference("wiki", EntityType.WIKI)));
92   
93  1 Assert.assertEquals("page", reference.getName());
94  1 Assert.assertEquals(EntityType.DOCUMENT, reference.getType());
95  1 Assert.assertEquals("space", reference.getParent().getName());
96  1 Assert.assertEquals(EntityType.SPACE, reference.getParent().getType());
97  1 Assert.assertEquals("wiki", reference.getParent().getParent().getName());
98  1 Assert.assertEquals(EntityType.WIKI, reference.getParent().getParent().getType());
99    }
100   
 
101  1 toggle @Test
102    public void testResolveWithExplicitReferenceWithHolesAndIncompatibleParameter()
103    {
104  1 EntityReference reference = this.resolver.resolve(
105    new EntityReference("page", EntityType.DOCUMENT, new EntityReference("wiki", EntityType.WIKI)),
106    EntityType.DOCUMENT, new EntityReference("page", EntityType.PAGE));
107   
108  1 Assert.assertEquals("page", reference.getName());
109  1 Assert.assertEquals(EntityType.DOCUMENT, reference.getType());
110  1 Assert.assertEquals("page", reference.getParent().getName());
111  1 Assert.assertEquals(EntityType.SPACE, reference.getParent().getType());
112  1 Assert.assertEquals("wiki", reference.getParent().getParent().getName());
113  1 Assert.assertEquals(EntityType.WIKI, reference.getParent().getParent().getType());
114    }
115   
 
116  1 toggle @Test
117    public void testResolveWithNoExplicitAndPartialReference()
118    {
119  1 try {
120  1 this.resolver.resolve(null, EntityType.DOCUMENT);
121  0 Assert.fail("Should have raised an exception");
122    } catch (IllegalArgumentException expected) {
123  1 Assert.assertEquals("The resolver parameter doesn't contain an Entity Reference of type [DOCUMENT]",
124    expected.getMessage());
125    }
126    }
127   
 
128  1 toggle @Test
129    public void testResolveWithInvalidParameterType()
130    {
131  1 try {
132  1 this.resolver.resolve(null, EntityType.DOCUMENT, "wrong type");
133  0 Assert.fail("Should have raised an exception");
134    } catch (IllegalArgumentException expected) {
135  1 Assert.assertEquals("The resolver parameter doesn't contain an Entity Reference of type [DOCUMENT]",
136    expected.getMessage());
137    }
138    }
139   
 
140  1 toggle @Test
141    public void testResolveWithIncompleteExplicitReference()
142    {
143  1 try {
144  1 this.resolver.resolve(null, EntityType.DOCUMENT, new EntityReference("wiki", EntityType.WIKI));
145  0 Assert.fail("Should have raised an exception");
146    } catch (IllegalArgumentException expected) {
147  1 Assert.assertEquals("The resolver parameter doesn't contain an Entity Reference of type [DOCUMENT]",
148    expected.getMessage());
149    }
150    }
151    }