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