source: vlo/trunk/vlo_importer/src/test/java/eu/clarin/cmdi/vlo/importer/CMDIParserVTDXMLTest.java @ 2768

Last change on this file since 2768 was 2768, checked in by keeloo, 11 years ago

Integrated parameter branche into trunk again

File size: 3.1 KB
Line 
1package eu.clarin.cmdi.vlo.importer;
2
3import com.ximpleware.VTDGen;
4import com.ximpleware.VTDNav;
5import eu.clarin.cmdi.vlo.config.VloConfig;
6import static org.junit.Assert.assertEquals;
7import static org.junit.Assert.assertNull;
8import org.junit.Before;
9import org.junit.Test;
10
11public class CMDIParserVTDXMLTest {
12   
13    @Before
14    public void setUp() {
15
16        // read the configuration from the packaged configuration file
17        VloConfig.readPackagedConfig();
18
19        // optionally, modify the configuration here
20
21        // apparantly, this does not make the configuration available
22    }
23
24    @Test
25    public void testExtractXsdFromHeader() throws Exception {
26        String content = "";
27        content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
28        content += "<CMD xmlns=\"http://www.clarin.eu/cmd/\">\n";
29        content += "   <Header>\n";
30        content += "      <MdProfile>clarin.eu:cr1:p_1288172614026</MdProfile>\n";
31        content += "   </Header>\n";
32        content += "</CMD>\n";
33        String xsd = getXsd(content);
34        assertEquals("http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/clarin.eu:cr1:p_1288172614026/xsd", xsd);
35    }
36
37    @Test
38    public void testExtractXsdFromSchemaLocation() throws Exception {
39        String content = "";
40        content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
41        content += "<CMD xmlns=\"http://www.clarin.eu/cmd/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n";
42        content += "     xsi:schemaLocation=\"http://www.clarin.eu/cmd http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/clarin.eu:cr1:p_1288172614026/xsd\">\n";
43        content += "</CMD>\n";
44        String xsd = getXsd(content);
45        assertEquals("http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/clarin.eu:cr1:p_1288172614026/xsd", xsd);
46    }
47
48    @Test
49    public void testExtractXsdFromNoSchemaLocation() throws Exception {
50        String content = "";
51        content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
52        content += "<CMD xmlns=\"http://www.clarin.eu/cmd/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n";
53        content += "     xsi:noNamespaceSchemaLocation=\"http://www.meertens.knaw.nl/oai/cmdi/diddd_sub_location_profile.xsd\">\n";
54        content += "</CMD>\n";
55        String xsd = getXsd(content);
56        assertEquals("http://www.meertens.knaw.nl/oai/cmdi/diddd_sub_location_profile.xsd", xsd);
57    }
58
59    @Test
60    public void testNoXsd() throws Exception {
61        String content = "";
62        content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
63        content += "<CMD xmlns=\"http://www.clarin.eu/cmd/\">\n";
64        content += "</CMD>\n";
65        String xsd = getXsd(content);
66        assertNull(xsd);
67    }
68
69    private String getXsd(String content) throws Exception {
70        VTDGen vg = new VTDGen();
71        vg.setDoc(content.getBytes());
72        vg.parse(true);
73        VTDNav nav = vg.getNav();
74        CMDIParserVTDXML.setNameSpace(nav);
75        CMDIParserVTDXML parser = new CMDIParserVTDXML(null);
76        String xsd = parser.extractXsd(nav);
77        return xsd;
78    }
79}
Note: See TracBrowser for help on using the repository browser.