@@ -73,6 +73,64 @@ void testMsgXml() {
7373 assertEquals (expected , result );
7474 }
7575
76+ @ Test
77+ void testXmlEncodingOfIdAndType1 () {
78+ final String id = "i<&d>" + XmlFixture .TEXT ;
79+ final String type = "t>yp<e&" + XmlFixture .TEXT ;
80+ final String actualXml =
81+ new StructuredDataMessage (id , "discarded message" , type ).getFormattedMessage (new String [] {"XML" });
82+ final String expectedXml = "<StructuredData>\n "
83+ + "<type>t>yp<e&" + XmlFixture .ENCODED_TEXT
84+ + "</type>\n "
85+ + "<id>i<&d>" + XmlFixture .ENCODED_TEXT
86+ + "</id>\n "
87+ // Following part is encoded by `MapMessage::asXml`, hence, fuzzed & tested elsewhere
88+ + "<Map>\n "
89+ + "</Map>\n "
90+ + "</StructuredData>\n " ;
91+ assertEquals (expectedXml , actualXml );
92+ }
93+
94+ @ Test
95+ void testXmlEncodingOfIdAndType2 () {
96+ final String idName = "id&<-name>" + XmlFixture .TEXT ;
97+ final String idEnterpriseNumber = "id&<-enterprise-number>" + XmlFixture .TEXT ;
98+ final String [] idRequired = {"id&<-required>" + XmlFixture .TEXT };
99+ final String [] idOptional = {"id&<-optional>" + XmlFixture .TEXT };
100+ final String type = "t>yp<e&" + XmlFixture .TEXT ;
101+ final StructuredDataId id =
102+ new StructuredDataId (idName , idEnterpriseNumber , idRequired , idOptional , Integer .MAX_VALUE );
103+ final String actualXml =
104+ new StructuredDataMessage (id , "discarded message" , type ).getFormattedMessage (new String [] {"XML" });
105+ final String expectedXml = "<StructuredData>\n "
106+ + "<type>t>yp<e&" + XmlFixture .ENCODED_TEXT
107+ + "</type>\n "
108+ + "<id>" + "id&<-name>" + XmlFixture .ENCODED_TEXT
109+ + "@id&<-enterprise-number>" + XmlFixture .ENCODED_TEXT
110+ + "</id>\n "
111+ // Following part is encoded by `MapMessage::asXml`, hence, fuzzed & tested elsewhere
112+ + "<Map>\n "
113+ + "</Map>\n "
114+ + "</StructuredData>\n " ;
115+ assertEquals (expectedXml , actualXml );
116+ }
117+
118+ private enum XmlFixture {
119+ ;
120+
121+ private static final String TEXT ;
122+
123+ private static final String ENCODED_TEXT ;
124+
125+ static {
126+ final String notBmp = new String (Character .toChars (0x10000 ));
127+ final String invalid = "A\uD800 B\uDE00 C\0 \1 \2 \3 " ;
128+ final String encodedInvalid = "A\uFFFD B\uFFFD C\uFFFD \uFFFD \uFFFD \uFFFD " ;
129+ TEXT = " '\" \t \r \n " + notBmp + invalid ;
130+ ENCODED_TEXT = " '"\t \r \n " + notBmp + encodedInvalid ;
131+ }
132+ }
133+
76134 @ Test
77135 void testBuilder () {
78136 final String testMsg = "Test message {}" ;
0 commit comments