1 | /* |
---|
2 | * Copyright (C) 2014 CLARIN |
---|
3 | * |
---|
4 | * This program is free software: you can redistribute it and/or modify |
---|
5 | * it under the terms of the GNU General Public License as published by |
---|
6 | * the Free Software Foundation, either version 3 of the License, or |
---|
7 | * (at your option) any later version. |
---|
8 | * |
---|
9 | * This program is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | * GNU General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public License |
---|
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
16 | */ |
---|
17 | package eu.clarin.cmdi.vlo.service.impl; |
---|
18 | |
---|
19 | import java.io.File; |
---|
20 | import org.apache.solr.client.solrj.SolrQuery; |
---|
21 | import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; |
---|
22 | import org.apache.solr.client.solrj.response.QueryResponse; |
---|
23 | import org.apache.solr.common.SolrInputDocument; |
---|
24 | import org.apache.solr.common.params.SolrParams; |
---|
25 | import org.apache.solr.util.AbstractSolrTestCase; |
---|
26 | import org.junit.After; |
---|
27 | import org.junit.Before; |
---|
28 | import org.junit.Test; |
---|
29 | |
---|
30 | /** |
---|
31 | * Example taken from |
---|
32 | * {@link http://blog.synyx.de/2011/01/integration-tests-for-your-solr-config/} |
---|
33 | * |
---|
34 | * @author twagoo |
---|
35 | */ |
---|
36 | public class SearchResultsDaoImplTest extends AbstractSolrTestCase { |
---|
37 | |
---|
38 | private EmbeddedSolrServer server; |
---|
39 | |
---|
40 | @Before |
---|
41 | @Override |
---|
42 | public void setUp() throws Exception { |
---|
43 | super.setUp(); |
---|
44 | initCore(getResourcePath(getConfigString()), getResourcePath(getSchemaString())); |
---|
45 | server = new EmbeddedSolrServer(h.getCoreContainer(), h.getCore().getName()); |
---|
46 | } |
---|
47 | |
---|
48 | @After |
---|
49 | @Override |
---|
50 | public void tearDown() throws Exception { |
---|
51 | super.tearDown(); |
---|
52 | if (server != null) { |
---|
53 | server.shutdown(); |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | /** |
---|
58 | * Test of getFacets method, of class SearchResultsDaoImpl. |
---|
59 | */ |
---|
60 | @Test |
---|
61 | public void testGetFacets() throws Exception { |
---|
62 | SolrInputDocument document = new SolrInputDocument(); |
---|
63 | document.addField("id", "1"); |
---|
64 | document.addField("text", "test"); |
---|
65 | |
---|
66 | server.add(document); |
---|
67 | server.commit(); |
---|
68 | |
---|
69 | SolrParams params = new SolrQuery("text"); |
---|
70 | QueryResponse response = server.query(params); |
---|
71 | assertEquals(1L, response.getResults().getNumFound()); |
---|
72 | assertEquals("1", response.getResults().get(0).get("id")); |
---|
73 | } |
---|
74 | |
---|
75 | public static String getSchemaString() { |
---|
76 | return "/solr/collection1/conf/schema.xml"; |
---|
77 | } |
---|
78 | |
---|
79 | public static String getConfigString() { |
---|
80 | return "/solr/collection1/conf/solrconfig.xml"; |
---|
81 | } |
---|
82 | |
---|
83 | public static String getResourcePath(String resource) throws Exception { |
---|
84 | return new File(SearchResultsDaoImplTest.class.getResource(resource).toURI()).getAbsolutePath(); |
---|
85 | } |
---|
86 | } |
---|