Merge "Enhanced List Level flow with backward support"
[so.git] / bpmn / MSOCoreBPMN / src / test / java / org / onap / so / bpmn / core / xml / XmlToolTest.java
1 /*
2  * ============LICENSE_START======================================================= ONAP : SO
3  * ================================================================================ Copyright (C) 2018 AT&T Intellectual
4  * Property. All rights reserved. ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * 
8  * http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
11  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
12  * specific language governing permissions and limitations under the License.
13  * ============LICENSE_END=========================================================
14  */
15
16 package org.onap.so.bpmn.core.xml;
17
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertNotNull;
20 import java.util.Optional;
21 import org.junit.Test;
22
23 public class XmlToolTest {
24
25     private String response = "<Response>good</Response>";
26     private String responseModified = "<Response>veryGood</Response>";
27     private String encodeResponse = "&lt;Response&gt;good&lt;/Response&gt;";
28     private String encodeResponseNamespace =
29             "<Response xmlns:ns2=\"http://ecomp.att.com/mso/request/types/v1\">good</Response>";
30     private String attribute = "<Response>good&\"bad\"</Response>";
31     // private String updatedAttribute = "&lt;Response&gt;good&amp;&quot;bad&quot;&lt;/Response&gt;";
32
33     private String content = "<dummy><configuration-event>" + "<event-type>test</event-type>"
34             + "<event-correlator-type>test</event-correlator-type>" + "<event-correlator>123</event-correlator>"
35             + "<event-parameters><event-parameter>" + "<tag-name>test</tag-name>"
36             + "<tag-value>test</tag-value></event-parameter></event-parameters>" + "</configuration-event></dummy>";
37
38     @Test
39     public void test() throws Exception {
40         Object xmlMessage = new String(response);
41         String xmlResponse = XmlTool.normalize(xmlMessage);
42         assertEquals(response, xmlResponse.toString());
43         String xmlEncode = XmlTool.encode(xmlMessage);
44         assertEquals(encodeResponse, xmlEncode.toString());
45         Optional<String> optXml = XmlTool.modifyElement(response, "Response", "veryGood");
46         Object obj1 = new String(optXml.get().toString());
47         String noPreamble = XmlTool.removePreamble(obj1);
48         assertEquals(responseModified, noPreamble.toString());
49         Object obj2 = new String(encodeResponseNamespace);
50         String noNamespace = XmlTool.removeNamespaces(obj2);
51         assertEquals(response, noNamespace.toString());
52         Object obj3 = new String(attribute);
53
54         assertEquals(null, XmlTool.normalize(null));
55         assertEquals(null, XmlTool.encode(null));
56         assertEquals(null, XmlTool.removePreamble(null));
57         assertEquals(null, XmlTool.removeNamespaces(null));
58         assertEquals(Optional.empty(), XmlTool.modifyElement(null, "Response", "veryGood"));
59     }
60
61     @Test
62     public void normalizeTest() throws Exception {
63         String response = XmlTool.normalize(content);
64         assertNotNull(response);
65     }
66
67     @Test
68     public void modifyElementTest() throws Exception {
69         String response = XmlTool.modifyElement(content, "event-type", "uCPE-VMS").get();
70         assertNotNull(response);
71     }
72 }