Skip to content

Commit 6478a08

Browse files
committed
Add more test cases for default namespace handling
Adds additional test cases for `SimpleXmlEncoder` to ensure that the default namespace is set correctly in all situations.
1 parent ee2d52e commit 6478a08

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

metafacture-xml/src/test/java/org/metafacture/xml/SimpleXmlEncoderTest.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void shouldAddNamespaceToRootElement() {
110110
}
111111

112112
@Test
113-
public void shouldAddNamespaceWithEmptyKeyAsDefaultNamespace() {
113+
public void shouldAddNamespaceWithEmptyKeyAsDefaultNamespaceToRootTag() {
114114
final Map<String, String> namespaces = new HashMap<String, String>();
115115
namespaces.put("", "http://example.org/ns");
116116
simpleXmlEncoder.setNamespaces(namespaces);
@@ -121,6 +121,16 @@ public void shouldAddNamespaceWithEmptyKeyAsDefaultNamespace() {
121121
getResultXml());
122122
}
123123

124+
@Test
125+
public void shouldAddNamespaceWithEmptyKeyFromPropertiesFileAsDefaultNamespaceToRootTag() {
126+
simpleXmlEncoder.setNamespaceFile("org/metafacture/xml/SimpleXmlEncoderTest_namespaces.properties");
127+
128+
emitEmptyRecord();
129+
130+
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><records xmlns=\"http://example.org/ns\"><record /></records>",
131+
getResultXml());
132+
}
133+
124134
@Test
125135
public void shouldNotEmitRootTagIfWriteRootTagIsFalse() {
126136
simpleXmlEncoder.setWriteRootTag(false);
@@ -144,6 +154,30 @@ public void shouldAddNamespacesToRecordTagIfWriteRootTagIsFalse() {
144154
getResultXml());
145155
}
146156

157+
@Test
158+
public void shouldAddNamespaceWithEmptyKeyAsDefaultNamespaceToRecordTag() {
159+
final Map<String, String> namespaces = new HashMap<String, String>();
160+
namespaces.put("", "http://example.org/ns");
161+
simpleXmlEncoder.setNamespaces(namespaces);
162+
simpleXmlEncoder.setWriteRootTag(false);
163+
164+
emitEmptyRecord();
165+
166+
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><record xmlns=\"http://example.org/ns\" />",
167+
getResultXml());
168+
}
169+
170+
@Test
171+
public void shouldAddNamespaceWithEmptyKeyFromPropertiesFileAsDefaultNamespaceToRecordTag() {
172+
simpleXmlEncoder.setNamespaceFile("org/metafacture/xml/SimpleXmlEncoderTest_namespaces.properties");
173+
simpleXmlEncoder.setWriteRootTag(false);
174+
175+
emitEmptyRecord();
176+
177+
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><record xmlns=\"http://example.org/ns\" />",
178+
getResultXml());
179+
}
180+
147181
private void emitTwoRecords() {
148182
simpleXmlEncoder.startRecord("X");
149183
simpleXmlEncoder.literal(TAG, VALUE);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
=http://example.org/ns

0 commit comments

Comments
 (0)