Skip to content

Commit f060dd4

Browse files
committed
Fix #229: Add support for MarcXML in test cases
Enables MarcXML as input and result format in the Metamorph test framework.
1 parent c54e2e0 commit f060dd4

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/main/resources/metastream-readers.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ text/x-marc21 org.culturegraph.mf.stream.reader.MarcReader
1616
text/x-cg+xml org.culturegraph.mf.stream.reader.CGXmlReader
1717
text/x-formeta org.culturegraph.mf.stream.reader.FormetaReader
1818
application/x-cgentity org.culturegraph.mf.stream.reader.CGEntityReader
19+
application/marcxml+xml org.culturegraph.mf.stream.reader.MarcXmlReader

src/test/java/org/culturegraph/mf/test/TestCaseTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,22 @@ public void shouldSupportCGXmlAsInputAndResultFormat() {
8686
// an exception.
8787
}
8888

89+
@Test
90+
public void issue229ShouldSupportMarcXmlAsInputAndResultFormat() {
91+
final Element inputElement = createMarcXmlRecord(INPUT_TAG);
92+
final Element resultElement = createMarcXmlRecord(RESULT_TAG);
93+
94+
final Element testCaseElement = document.createElement(TEST_CASE_TAG);
95+
testCaseElement.appendChild(inputElement);
96+
testCaseElement.appendChild(resultElement);
97+
98+
final TestCase testCase = new TestCase(testCaseElement);
99+
testCase.run();
100+
101+
// The test was successful if run does not throw
102+
// an exception.
103+
}
104+
89105
@Test
90106
public void issue219ShouldResolveXIncludesInMetamorphResources() {
91107
final Element inputElement = createFormetaRecord(INPUT_TAG);
@@ -125,4 +141,19 @@ private Element createCGXmlRecord(final String elementName) {
125141
return element;
126142
}
127143

144+
private Element createMarcXmlRecord(final String elementName) {
145+
final Element fieldElement = document.createElement("controlfield");
146+
fieldElement.setAttribute("tag", "001");
147+
fieldElement.setTextContent("123");
148+
final Element recordElement = document.createElement("record");
149+
recordElement.appendChild(fieldElement);
150+
final Element collectionElement = document.createElementNS(
151+
"http://www.loc.gov/MARC21/slim", "collection");
152+
collectionElement.appendChild(recordElement);
153+
final Element element = document.createElement(elementName);
154+
element.setAttribute("type", "application/marcxml+xml");
155+
element.appendChild(collectionElement);
156+
return element;
157+
}
158+
128159
}

0 commit comments

Comments
 (0)