1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.model.internal.reference

File ExplicitReferenceEntityReferenceResolverTest.java

 

Code metrics

0
41
8
1
136
97
11
0.27
5.12
8
1.38

Classes

Class Line # Actions
ExplicitReferenceEntityReferenceResolverTest 36 41 0% 11 3
0.9387755493.9%
 

Contributing tests

This file is covered by 7 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: 1c295800350494b19ef492a7e4974e86f3aeede3 $
34    * @since 2.2.3
35    */
 
36    public class ExplicitReferenceEntityReferenceResolverTest
37    {
38    private EntityReferenceResolver<EntityReference> resolver;
39   
 
40  7 toggle @Before
41    public void setUp() throws Exception
42    {
43  7 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 testResolveWithNoExplicitAndPartialReference()
103    {
104  1 try {
105  1 this.resolver.resolve(null, EntityType.DOCUMENT);
106  0 Assert.fail("Should have raised an exception");
107    } catch (IllegalArgumentException expected) {
108  1 Assert.assertEquals("The resolver parameter doesn't contain an Entity Reference of type [DOCUMENT]",
109    expected.getMessage());
110    }
111    }
112   
 
113  1 toggle @Test
114    public void testResolveWithInvalidParameterType()
115    {
116  1 try {
117  1 this.resolver.resolve(null, EntityType.DOCUMENT, "wrong type");
118  0 Assert.fail("Should have raised an exception");
119    } catch (IllegalArgumentException expected) {
120  1 Assert.assertEquals("The resolver parameter doesn't contain an Entity Reference of type [DOCUMENT]",
121    expected.getMessage());
122    }
123    }
124   
 
125  1 toggle @Test
126    public void testResolveWithIncompleteExplicitReference()
127    {
128  1 try {
129  1 this.resolver.resolve(null, EntityType.DOCUMENT, new EntityReference("wiki", EntityType.WIKI));
130  0 Assert.fail("Should have raised an exception");
131    } catch (IllegalArgumentException expected) {
132  1 Assert.assertEquals("The resolver parameter doesn't contain an Entity Reference of type [DOCUMENT]",
133    expected.getMessage());
134    }
135    }
136    }