Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for nested namespaces #78

Merged
merged 1 commit into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/test/java/com/datasonnet/XMLReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ void testXMLReaderExt() throws Exception {
JSONAssert.assertEquals(expectedJson, mappedJson, true);
}

@Test
void nestedNamespaces() throws Exception {
mapAndAssert("xmlNestedNamespaces.xml", "xmlNestedNamespaces.json");
}

@Test
void testMixedContent() throws Exception {
mapAndAssert("xmlMixedContent.xml", "xmlMixedContent.json");
Expand Down
13 changes: 11 additions & 2 deletions src/test/java/com/datasonnet/XMLWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,6 @@ void testFlattenMixedContentWithNamespaces() throws Exception {
assertEquals(expected, mapped, "Expected " + expected + " but got " + mapped);
}



@Test
void testXMLRoot() throws Exception {
String jsonData = TestResourceReader.readFileAsString("xmlRoot.json");
Expand All @@ -266,4 +264,15 @@ void testXMLRoot() throws Exception {
fail("This transformation should not fail");
}
}

@Test
void testNestedNamespaces() throws Exception {
String jsonData = TestResourceReader.readFileAsString("xmlNestedNamespaces.json");
String expectedXml = TestResourceReader.readFileAsString("xmlNestedNamespaces.xml");

Mapper mapper = new Mapper("payload");

String mappedXml = mapper.transform(new DefaultDocument<String>(jsonData, MediaTypes.APPLICATION_JSON), Collections.emptyMap(), MediaTypes.APPLICATION_XML).getContent();
assertThat(mappedXml, CompareMatcher.isSimilarTo(expectedXml).ignoreWhitespace());
}
}
21 changes: 21 additions & 0 deletions src/test/resources/xmlNestedNamespaces.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"a": {
"@xmlns": {
"$":"https://example.org"
},
"b:b": {
"@xmlns": {
"b":"https://example.com"
},
"b:c": {
"@xmlns": {
"c":"https://example.net"
},
"@c:d":"orange",
"c:e": {
"$":"nested","~":1
}, "~":1
}, "~":1
}, "~":1
}
}
8 changes: 8 additions & 0 deletions src/test/resources/xmlNestedNamespaces.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<a xmlns="https://example.org">
<b:b xmlns:b="https://example.com">
<b:c c:d="orange" xmlns:c="https://example.net">
<c:e>nested</c:e>
</b:c>
</b:b>
</a>