1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.search.solr.internal

File SolrInstanceProviderTest.java

 

Code metrics

0
17
4
1
96
59
5
0.29
4.25
4
1.25

Classes

Class Line # Actions
SolrInstanceProviderTest 43 17 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * Tests for {@link SolrInstanceProvider}.
40    *
41    * @version $Id: 7c505f95f68af2f0ef7d36b73d7bc59ceac27d92 $
42    */
 
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   
 
55  3 toggle @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   
 
68  1 toggle @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   
 
77  1 toggle @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   
 
86  1 toggle @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    }