| 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 (47) |
Complexity: 12 |
Complexity Density: 0.34 |
|
| 44 |
|
public class DomainWikiReferenceExtractorTest |
| 45 |
|
{ |
| 46 |
|
@Rule |
| 47 |
|
public MockitoComponentMockingRule<DomainWikiReferenceExtractor> mocker = |
| 48 |
|
new MockitoComponentMockingRule<>(DomainWikiReferenceExtractor.class); |
| 49 |
|
|
| 50 |
|
private WikiDescriptorManager wikiDescriptorManager; |
| 51 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 52 |
9 |
@Before... |
| 53 |
|
public void setUp() throws Exception |
| 54 |
|
{ |
| 55 |
9 |
this.wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class); |
| 56 |
9 |
when(wikiDescriptorManager.getMainWikiId()).thenReturn("xwiki"); |
| 57 |
|
} |
| 58 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 59 |
1 |
@Test... |
| 60 |
|
public void extractWhenNoWikiDescriptorForFullDomain() throws Exception |
| 61 |
|
{ |
| 62 |
1 |
setUpConfiguration(WikiNotFoundBehavior.REDIRECT_TO_MAIN_WIKI); |
| 63 |
1 |
testAndAssert("http://wiki.server.com/xwiki/bin/view/Main/WebHome", "xwiki"); |
| 64 |
|
} |
| 65 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 66 |
1 |
@Test... |
| 67 |
|
public void extractWhenNoWikiDescriptorForFullDomainButDescriptorForSubdomain() throws Exception |
| 68 |
|
{ |
| 69 |
1 |
setUpConfiguration(WikiNotFoundBehavior.REDIRECT_TO_MAIN_WIKI); |
| 70 |
|
|
| 71 |
1 |
WikiDescriptorManager wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class); |
| 72 |
1 |
when(wikiDescriptorManager.getByAlias("wiki.server.com")).thenReturn(null); |
| 73 |
1 |
when(wikiDescriptorManager.getById("wiki")).thenReturn(new WikiDescriptor("dummy", "dummy")); |
| 74 |
|
|
| 75 |
1 |
testAndAssert("http://wiki.server.com/xwiki/bin/view/Main/WebHome", "wiki"); |
| 76 |
|
} |
| 77 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 78 |
1 |
@Test... |
| 79 |
|
public void extractWhenNoWikiDescriptorButStartsWithWWW() throws Exception |
| 80 |
|
{ |
| 81 |
1 |
setUpConfiguration(WikiNotFoundBehavior.REDIRECT_TO_MAIN_WIKI); |
| 82 |
1 |
testAndAssert("http://www.wiki.com/xwiki/bin/view/Main/WebHome", "xwiki"); |
| 83 |
|
} |
| 84 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 85 |
1 |
@Test... |
| 86 |
|
public void extractWhenNoWikiDescriptorButStartsWithLocalhost() throws Exception |
| 87 |
|
{ |
| 88 |
1 |
setUpConfiguration(WikiNotFoundBehavior.REDIRECT_TO_MAIN_WIKI); |
| 89 |
1 |
testAndAssert("http://localhost/xwiki/bin/view/Main/WebHome", "xwiki"); |
| 90 |
|
} |
| 91 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 92 |
1 |
@Test... |
| 93 |
|
public void extractWhenNoWikiDescriptorButStartsWithIP() throws Exception |
| 94 |
|
{ |
| 95 |
1 |
setUpConfiguration(WikiNotFoundBehavior.REDIRECT_TO_MAIN_WIKI); |
| 96 |
1 |
testAndAssert("http://192.168.0.10/xwiki/bin/view/Main/WebHome", "xwiki"); |
| 97 |
|
} |
| 98 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 99 |
1 |
@Test... |
| 100 |
|
public void extractWhenWikiDescriptor() throws Exception |
| 101 |
|
{ |
| 102 |
1 |
setUpConfiguration(WikiNotFoundBehavior.REDIRECT_TO_MAIN_WIKI); |
| 103 |
|
|
| 104 |
1 |
WikiDescriptorManager wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class); |
| 105 |
1 |
when(wikiDescriptorManager.getByAlias("wiki.server.com")).thenReturn(new WikiDescriptor("wikiid", "wiki")); |
| 106 |
|
|
| 107 |
1 |
testAndAssert("http://wiki.server.com/xwiki/bin/view/Main/WebHome", "wikiid"); |
| 108 |
|
} |
| 109 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 110 |
1 |
@Test... |
| 111 |
|
public void extractWhenNoWikiDescriptorAndDisplayErrorWhenWikiNotFound() throws Exception |
| 112 |
|
{ |
| 113 |
1 |
setUpConfiguration(WikiNotFoundBehavior.DISPLAY_ERROR); |
| 114 |
1 |
testAndAssert("http://wiki.server.com/xwiki/bin/view/Main/WebHome", "wiki"); |
| 115 |
|
} |
| 116 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 117 |
1 |
@Test... |
| 118 |
|
public void extractWhenNoAliasAndUnderscoreInDomainName() throws Exception |
| 119 |
|
{ |
| 120 |
|
|
| 121 |
1 |
Execution execution = mocker.getInstance(Execution.class); |
| 122 |
1 |
when(execution.getContext()).thenReturn(new ExecutionContext()); |
| 123 |
|
|
| 124 |
1 |
testAndAssert("http://some_domain.server.com/xwiki/bin/view/Main/WebHome", "some_domain"); |
| 125 |
|
} |
| 126 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 127 |
1 |
@Test... |
| 128 |
|
public void extractWhenNoExecutionContext() throws Exception |
| 129 |
|
{ |
| 130 |
1 |
testAndAssert("http://domain.server.com/xwiki/bin/view/Main/WebHome", "domain"); |
| 131 |
|
|
| 132 |
1 |
verify(this.wikiDescriptorManager, never()).getByAlias(any()); |
| 133 |
1 |
verify(this.wikiDescriptorManager, never()).getById(any()); |
| 134 |
|
} |
| 135 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 136 |
9 |
private void testAndAssert(String urlToTest, String expectedWikiId) throws Exception... |
| 137 |
|
{ |
| 138 |
9 |
ExtendedURL url = new ExtendedURL(new URL(urlToTest), "xwiki"); |
| 139 |
|
|
| 140 |
9 |
url.getSegments().remove(0); |
| 141 |
9 |
WikiReference wikiReference = this.mocker.getComponentUnderTest().extract(url); |
| 142 |
9 |
assertEquals(new WikiReference(expectedWikiId), wikiReference); |
| 143 |
|
} |
| 144 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 145 |
7 |
private void setUpConfiguration(WikiNotFoundBehavior wikiNotFoundBehavior) throws Exception... |
| 146 |
|
{ |
| 147 |
|
|
| 148 |
7 |
Execution execution = mocker.getInstance(Execution.class); |
| 149 |
7 |
when(execution.getContext()).thenReturn(new ExecutionContext()); |
| 150 |
|
|
| 151 |
7 |
StandardURLConfiguration urlConfiguration = mocker.getInstance(StandardURLConfiguration.class); |
| 152 |
7 |
when(urlConfiguration.getWikiNotFoundBehavior()).thenReturn(wikiNotFoundBehavior); |
| 153 |
|
} |
| 154 |
|
} |