-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
proxies.xml: Allow XML Content in Mixed Configuration Elements (#1388)
* Cleanup * Cleanup2
- Loading branch information
Showing
7 changed files
with
225 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
annot/src/test/java/com/predic8/membrane/annot/AnnotUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.predic8.membrane.annot; | ||
|
||
import org.junit.jupiter.api.*; | ||
import org.w3c.dom.*; | ||
|
||
import javax.xml.parsers.*; | ||
import java.io.*; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class AnnotUtilsTest { | ||
|
||
@Test | ||
void simple() throws Exception { | ||
assertEquals("<foo>123</foo>", str(""" | ||
<e><foo>123</foo></e> | ||
""")); | ||
} | ||
|
||
@Test | ||
void empty() throws Exception { | ||
assertEquals("<foo></foo>", str(""" | ||
<e><foo/></e> | ||
""")); | ||
} | ||
|
||
@Test | ||
void str() throws Exception { | ||
assertEquals("123", str(""" | ||
<e>123</e> | ||
""")); | ||
} | ||
|
||
@Test | ||
void nothing() throws Exception { | ||
assertEquals("", str(""" | ||
<e></e> | ||
""")); | ||
} | ||
|
||
@Test | ||
void attr() throws Exception { | ||
assertEquals("<foo bar=\"3\"></foo>", str(""" | ||
<e><foo bar="3"/></e> | ||
""")); | ||
} | ||
|
||
@Test | ||
void nested() throws Exception { | ||
assertEquals("<a><b><c></c></b></a>", str(""" | ||
<e><a><b><c></c></b></a></e> | ||
""")); | ||
} | ||
|
||
@Test | ||
void mixed() throws Exception { | ||
assertEquals("1<a>2<b>3<c>4</c>5</b>6</a>7", str(""" | ||
<e>1<a>2<b>3<c>4</c>5</b>6</a>7</e> | ||
""")); | ||
} | ||
|
||
@Test | ||
void ns() throws Exception { | ||
assertEquals("<foo ns=\"bar\"></foo>", str(""" | ||
<e><foo ns="bar"></foo></e> | ||
""")); | ||
} | ||
|
||
@Test | ||
void cdata() throws Exception { | ||
assertEquals("1<foo ns=\"bar\">234</foo>5", str(""" | ||
<e>1<foo ns="bar">2<![CDATA[3]]>4</foo>5</e> | ||
""")); | ||
} | ||
|
||
@Test | ||
void entities() throws Exception { | ||
assertEquals("1<foo>> < &</foo>2", str(""" | ||
<e>1<foo>> < &</foo>2</e> | ||
""")); | ||
} | ||
|
||
|
||
private String str(String s) throws Exception { | ||
return AnnotUtils.getContentAsString(parse(s)); | ||
} | ||
|
||
private Element parse(String xml) throws Exception { | ||
ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes()); | ||
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); | ||
Document doc = builder.parse(bais); | ||
return doc.getDocumentElement(); | ||
} | ||
} |
Oops, something went wrong.