source: vlo/branches/vlo-3.1/vlo-commons/src/test/java/eu/clarin/cmdi/vlo/config/VloConfigMarshallerTest.java @ 6088

Last change on this file since 6088 was 6088, checked in by Twan Goosen, 9 years ago

Merged fix of #739 and #740 from trunk to 3.1 branch

File size: 2.6 KB
Line 
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 */
17package eu.clarin.cmdi.vlo.config;
18
19import java.io.File;
20import java.io.InputStream;
21import java.io.StringWriter;
22import java.util.Arrays;
23import javax.xml.transform.stream.StreamResult;
24import javax.xml.transform.stream.StreamSource;
25import static org.junit.Assert.assertEquals;
26import static org.junit.Assert.assertNotNull;
27import org.junit.Before;
28import org.junit.Test;
29import org.slf4j.Logger;
30import org.slf4j.LoggerFactory;
31
32/**
33 *
34 * @author twagoo
35 */
36public 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}
Note: See TracBrowser for help on using the repository browser.