1 | package eu.clarin.cmdi.vlo.importer; |
---|
2 | |
---|
3 | import java.io.File; |
---|
4 | import java.io.IOException; |
---|
5 | import java.net.URISyntaxException; |
---|
6 | import java.net.URL; |
---|
7 | import java.util.ArrayList; |
---|
8 | import java.util.Collection; |
---|
9 | import java.util.Enumeration; |
---|
10 | import java.util.regex.Pattern; |
---|
11 | import java.util.zip.ZipEntry; |
---|
12 | import java.util.zip.ZipException; |
---|
13 | import java.util.zip.ZipFile; |
---|
14 | |
---|
15 | import org.apache.commons.io.FileUtils; |
---|
16 | import org.junit.After; |
---|
17 | import org.junit.Before; |
---|
18 | import org.junit.Rule; |
---|
19 | import org.junit.rules.TemporaryFolder; |
---|
20 | |
---|
21 | import eu.clarin.cmdi.vlo.LanguageCodeUtils; |
---|
22 | import eu.clarin.cmdi.vlo.config.DefaultVloConfigFactory; |
---|
23 | import eu.clarin.cmdi.vlo.config.VloConfig; |
---|
24 | import eu.clarin.cmdi.vlo.config.VloConfigFactory; |
---|
25 | |
---|
26 | public abstract class ImporterTestcase { |
---|
27 | |
---|
28 | private final String VOC_MAPS_PATH = "/maps/uniform_maps"; |
---|
29 | private final VloConfigFactory configFactory = new DefaultVloConfigFactory(); |
---|
30 | protected VloConfig config; |
---|
31 | |
---|
32 | private static int cnt = 0; |
---|
33 | |
---|
34 | @Rule |
---|
35 | public TemporaryFolder tempFolder = new TemporaryFolder(); |
---|
36 | |
---|
37 | protected File createCmdiFile(String name, String content) throws IOException { |
---|
38 | File file = tempFolder.newFile(name + cnt++ + ".cmdi"); |
---|
39 | FileUtils.writeStringToFile(file, content, "UTF-8"); |
---|
40 | return file; |
---|
41 | } |
---|
42 | |
---|
43 | @After |
---|
44 | public void cleanup() { |
---|
45 | MetadataImporter.config = null; |
---|
46 | } |
---|
47 | |
---|
48 | @Before |
---|
49 | public void setup() throws Exception { |
---|
50 | // read the configuration defined in the packaged configuration file |
---|
51 | MetadataImporter.config = configFactory.newConfig(); |
---|
52 | |
---|
53 | // optionally, modify the configuration here |
---|
54 | |
---|
55 | MetadataImporter.config.setComponentRegistryRESTURL("http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/"); |
---|
56 | //point to transformed maps |
---|
57 | MetadataImporter.config.setLicenseAvailabilityMapUrl(VOC_MAPS_PATH + MetadataImporter.config.getLicenseAvailabilityMapUrl()); |
---|
58 | MetadataImporter.config.setLanguageNameVariantsUrl(VOC_MAPS_PATH + MetadataImporter.config.getLanguageNameVariantsUrl()); |
---|
59 | MetadataImporter. config.setNationalProjectMapping(VOC_MAPS_PATH + MetadataImporter.config.getNationalProjectMapping()); |
---|
60 | MetadataImporter.config.setOrganisationNamesUrl(VOC_MAPS_PATH + MetadataImporter.config.getOrganisationNamesUrl()); |
---|
61 | MetadataImporter.config.setResourceClassMapUrl(VOC_MAPS_PATH + MetadataImporter.config.getResourceClassMapUrl()); |
---|
62 | |
---|
63 | config = MetadataImporter.config; |
---|
64 | |
---|
65 | MetadataImporter.languageCodeUtils = new LanguageCodeUtils(config); |
---|
66 | |
---|
67 | |
---|
68 | |
---|
69 | } |
---|
70 | |
---|
71 | public static String getTestFacetConceptFilePath() { |
---|
72 | try { |
---|
73 | return new File(ImporterTestcase.class.getResource("/facetConceptsTest.xml").toURI()).getAbsolutePath(); |
---|
74 | } catch (URISyntaxException ex) { |
---|
75 | throw new RuntimeException(ex); |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | |
---|
81 | } |
---|