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