1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.internal.model.reference; |
21 |
|
|
22 |
|
import org.junit.Assert; |
23 |
|
import org.junit.Before; |
24 |
|
import org.junit.Rule; |
25 |
|
import org.junit.Test; |
26 |
|
import org.xwiki.model.EntityType; |
27 |
|
import org.xwiki.model.internal.DefaultModelConfiguration; |
28 |
|
import org.xwiki.model.internal.reference.DefaultSymbolScheme; |
29 |
|
import org.xwiki.model.reference.DocumentReference; |
30 |
|
import org.xwiki.model.reference.EntityReference; |
31 |
|
import org.xwiki.model.reference.EntityReferenceResolver; |
32 |
|
import org.xwiki.test.annotation.ComponentList; |
33 |
|
|
34 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
35 |
|
import com.xpn.xwiki.test.MockitoOldcoreRule; |
36 |
|
|
37 |
|
|
38 |
|
@link |
39 |
|
|
40 |
|
@version |
41 |
|
|
42 |
|
@ComponentList(value = { |
43 |
|
CurrentEntityReferenceProvider.class, |
44 |
|
CurrentStringEntityReferenceResolver.class, |
45 |
|
DefaultModelConfiguration.class, |
46 |
|
DefaultSymbolScheme.class |
47 |
|
}) |
|
|
| 100% |
Uncovered Elements: 0 (47) |
Complexity: 7 |
Complexity Density: 0.17 |
|
48 |
|
public class CurrentStringEntityReferenceResolverTest |
49 |
|
{ |
50 |
|
@Rule |
51 |
|
public MockitoOldcoreRule oldcore = new MockitoOldcoreRule(); |
52 |
|
|
53 |
|
private static final String CURRENT_WIKI = "currentwiki"; |
54 |
|
|
55 |
|
private static final String CURRENT_SPACE = "currentspace"; |
56 |
|
|
57 |
|
private static final String CURRENT_PAGE = "currentpage"; |
58 |
|
|
59 |
|
private static final String CURRENTDOC_SPACE = "currentdocspace"; |
60 |
|
|
61 |
|
private static final String CURRENTDOC_PAGE = "currentdocpage"; |
62 |
|
|
63 |
|
private EntityReferenceResolver<String> resolver; |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
65 |
6 |
@Before... |
66 |
|
public void before() throws Exception |
67 |
|
{ |
68 |
6 |
this.oldcore.getXWikiContext().setWikiId(CURRENT_WIKI); |
69 |
|
|
70 |
6 |
this.resolver = this.oldcore.getMocker().getInstance(EntityReferenceResolver.TYPE_STRING, "current"); |
71 |
|
} |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
73 |
1 |
@Test... |
74 |
|
public void testResolveDocumentReferenceWhenNoContextWiki() throws Exception |
75 |
|
{ |
76 |
1 |
this.oldcore.getXWikiContext().setWikiId(null); |
77 |
|
|
78 |
1 |
EntityReference reference = resolver.resolve("", EntityType.DOCUMENT); |
79 |
|
|
80 |
1 |
Assert.assertEquals("xwiki", reference.extractReference(EntityType.WIKI).getName()); |
81 |
1 |
Assert.assertEquals("Main", reference.extractReference(EntityType.SPACE).getName()); |
82 |
1 |
Assert.assertEquals("WebHome", reference.getName()); |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
85 |
1 |
@Test... |
86 |
|
public void testResolveDocumentReferenceWhenNoContextDocument() throws Exception |
87 |
|
{ |
88 |
1 |
this.oldcore.getXWikiContext().setWikiId(null); |
89 |
1 |
this.oldcore.getXWikiContext().setDoc(null); |
90 |
|
|
91 |
1 |
EntityReference reference = resolver.resolve("", EntityType.DOCUMENT); |
92 |
|
|
93 |
1 |
Assert.assertEquals("xwiki", reference.extractReference(EntityType.WIKI).getName()); |
94 |
1 |
Assert.assertEquals("Main", reference.extractReference(EntityType.SPACE).getName()); |
95 |
1 |
Assert.assertEquals("WebHome", reference.getName()); |
96 |
|
} |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
98 |
1 |
@Test... |
99 |
|
public void testResolveDocumentReferenceWhenContextDocument() throws Exception |
100 |
|
{ |
101 |
1 |
this.oldcore.getXWikiContext().setDoc( |
102 |
|
new XWikiDocument(new DocumentReference(CURRENT_WIKI, CURRENTDOC_SPACE, CURRENTDOC_PAGE))); |
103 |
|
|
104 |
1 |
EntityReference reference = resolver.resolve("", EntityType.DOCUMENT); |
105 |
|
|
106 |
1 |
Assert.assertEquals(CURRENT_WIKI, reference.extractReference(EntityType.WIKI).getName()); |
107 |
1 |
Assert.assertEquals(CURRENTDOC_SPACE, reference.extractReference(EntityType.SPACE).getName()); |
108 |
1 |
Assert.assertEquals(CURRENTDOC_PAGE, reference.getName()); |
109 |
|
} |
110 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
111 |
1 |
@Test... |
112 |
|
public void testResolveAttachmentReference() throws Exception |
113 |
|
{ |
114 |
1 |
this.oldcore.getXWikiContext().setDoc( |
115 |
|
new XWikiDocument(new DocumentReference(CURRENT_WIKI, CURRENTDOC_SPACE, CURRENTDOC_PAGE))); |
116 |
|
|
117 |
1 |
EntityReference reference = resolver.resolve("", EntityType.ATTACHMENT); |
118 |
|
|
119 |
1 |
Assert.assertEquals(CURRENT_WIKI, reference.extractReference(EntityType.WIKI).getName()); |
120 |
1 |
Assert.assertEquals(CURRENTDOC_SPACE, reference.extractReference(EntityType.SPACE).getName()); |
121 |
1 |
Assert.assertEquals(CURRENTDOC_PAGE, reference.extractReference(EntityType.DOCUMENT).getName()); |
122 |
1 |
Assert.assertEquals("filename", reference.getName()); |
123 |
|
} |
124 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
125 |
1 |
@Test... |
126 |
|
public void testResolveAttachmentReferenceWhenMissingParentsAndNoContextDocument() |
127 |
|
{ |
128 |
1 |
EntityReference reference = resolver.resolve("filename", EntityType.ATTACHMENT); |
129 |
|
|
130 |
1 |
Assert.assertEquals("WebHome", reference.getParent().getName()); |
131 |
1 |
Assert.assertEquals(EntityType.DOCUMENT, reference.getParent().getType()); |
132 |
1 |
Assert.assertEquals("Main", reference.getParent().getParent().getName()); |
133 |
1 |
Assert.assertEquals(EntityType.SPACE, reference.getParent().getParent().getType()); |
134 |
1 |
Assert.assertEquals(CURRENT_WIKI, reference.getParent().getParent().getParent().getName()); |
135 |
1 |
Assert.assertEquals(EntityType.WIKI, reference.getParent().getParent().getParent().getType()); |
136 |
|
} |
137 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
138 |
1 |
@Test... |
139 |
|
public void testResolveAttachmentReferenceWhenMissingParentsAndContextDocument() |
140 |
|
{ |
141 |
1 |
this.oldcore.getXWikiContext().setWikiId(CURRENT_WIKI); |
142 |
1 |
this.oldcore.getXWikiContext().setDoc( |
143 |
|
new XWikiDocument(new DocumentReference("docwiki", CURRENT_SPACE, CURRENT_PAGE))); |
144 |
|
|
145 |
1 |
EntityReference reference = resolver.resolve("filename", EntityType.ATTACHMENT); |
146 |
|
|
147 |
1 |
Assert.assertEquals(CURRENT_PAGE, reference.getParent().getName()); |
148 |
1 |
Assert.assertEquals(EntityType.DOCUMENT, reference.getParent().getType()); |
149 |
1 |
Assert.assertEquals(CURRENT_SPACE, reference.getParent().getParent().getName()); |
150 |
1 |
Assert.assertEquals(EntityType.SPACE, reference.getParent().getParent().getType()); |
151 |
1 |
Assert.assertEquals(CURRENT_WIKI, reference.getParent().getParent().getParent().getName()); |
152 |
1 |
Assert.assertEquals(EntityType.WIKI, reference.getParent().getParent().getParent().getType()); |
153 |
|
} |
154 |
|
} |