First part of onap rename
[appc.git] / appc-config / appc-config-audit / provider / src / test / java / org / openecomp / sdnc / config / audit / node / TestCompareNodeXml.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property.  All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdnc.config.audit.node;
22
23 import java.io.IOException;
24 import java.util.HashMap;
25 import org.junit.Test;
26 import org.openecomp.sdnc.config.audit.node.CompareNode;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
32
33 public class TestCompareNodeXml {
34     private static final Logger log = LoggerFactory.getLogger(TestCompareNodeXml.class);
35
36     @Test
37     public void TestCompareExtactXML() throws SvcLogicException {
38         log.debug("TestCompareNode.TestCompareExtactXML()");
39         SvcLogicContext ctx = new SvcLogicContext();
40         HashMap<String, String> testMap = new HashMap<String, String>();
41         CompareNode cmp = new CompareNode();
42         String s = "<configuration  xmlns=" + "\"http://xml.juniper.net/xnm/1.1/xnm\"" + " junos:commit-seconds="
43                 + "\"1473957536\" " + "junos:commit-localtime=" + "\"2016-09-15 16:38:56 UTC\" " + "junos:commit-user="
44                 + "\"root\"" + "><name>Test</name></configuration>";
45
46         String t = "<configuration  xmlns=" + "\"http://xml.juniper.net/xnm/1.1/xnm\"" + " junos:commit-seconds="
47                 + "\"1473957536\" " + "junos:commit-localtime=" + "\"2016-09-15 16:38:56 UTC\" " + "junos:commit-user="
48                 + "\"root\"" + "><name>Test</name></configuration>";
49         testMap.put("compareDataType", "RESTCONF-XML");
50         testMap.put("requestIdentifier", "123");
51         testMap.put("sourceData", s);
52         testMap.put("targetData", t);
53         cmp.compare(testMap, ctx);
54         assert (ctx.getAttribute("123." + "STATUS").equals("SUCCESS"));
55     }
56
57     @Test
58     public void TestCompareforAttributeOrder() throws IOException, SvcLogicException {
59         log.debug("TestCompareNode.TestCompareforAttributeOrder()");
60         SvcLogicContext ctx = new SvcLogicContext();
61         HashMap<String, String> testMap = new HashMap<String, String>();
62         CompareNode cmp = new CompareNode();
63         testMap.put("compareDataType", "XML");
64         testMap.put("sourceData",
65                 "<SipIfTermination><id>2</id><udpPortInUse>true</udpPortInUse><udpPort>5060</udpPort><tcpPortInUse>true</tcpPortInUse><tcpPort>5060</tcpPort></SipIfTermination>");
66         testMap.put("targetData",
67                 "<SipIfTermination><udpPortInUse>true</udpPortInUse><udpPort>5060</udpPort><tcpPortInUse>true</tcpPortInUse><tcpPort>5060</tcpPort><id>2</id></SipIfTermination>");
68         cmp.compare(testMap, ctx);
69         assert (ctx.getAttribute("STATUS").equals("SUCCESS"));
70     }
71
72     @Test
73     public void TestCompareForComments() throws SvcLogicException {
74         log.debug("TestCompareNode.TestCompareForComments()");
75         SvcLogicContext ctx = new SvcLogicContext();
76         HashMap<String, String> testMap = new HashMap<String, String>();
77         CompareNode cmp = new CompareNode();
78         testMap.put("compareDataType", "XML");
79         testMap.put("sourceData", "<SipIfTermination><id>2</id><!--this is a commnect --></SipIfTermination>");
80         testMap.put("targetData", "<SipIfTermination><id>2</id></SipIfTermination>");
81         cmp.compare(testMap, ctx);
82         assert (ctx.getAttribute("STATUS").equals("SUCCESS"));
83     }
84
85 }