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.config; |
---|
18 | |
---|
19 | import java.io.File; |
---|
20 | import java.io.InputStream; |
---|
21 | import java.io.StringWriter; |
---|
22 | import java.util.Arrays; |
---|
23 | import javax.xml.transform.stream.StreamResult; |
---|
24 | import javax.xml.transform.stream.StreamSource; |
---|
25 | import static org.junit.Assert.assertEquals; |
---|
26 | import static org.junit.Assert.assertNotNull; |
---|
27 | import org.junit.Before; |
---|
28 | import org.junit.Test; |
---|
29 | import org.slf4j.Logger; |
---|
30 | import org.slf4j.LoggerFactory; |
---|
31 | |
---|
32 | /** |
---|
33 | * |
---|
34 | * @author twagoo |
---|
35 | */ |
---|
36 | public class VloConfigMarshallerTest { |
---|
37 | |
---|
38 | private final static Logger logger = LoggerFactory.getLogger(VloConfigMarshallerTest.class); |
---|
39 | private VloConfigMarshaller instance; |
---|
40 | |
---|
41 | @Before |
---|
42 | public void setUp() throws Exception { |
---|
43 | instance = new VloConfigMarshaller(); |
---|
44 | } |
---|
45 | |
---|
46 | /** |
---|
47 | * Test of marshal method, of class VloConfigMarshaller. |
---|
48 | */ |
---|
49 | @Test |
---|
50 | public void testUnmarshal() throws Exception { |
---|
51 | InputStream configFile = getClass().getResourceAsStream("/VloConfig.xml"); |
---|
52 | VloConfig config = instance.unmarshal(new StreamSource(configFile)); |
---|
53 | configFile.close(); |
---|
54 | |
---|
55 | assertNotNull(config); |
---|
56 | assertEquals("http://localhost:8080/vlo-solr/core0/", config.getSolrUrl()); |
---|
57 | assertEquals(2, config.getDataRoots().size()); |
---|
58 | assertEquals(14, config.getFacetFields().size()); |
---|
59 | } |
---|
60 | |
---|
61 | /** |
---|
62 | * Test of marshal method, of class VloConfigMarshaller. |
---|
63 | */ |
---|
64 | @Test |
---|
65 | public void testMarshal() throws Exception { |
---|
66 | final VloConfig config = new VloConfig(); |
---|
67 | config.setSolrUrl("http://server/solr"); |
---|
68 | config.setDataRoots(Arrays.asList(new DataRoot("originName", new File("rootFile"), "prefix", "toStrip", Boolean.FALSE))); |
---|
69 | config.setFacetFields(Arrays.asList("collection", "country", "continent")); |
---|
70 | final StringWriter sw = new StringWriter(); |
---|
71 | instance.marshal(config, new StreamResult(sw)); |
---|
72 | logger.debug(sw.toString()); |
---|
73 | } |
---|
74 | |
---|
75 | } |
---|