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

File SolrFieldStringEntityReferenceResolverTest.java

 

Code metrics

0
11
1
1
89
49
1
0.09
11
1
1

Classes

Class Line # Actions
SolrFieldStringEntityReferenceResolverTest 45 11 0% 1 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.search.solr.internal;
21   
22    import java.util.Arrays;
23   
24    import org.junit.Rule;
25    import org.junit.Test;
26    import org.xwiki.model.EntityType;
27    import org.xwiki.model.reference.ClassPropertyReference;
28    import org.xwiki.model.reference.DocumentReference;
29    import org.xwiki.model.reference.EntityReference;
30    import org.xwiki.model.reference.EntityReferenceProvider;
31    import org.xwiki.model.reference.EntityReferenceResolver;
32    import org.xwiki.model.reference.SpaceReference;
33    import org.xwiki.model.reference.WikiReference;
34    import org.xwiki.test.mockito.MockitoComponentMockingRule;
35   
36    import static org.junit.Assert.*;
37    import static org.mockito.Mockito.*;
38   
39    /**
40    * Unit tests for {@link SolrFieldStringEntityReferenceResolver}.
41    *
42    * @version $Id: 494147eac92aff82058e555e2870598cad36d3a7 $
43    * @since 5.3RC1
44    */
 
45    public class SolrFieldStringEntityReferenceResolverTest
46    {
47    @Rule
48    public MockitoComponentMockingRule<EntityReferenceResolver<String>> mocker =
49    new MockitoComponentMockingRule<EntityReferenceResolver<String>>(SolrFieldStringEntityReferenceResolver.class);
50   
 
51  1 toggle @Test
52    public void resolve() throws Exception
53    {
54  1 EntityReferenceProvider currentEntityReferenceProvider =
55    this.mocker.getInstance(EntityReferenceProvider.class, "current");
56  1 when(currentEntityReferenceProvider.getDefaultReference(EntityType.WIKI)).thenReturn(new WikiReference("test"));
57   
58  1 EntityReferenceResolver<String> resolver = mocker.getComponentUnderTest();
59   
60  1 DocumentReference documentReference =
61    new DocumentReference("test", Arrays.asList("My App", "Code", "Model"), "A Class");
62  1 assertEquals(new ClassPropertyReference("title", documentReference),
63    new ClassPropertyReference(resolver.resolve("My App.Code.Model.A Class.title", EntityType.CLASS_PROPERTY)));
64   
65  1 documentReference = new DocumentReference("test", Arrays.asList("My.App", "Co.de"), "A.Class");
66  1 assertEquals(new ClassPropertyReference("ti.tle", documentReference),
67    new ClassPropertyReference(resolver.resolve("My..App.Co..de.A..Class.ti..tle", EntityType.CLASS_PROPERTY)));
68   
69  1 assertEquals(new SpaceReference("0.9", new SpaceReference("a..z", new WikiReference("test"))),
70    new SpaceReference(resolver.resolve("a....z.0..9", EntityType.SPACE)));
71   
72    // Relative reference resolved based on the given parameters.
73   
74  1 assertEquals(
75    new ClassPropertyReference("title", new DocumentReference("foo", Arrays.asList("Code", "Model"), "A Class")),
76    new ClassPropertyReference(resolver.resolve("Code.Model.A Class.title", EntityType.CLASS_PROPERTY,
77    new SpaceReference("My App", new WikiReference("foo")))));
78   
79    // Relative reference resolve based on the current entity.
80   
81  1 when(currentEntityReferenceProvider.getDefaultReference(EntityType.SPACE)).thenReturn(
82    new EntityReference("Code", EntityType.SPACE, new EntityReference("My App", EntityType.SPACE, null)));
83  1 assertEquals(
84    new ClassPropertyReference("title",
85    new DocumentReference("bar", Arrays.asList("My App", "Code"), "A Class")),
86    new ClassPropertyReference(resolver.resolve("A Class.title", EntityType.CLASS_PROPERTY, new WikiReference(
87    "bar"))));
88    }
89    }