1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.lesscss.internal.skin; |
21 |
|
|
22 |
|
import javax.inject.Provider; |
23 |
|
|
24 |
|
import org.junit.Before; |
25 |
|
import org.junit.Rule; |
26 |
|
import org.junit.Test; |
27 |
|
import org.xwiki.component.util.DefaultParameterizedType; |
28 |
|
import org.xwiki.lesscss.compiler.LESSCompilerException; |
29 |
|
import org.xwiki.model.reference.DocumentReference; |
30 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
31 |
|
import org.xwiki.model.reference.WikiReference; |
32 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
33 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
34 |
|
|
35 |
|
import com.xpn.xwiki.XWiki; |
36 |
|
import com.xpn.xwiki.XWikiContext; |
37 |
|
import com.xpn.xwiki.XWikiException; |
38 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
39 |
|
|
40 |
|
import static org.junit.Assert.assertEquals; |
41 |
|
import static org.junit.Assert.assertNotNull; |
42 |
|
import static org.junit.Assert.assertTrue; |
43 |
|
import static org.mockito.ArgumentMatchers.eq; |
44 |
|
import static org.mockito.Mockito.mock; |
45 |
|
import static org.mockito.Mockito.when; |
46 |
|
|
47 |
|
|
48 |
|
@since |
49 |
|
@version |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (47) |
Complexity: 5 |
Complexity Density: 0.12 |
|
51 |
|
public class DefaultSkinReferenceFactoryTest |
52 |
|
{ |
53 |
|
@Rule |
54 |
|
public MockitoComponentMockingRule<DefaultSkinReferenceFactory> mocker = |
55 |
|
new MockitoComponentMockingRule<>(DefaultSkinReferenceFactory.class); |
56 |
|
|
57 |
|
private Provider<XWikiContext> xcontextProvider; |
58 |
|
|
59 |
|
private DocumentReferenceResolver<String> documentReferenceResolver; |
60 |
|
|
61 |
|
private WikiDescriptorManager wikiDescriptorManager; |
62 |
|
|
63 |
|
private XWikiContext xcontext; |
64 |
|
|
65 |
|
private XWiki xwiki; |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
67 |
3 |
@Before... |
68 |
|
public void setUp() throws Exception |
69 |
|
{ |
70 |
3 |
documentReferenceResolver = mocker.getInstance(new DefaultParameterizedType(null, |
71 |
|
DocumentReferenceResolver.class, String.class)); |
72 |
3 |
wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class); |
73 |
3 |
xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER); |
74 |
3 |
xcontext = mock(XWikiContext.class); |
75 |
3 |
when(xcontextProvider.get()).thenReturn(xcontext); |
76 |
3 |
xwiki = mock(XWiki.class); |
77 |
3 |
when(xcontext.getWiki()).thenReturn(xwiki); |
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
80 |
1 |
@Test... |
81 |
|
public void createReferenceWhenSkinOnDB() throws Exception |
82 |
|
{ |
83 |
|
|
84 |
1 |
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wikiId"); |
85 |
1 |
DocumentReference skinDocRef = new DocumentReference("wikiId", "XWiki", "MySkin"); |
86 |
1 |
when(documentReferenceResolver.resolve(eq("XWiki.MySkin"), eq(new WikiReference("wikiId")))) |
87 |
|
.thenReturn(skinDocRef); |
88 |
1 |
when(xwiki.exists(skinDocRef, xcontext)).thenReturn(true); |
89 |
1 |
XWikiDocument skinDoc = mock(XWikiDocument.class); |
90 |
1 |
when(xwiki.getDocument(skinDocRef, xcontext)).thenReturn(skinDoc); |
91 |
1 |
when(skinDoc.getXObjectSize(eq(new DocumentReference("wikiId", "XWiki", "XWikiSkins")))).thenReturn(1); |
92 |
|
|
93 |
|
|
94 |
1 |
SkinReference skinReference = mocker.getComponentUnderTest().createReference("XWiki.MySkin"); |
95 |
|
|
96 |
|
|
97 |
1 |
assertTrue(skinReference instanceof DocumentSkinReference); |
98 |
1 |
DocumentSkinReference docSkinRef = (DocumentSkinReference) skinReference; |
99 |
1 |
assertEquals(skinDocRef, docSkinRef.getSkinDocument()); |
100 |
|
} |
101 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 2 |
Complexity Density: 0.15 |
1PASS
|
|
102 |
1 |
@Test... |
103 |
|
public void createReferenceWhenSkinOnDBWithException() throws Exception |
104 |
|
{ |
105 |
|
|
106 |
1 |
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wikiId"); |
107 |
1 |
DocumentReference skinDocRef = new DocumentReference("wikiId", "XWiki", "MySkin"); |
108 |
1 |
when(documentReferenceResolver.resolve(eq("XWiki.MySkin"), eq(new WikiReference("wikiId")))) |
109 |
|
.thenReturn(skinDocRef); |
110 |
1 |
when(xwiki.exists(skinDocRef, xcontext)).thenReturn(true); |
111 |
1 |
Exception exception = new XWikiException(); |
112 |
1 |
when(xwiki.getDocument(skinDocRef, xcontext)).thenThrow(exception); |
113 |
|
|
114 |
|
|
115 |
1 |
LESSCompilerException caughtException = null; |
116 |
1 |
try { |
117 |
1 |
mocker.getComponentUnderTest().createReference("XWiki.MySkin"); |
118 |
|
} catch(LESSCompilerException e) { |
119 |
1 |
caughtException = e; |
120 |
|
} |
121 |
|
|
122 |
|
|
123 |
1 |
assertNotNull(caughtException); |
124 |
1 |
assertEquals(exception, caughtException.getCause()); |
125 |
1 |
assertEquals("Unable to read document [wikiId:XWiki.MySkin]", caughtException.getMessage()); |
126 |
|
} |
127 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
128 |
1 |
@Test... |
129 |
|
public void createReferenceWhenSkinOnFS() throws Exception |
130 |
|
{ |
131 |
|
|
132 |
1 |
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wikiId"); |
133 |
1 |
DocumentReference skinDocRef = new DocumentReference("wikiId", "Main", "Flamingo"); |
134 |
1 |
when(documentReferenceResolver.resolve(eq("flamingo"), eq(new WikiReference("wikiId")))) |
135 |
|
.thenReturn(skinDocRef); |
136 |
1 |
when(xwiki.exists(skinDocRef, xcontext)).thenReturn(true); |
137 |
1 |
XWikiDocument skinDoc = mock(XWikiDocument.class); |
138 |
1 |
when(xwiki.getDocument(skinDocRef, xcontext)).thenReturn(skinDoc); |
139 |
1 |
when(skinDoc.getXObjectSize(eq(new DocumentReference("wikiId", "XWiki", "XWikiSkins")))).thenReturn(0); |
140 |
|
|
141 |
|
|
142 |
1 |
SkinReference skinReference = mocker.getComponentUnderTest().createReference("flamingo"); |
143 |
|
|
144 |
|
|
145 |
1 |
assertTrue(skinReference instanceof FSSkinReference); |
146 |
1 |
FSSkinReference fsSkinRef = (FSSkinReference) skinReference; |
147 |
1 |
assertEquals("flamingo", fsSkinRef.getSkinName()); |
148 |
1 |
assertEquals("SkinFS[flamingo]", fsSkinRef.toString()); |
149 |
|
} |
150 |
|
} |