1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.search.solr.internal.reference; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
import java.util.Locale; |
24 |
|
|
25 |
|
import org.apache.solr.common.SolrDocument; |
26 |
|
import org.junit.Before; |
27 |
|
import org.junit.Rule; |
28 |
|
import org.junit.Test; |
29 |
|
import org.mockito.invocation.InvocationOnMock; |
30 |
|
import org.mockito.stubbing.Answer; |
31 |
|
import org.xwiki.model.EntityType; |
32 |
|
import org.xwiki.model.reference.AttachmentReference; |
33 |
|
import org.xwiki.model.reference.DocumentReference; |
34 |
|
import org.xwiki.model.reference.EntityReference; |
35 |
|
import org.xwiki.model.reference.EntityReferenceResolver; |
36 |
|
import org.xwiki.model.reference.ObjectPropertyReference; |
37 |
|
import org.xwiki.model.reference.ObjectReference; |
38 |
|
import org.xwiki.model.reference.SpaceReference; |
39 |
|
import org.xwiki.model.reference.WikiReference; |
40 |
|
import org.xwiki.search.solr.internal.api.FieldUtils; |
41 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
42 |
|
|
43 |
|
import static org.junit.Assert.*; |
44 |
|
import static org.mockito.ArgumentMatchers.*; |
45 |
|
import static org.mockito.Mockito.*; |
46 |
|
|
47 |
|
|
48 |
|
@link |
49 |
|
|
50 |
|
@version |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (31) |
Complexity: 4 |
Complexity Density: 0.15 |
|
52 |
|
public class SolrEntityReferenceResolverTest |
53 |
|
{ |
54 |
|
@Rule |
55 |
|
public MockitoComponentMockingRule<EntityReferenceResolver<SolrDocument>> mocker = |
56 |
|
new MockitoComponentMockingRule<EntityReferenceResolver<SolrDocument>>(SolrEntityReferenceResolver.class); |
57 |
|
|
58 |
|
private SolrDocument solrDocument; |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
|
60 |
1 |
@Before... |
61 |
|
public void configure() throws Exception |
62 |
|
{ |
63 |
1 |
solrDocument = new SolrDocument(); |
64 |
1 |
solrDocument.setField(FieldUtils.WIKI, "chess"); |
65 |
1 |
solrDocument.setField(FieldUtils.SPACES, Arrays.asList("Path", "To", "Success")); |
66 |
1 |
solrDocument.setField(FieldUtils.NAME, "WebHome"); |
67 |
1 |
solrDocument.setField(FieldUtils.DOCUMENT_LOCALE, "fr"); |
68 |
|
|
69 |
1 |
solrDocument.addField(FieldUtils.FILENAME, "image.png"); |
70 |
1 |
solrDocument.addField(FieldUtils.FILENAME, "presentation.odp"); |
71 |
|
|
72 |
1 |
solrDocument.addField(FieldUtils.CLASS, "App.Code.PlayerClass"); |
73 |
1 |
solrDocument.addField(FieldUtils.CLASS, "App.Code.TrainerClass"); |
74 |
1 |
solrDocument.setField(FieldUtils.NUMBER, 13); |
75 |
1 |
solrDocument.setField(FieldUtils.PROPERTY_NAME, "age"); |
76 |
|
|
77 |
1 |
EntityReferenceResolver<EntityReference> explicitReferenceEntityReferenceResolver = |
78 |
|
this.mocker.getInstance(EntityReferenceResolver.TYPE_REFERENCE, "explicit"); |
79 |
1 |
doAnswer(new Answer<EntityReference>() |
80 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
81 |
6 |
@Override... |
82 |
|
public EntityReference answer(InvocationOnMock invocation) throws Throwable |
83 |
|
{ |
84 |
6 |
EntityReference reference = invocation.getArgument(0); |
85 |
6 |
EntityType type = invocation.getArgument(1); |
86 |
6 |
return reference.extractReference(type); |
87 |
|
} |
88 |
|
}).when(explicitReferenceEntityReferenceResolver).resolve(any(EntityReference.class), any(EntityType.class)); |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
91 |
1 |
@Test... |
92 |
|
public void resolve() throws Exception |
93 |
|
{ |
94 |
1 |
WikiReference wikiReference = new WikiReference("chess"); |
95 |
1 |
assertReference(wikiReference); |
96 |
|
|
97 |
1 |
assertReference(new SpaceReference("Success", new SpaceReference("To", |
98 |
|
new SpaceReference("Path", wikiReference)))); |
99 |
|
|
100 |
1 |
DocumentReference documentReference = |
101 |
|
new DocumentReference("chess", Arrays.asList("Path", "To", "Success"), "WebHome", Locale.FRENCH); |
102 |
1 |
assertReference(documentReference); |
103 |
|
|
104 |
1 |
assertReference(new AttachmentReference("image.png", documentReference)); |
105 |
|
|
106 |
1 |
ObjectReference objectReference = new ObjectReference("App.Code.PlayerClass[13]", documentReference); |
107 |
1 |
assertReference(objectReference); |
108 |
|
|
109 |
1 |
assertReference(new ObjectPropertyReference("age", objectReference)); |
110 |
|
} |
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
112 |
6 |
private void assertReference(EntityReference reference) throws Exception... |
113 |
|
{ |
114 |
6 |
solrDocument.setField(FieldUtils.TYPE, reference.getType().name()); |
115 |
6 |
assertEquals(reference, this.mocker.getComponentUnderTest().resolve(solrDocument, reference.getType())); |
116 |
|
} |
117 |
|
} |