Skip to content

Commit

Permalink
Merge pull request #78 from datasonnet/nested-namespace-tests
Browse files Browse the repository at this point in the history
Add tests for nested namespaces
  • Loading branch information
fugu13 authored Dec 2, 2020
2 parents e631a62 + d996e05 commit 1a2ae02
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
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>

0 comments on commit 1a2ae02

Please sign in to comment.