|
1 |
| -/** |
2 |
| - * |
3 |
| - */ |
| 1 | +/** |
| 2 | + * |
| 3 | + */ |
4 | 4 | /*
|
5 | 5 | * Copyright 2013 Deutsche Nationalbibliothek
|
6 | 6 | *
|
|
16 | 16 | * See the License for the specific language governing permissions and
|
17 | 17 | * limitations under the License.
|
18 | 18 | */
|
19 |
| -package org.culturegraph.mf.test; |
20 |
| - |
21 |
| -import java.io.File; |
22 |
| -import java.io.FileNotFoundException; |
23 |
| -import java.io.IOException; |
24 |
| -import java.io.InputStream; |
25 |
| -import java.net.URL; |
26 |
| -import java.util.ArrayList; |
27 |
| -import java.util.List; |
28 |
| - |
29 |
| -import javax.xml.XMLConstants; |
30 |
| -import javax.xml.parsers.DocumentBuilder; |
31 |
| -import javax.xml.parsers.DocumentBuilderFactory; |
32 |
| -import javax.xml.parsers.ParserConfigurationException; |
33 |
| -import javax.xml.validation.Schema; |
34 |
| -import javax.xml.validation.SchemaFactory; |
35 |
| - |
36 |
| -import org.culturegraph.mf.util.ResourceUtil; |
37 |
| -import org.w3c.dom.Document; |
38 |
| -import org.w3c.dom.Element; |
39 |
| -import org.w3c.dom.NodeList; |
40 |
| -import org.xml.sax.SAXException; |
41 |
| - |
42 |
| - |
43 |
| -/** |
44 |
| - * @author Christoph Böhme <[email protected]> |
45 |
| - * |
46 |
| - */ |
47 |
| -public final class TestCaseLoader { |
48 |
| - |
49 |
| - /** |
50 |
| - * |
51 |
| - */ |
52 |
| - private static final String FILE_NOT_FOUND = "Could not find test case file: "; |
53 |
| - |
54 |
| - private static final String SCHEMA_FILE = "schema/metamorph-test.xsd"; |
55 |
| - |
56 |
| - private static final String TEST_CASE_TAG = "test-case"; |
57 |
| - |
58 |
| - private TestCaseLoader() { |
59 |
| - // No instances allowed |
60 |
| - } |
61 |
| - |
62 |
| - |
63 |
| - //TODO seems to be unused |
64 |
| - public static List<TestCase> load(final String testDef) { |
65 |
| - try { |
66 |
| - return load(ResourceUtil.getStream(testDef)); |
67 |
| - } catch (FileNotFoundException e) { |
68 |
| - throw new TestConfigurationException(FILE_NOT_FOUND + testDef, e); |
69 |
| - } |
70 |
| - } |
71 |
| - |
72 |
| - //TODO seems to be unused |
73 |
| - public static List<TestCase> load(final File testDefFile) { |
74 |
| - try { |
75 |
| - return load(ResourceUtil.getStream(testDefFile)); |
76 |
| - } catch (FileNotFoundException e) { |
77 |
| - throw new TestConfigurationException(FILE_NOT_FOUND + testDefFile, e); |
78 |
| - } |
79 |
| - } |
80 |
| - |
81 |
| - public static List<TestCase> load(final InputStream inputStream) { |
82 |
| - |
83 |
| - try { |
84 |
| - final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); |
85 |
| - final URL schemaUrl = Thread.currentThread().getContextClassLoader().getResource(SCHEMA_FILE); |
86 |
| - final Schema schema = schemaFactory.newSchema(schemaUrl); |
87 |
| - |
88 |
| - final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); |
89 |
| - builderFactory.setIgnoringElementContentWhitespace(true); |
90 |
| - builderFactory.setIgnoringComments(true); |
91 |
| - builderFactory.setNamespaceAware(true); |
92 |
| - builderFactory.setCoalescing(true); |
93 |
| - builderFactory.setSchema(schema); |
94 |
| - |
95 |
| - final DocumentBuilder builder = builderFactory.newDocumentBuilder(); |
96 |
| - final Document doc = builder.parse(inputStream); |
97 |
| - |
98 |
| - final List<TestCase> testCases = new ArrayList<TestCase>(); |
99 |
| - final NodeList testCaseNodes = doc.getElementsByTagName(TEST_CASE_TAG); |
100 |
| - for(int i=0; i < testCaseNodes.getLength(); ++i) { |
101 |
| - final Element testCaseElement = (Element) testCaseNodes.item(i); |
102 |
| - testCases.add(new TestCase(testCaseElement)); |
103 |
| - } |
104 |
| - |
105 |
| - return testCases; |
106 |
| - |
107 |
| - } catch (ParserConfigurationException e) { |
108 |
| - throw new TestConfigurationException("Parser configuration failed", e); |
109 |
| - } catch (SAXException e) { |
110 |
| - throw new TestConfigurationException("Parser error", e); |
111 |
| - } catch (IOException e) { |
112 |
| - throw new TestConfigurationException("Error while reading file", e); |
113 |
| - } |
114 |
| - } |
115 |
| -} |
116 |
| -
|
| 19 | +package org.culturegraph.mf.test; |
| 20 | + |
| 21 | +import java.io.File; |
| 22 | +import java.io.FileNotFoundException; |
| 23 | +import java.io.IOException; |
| 24 | +import java.io.InputStream; |
| 25 | +import java.net.URL; |
| 26 | +import java.util.ArrayList; |
| 27 | +import java.util.List; |
| 28 | + |
| 29 | +import javax.xml.XMLConstants; |
| 30 | +import javax.xml.parsers.DocumentBuilder; |
| 31 | +import javax.xml.parsers.DocumentBuilderFactory; |
| 32 | +import javax.xml.parsers.ParserConfigurationException; |
| 33 | +import javax.xml.validation.Schema; |
| 34 | +import javax.xml.validation.SchemaFactory; |
| 35 | + |
| 36 | +import org.culturegraph.mf.util.ResourceUtil; |
| 37 | +import org.w3c.dom.Document; |
| 38 | +import org.w3c.dom.Element; |
| 39 | +import org.w3c.dom.NodeList; |
| 40 | +import org.xml.sax.SAXException; |
| 41 | + |
| 42 | + |
| 43 | +/** |
| 44 | + * @author Christoph Böhme <[email protected]> |
| 45 | + * |
| 46 | + */ |
| 47 | +public final class TestCaseLoader { |
| 48 | + |
| 49 | + /** |
| 50 | + * |
| 51 | + */ |
| 52 | + private static final String FILE_NOT_FOUND = "Could not find test case file: "; |
| 53 | + |
| 54 | + private static final String SCHEMA_FILE = "schemata/metamorph-test.xsd"; |
| 55 | + |
| 56 | + private static final String TEST_CASE_TAG = "test-case"; |
| 57 | + |
| 58 | + private TestCaseLoader() { |
| 59 | + // No instances allowed |
| 60 | + } |
| 61 | + |
| 62 | + |
| 63 | + //TODO seems to be unused |
| 64 | + public static List<TestCase> load(final String testDef) { |
| 65 | + try { |
| 66 | + return load(ResourceUtil.getStream(testDef)); |
| 67 | + } catch (FileNotFoundException e) { |
| 68 | + throw new TestConfigurationException(FILE_NOT_FOUND + testDef, e); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + //TODO seems to be unused |
| 73 | + public static List<TestCase> load(final File testDefFile) { |
| 74 | + try { |
| 75 | + return load(ResourceUtil.getStream(testDefFile)); |
| 76 | + } catch (FileNotFoundException e) { |
| 77 | + throw new TestConfigurationException(FILE_NOT_FOUND + testDefFile, e); |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + public static List<TestCase> load(final InputStream inputStream) { |
| 82 | + |
| 83 | + try { |
| 84 | + final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); |
| 85 | + final URL schemaUrl = Thread.currentThread().getContextClassLoader().getResource(SCHEMA_FILE); |
| 86 | + final Schema schema = schemaFactory.newSchema(schemaUrl); |
| 87 | + |
| 88 | + final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); |
| 89 | + builderFactory.setIgnoringElementContentWhitespace(true); |
| 90 | + builderFactory.setIgnoringComments(true); |
| 91 | + builderFactory.setNamespaceAware(true); |
| 92 | + builderFactory.setCoalescing(true); |
| 93 | + builderFactory.setSchema(schema); |
| 94 | + |
| 95 | + final DocumentBuilder builder = builderFactory.newDocumentBuilder(); |
| 96 | + final Document doc = builder.parse(inputStream); |
| 97 | + |
| 98 | + final List<TestCase> testCases = new ArrayList<TestCase>(); |
| 99 | + final NodeList testCaseNodes = doc.getElementsByTagName(TEST_CASE_TAG); |
| 100 | + for(int i=0; i < testCaseNodes.getLength(); ++i) { |
| 101 | + final Element testCaseElement = (Element) testCaseNodes.item(i); |
| 102 | + testCases.add(new TestCase(testCaseElement)); |
| 103 | + } |
| 104 | + |
| 105 | + return testCases; |
| 106 | + |
| 107 | + } catch (ParserConfigurationException e) { |
| 108 | + throw new TestConfigurationException("Parser configuration failed", e); |
| 109 | + } catch (SAXException e) { |
| 110 | + throw new TestConfigurationException("Parser error", e); |
| 111 | + } catch (IOException e) { |
| 112 | + throw new TestConfigurationException("Error while reading file", e); |
| 113 | + } |
| 114 | + } |
| 115 | +} |
| 116 | + |
0 commit comments