| 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; |
| 21 |
|
|
| 22 |
|
import java.net.URL; |
| 23 |
|
|
| 24 |
|
import org.junit.Assert; |
| 25 |
|
import org.junit.Before; |
| 26 |
|
import org.junit.Rule; |
| 27 |
|
import org.junit.Test; |
| 28 |
|
import org.xwiki.component.manager.ComponentLookupException; |
| 29 |
|
import org.xwiki.component.phase.InitializationException; |
| 30 |
|
import org.xwiki.search.solr.internal.api.SolrConfiguration; |
| 31 |
|
import org.xwiki.search.solr.internal.api.SolrInstance; |
| 32 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
| 33 |
|
|
| 34 |
|
import static org.mockito.ArgumentMatchers.any; |
| 35 |
|
import static org.mockito.ArgumentMatchers.eq; |
| 36 |
|
import static org.mockito.Mockito.when; |
| 37 |
|
|
| 38 |
|
|
| 39 |
|
@link |
| 40 |
|
|
| 41 |
|
@version |
| 42 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 5 |
Complexity Density: 0.29 |
|
| 43 |
|
public class SolrInstanceProviderTest |
| 44 |
|
{ |
| 45 |
|
@Rule |
| 46 |
|
public final MockitoComponentMockingRule<SolrInstanceProvider> mocker = |
| 47 |
|
new MockitoComponentMockingRule<SolrInstanceProvider>(SolrInstanceProvider.class); |
| 48 |
|
|
| 49 |
|
private SolrInstance embedded; |
| 50 |
|
|
| 51 |
|
private SolrInstance remote; |
| 52 |
|
|
| 53 |
|
private SolrConfiguration mockConfig; |
| 54 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 55 |
3 |
@Before... |
| 56 |
|
public void setUp() throws Exception |
| 57 |
|
{ |
| 58 |
3 |
URL url = this.getClass().getClassLoader().getResource("solrhome"); |
| 59 |
|
|
| 60 |
3 |
this.mockConfig = this.mocker.getInstance(SolrConfiguration.class); |
| 61 |
3 |
when(this.mockConfig.getInstanceConfiguration(eq(EmbeddedSolrInstance.TYPE), eq("home"), any())) |
| 62 |
|
.thenReturn(url.getPath()); |
| 63 |
|
|
| 64 |
3 |
this.embedded = this.mocker.registerMockComponent(SolrInstance.class, "embedded"); |
| 65 |
3 |
this.remote = this.mocker.registerMockComponent(SolrInstance.class, "remote"); |
| 66 |
|
} |
| 67 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 68 |
1 |
@Test... |
| 69 |
|
public void testEmbeddedInstanceRetrieval() throws Exception |
| 70 |
|
{ |
| 71 |
1 |
when(this.mockConfig.getServerType()).thenReturn("embedded"); |
| 72 |
1 |
SolrInstance instance = this.mocker.getComponentUnderTest().get(); |
| 73 |
1 |
Assert.assertNotNull(instance); |
| 74 |
1 |
Assert.assertSame(this.embedded, instance); |
| 75 |
|
} |
| 76 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 77 |
1 |
@Test... |
| 78 |
|
public void testRemoteInstanceRetrieval() throws Exception |
| 79 |
|
{ |
| 80 |
1 |
when(this.mockConfig.getServerType()).thenReturn("remote"); |
| 81 |
1 |
SolrInstance instance = this.mocker.getComponentUnderTest().get(); |
| 82 |
1 |
Assert.assertNotNull(instance); |
| 83 |
1 |
Assert.assertSame(this.remote, instance); |
| 84 |
|
} |
| 85 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
1PASS
|
|
| 86 |
1 |
@Test(expected = InitializationException.class)... |
| 87 |
|
public void testInstanceRetrievalWithWrongConfiguration() throws Throwable |
| 88 |
|
{ |
| 89 |
1 |
when(this.mockConfig.getServerType()).thenReturn("none"); |
| 90 |
1 |
try { |
| 91 |
1 |
this.mocker.getComponentUnderTest(); |
| 92 |
|
} catch (ComponentLookupException ex) { |
| 93 |
1 |
throw ex.getCause(); |
| 94 |
|
} |
| 95 |
|
} |
| 96 |
|
} |