1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.url.internal.standard; |
21 |
|
|
22 |
|
import java.net.URL; |
23 |
|
|
24 |
|
import org.junit.Before; |
25 |
|
import org.junit.Rule; |
26 |
|
import org.junit.Test; |
27 |
|
import org.xwiki.context.Execution; |
28 |
|
import org.xwiki.context.ExecutionContext; |
29 |
|
import org.xwiki.model.reference.WikiReference; |
30 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
31 |
|
import org.xwiki.url.ExtendedURL; |
32 |
|
import org.xwiki.wiki.descriptor.WikiDescriptor; |
33 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
34 |
|
|
35 |
|
import static org.junit.Assert.assertEquals; |
36 |
|
import static org.mockito.Mockito.*; |
37 |
|
|
38 |
|
|
39 |
|
@link |
40 |
|
|
41 |
|
@version |
42 |
|
@since |
43 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (42) |
Complexity: 10 |
Complexity Density: 0.31 |
|
44 |
|
public class PathWikiReferenceExtractorTest |
45 |
|
{ |
46 |
|
@Rule |
47 |
|
public MockitoComponentMockingRule<PathWikiReferenceExtractor> mocker = |
48 |
|
new MockitoComponentMockingRule<>(PathWikiReferenceExtractor.class); |
49 |
|
|
50 |
|
private WikiDescriptorManager wikiDescriptorManager; |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
52 |
7 |
@Before... |
53 |
|
public void setUp() throws Exception |
54 |
|
{ |
55 |
7 |
this.wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class); |
56 |
7 |
when(wikiDescriptorManager.getMainWikiId()).thenReturn("xwiki"); |
57 |
|
} |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
59 |
1 |
@Test... |
60 |
|
public void extractWhenWikiDescriptor() throws Exception |
61 |
|
{ |
62 |
1 |
setUpConfiguration(WikiNotFoundBehavior.REDIRECT_TO_MAIN_WIKI); |
63 |
|
|
64 |
1 |
WikiDescriptorManager wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class); |
65 |
1 |
when(wikiDescriptorManager.getByAlias("someWiki")).thenReturn(new WikiDescriptor("wikiid", "someWiki")); |
66 |
|
|
67 |
1 |
testAndAssert("http://localhost/xwiki/wiki/someWiki/view/Main/WebHome", "wikiid"); |
68 |
|
} |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
70 |
1 |
@Test... |
71 |
|
public void extractWhenNoWikiDescriptor() throws Exception |
72 |
|
{ |
73 |
1 |
setUpConfiguration(WikiNotFoundBehavior.REDIRECT_TO_MAIN_WIKI); |
74 |
1 |
testAndAssert("http://localhost/xwiki/wiki/someWiki/view/Main/WebHome", "xwiki"); |
75 |
|
} |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
77 |
1 |
@Test... |
78 |
|
public void extractWhenWikiDescriptorButEmptyServerName() throws Exception |
79 |
|
{ |
80 |
1 |
setUpConfiguration(WikiNotFoundBehavior.REDIRECT_TO_MAIN_WIKI); |
81 |
|
|
82 |
1 |
WikiDescriptorManager wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class); |
83 |
1 |
when(wikiDescriptorManager.getByAlias("someWiki")).thenReturn(new WikiDescriptor("", "someWiki")); |
84 |
|
|
85 |
1 |
testAndAssert("http://localhost/xwiki/wiki/someWiki/view/Main/WebHome", "xwiki"); |
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
88 |
1 |
@Test... |
89 |
|
public void extractWhenNoDescriptorMatchingAliasButDescriptorMatchingId() throws Exception |
90 |
|
{ |
91 |
1 |
setUpConfiguration(WikiNotFoundBehavior.REDIRECT_TO_MAIN_WIKI); |
92 |
|
|
93 |
1 |
WikiDescriptorManager wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class); |
94 |
1 |
when(wikiDescriptorManager.getByAlias("someWiki")).thenReturn(null); |
95 |
1 |
when(wikiDescriptorManager.getById("someWiki")).thenReturn(new WikiDescriptor("dummy", "dummy")); |
96 |
|
|
97 |
1 |
testAndAssert("http://localhost/xwiki/wiki/someWiki/view/Main/WebHome", "somewiki"); |
98 |
|
} |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
100 |
1 |
@Test... |
101 |
|
public void extractWhenNoWikiDescriptorButWithDomainBasedURL() throws Exception |
102 |
|
{ |
103 |
1 |
setUpConfiguration(WikiNotFoundBehavior.REDIRECT_TO_MAIN_WIKI); |
104 |
1 |
testAndAssert("http://wiki.server.com/xwiki/bin/view/Main/WebHome", "xwiki"); |
105 |
|
} |
106 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
107 |
1 |
@Test... |
108 |
|
public void extractWhenNoWikiDescriptorAndDisplayErrorWhenWikiNotFound() throws Exception |
109 |
|
{ |
110 |
1 |
setUpConfiguration(WikiNotFoundBehavior.DISPLAY_ERROR); |
111 |
1 |
testAndAssert("http://localhost/xwiki/wiki/someWiki/view/Main/WebHome", "somewiki"); |
112 |
|
} |
113 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
114 |
1 |
@Test... |
115 |
|
public void extractWhenNoExecutionContext() throws Exception |
116 |
|
{ |
117 |
1 |
testAndAssert("http://localhost/xwiki/wiki/someWiki/view/Main/WebHome", "somewiki"); |
118 |
|
|
119 |
1 |
verify(this.wikiDescriptorManager, never()).getByAlias(any()); |
120 |
1 |
verify(this.wikiDescriptorManager, never()).getById(any()); |
121 |
|
} |
122 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
123 |
7 |
private void testAndAssert(String urlToTest, String expectedWikiId) throws Exception... |
124 |
|
{ |
125 |
7 |
ExtendedURL url = new ExtendedURL(new URL(urlToTest), "xwiki"); |
126 |
|
|
127 |
7 |
url.getSegments().remove(0); |
128 |
7 |
WikiReference wikiReference = this.mocker.getComponentUnderTest().extract(url); |
129 |
7 |
assertEquals(new WikiReference(expectedWikiId), wikiReference); |
130 |
|
} |
131 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
132 |
6 |
private void setUpConfiguration(WikiNotFoundBehavior wikiNotFoundBehavior) throws Exception... |
133 |
|
{ |
134 |
|
|
135 |
6 |
Execution execution = mocker.getInstance(Execution.class); |
136 |
6 |
when(execution.getContext()).thenReturn(new ExecutionContext()); |
137 |
|
|
138 |
6 |
StandardURLConfiguration urlConfiguration = mocker.getInstance(StandardURLConfiguration.class); |
139 |
6 |
when(urlConfiguration.getWikiNotFoundBehavior()).thenReturn(wikiNotFoundBehavior); |
140 |
|
} |
141 |
|
} |