2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Modifications Copyright (C) 2018 IBM.
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.sdnc.config.audit.node;
28 import java.io.IOException;
29 import java.util.HashMap;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
38 public class TestCompareNodeXml {
39 private static final Logger log = LoggerFactory.getLogger(TestCompareNodeXml.class);
40 private CompareNode cmp ;
41 private HashMap<String, String> testMap;
42 private SvcLogicContext ctx;
47 cmp = new CompareNode();
48 ctx = new SvcLogicContext();
49 testMap = new HashMap<String, String>();
53 public void TestCompareExtactXML() throws SvcLogicException {
54 log.debug("TestCompareNode.TestCompareExtactXML()");
55 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>";
56 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>";
57 testMap.put("compareDataType", "RESTCONF-XML");
58 testMap.put("requestIdentifier", "123");
59 testMap.put("sourceData", s);
60 testMap.put("targetData", t);
61 cmp.compare(testMap, ctx);
62 assert (ctx.getAttribute("123." + "STATUS").equals("SUCCESS"));
66 public void TestCompareforAttributeOrder() throws IOException, SvcLogicException {
67 log.debug("TestCompareNode.TestCompareforAttributeOrder()");
68 testMap.put("compareDataType", "XML");
69 testMap.put("sourceData",
70 "<SipIfTermination><id>2</id><udpPortInUse>true</udpPortInUse><udpPort>5060</udpPort><tcpPortInUse>true</tcpPortInUse><tcpPort>5060</tcpPort></SipIfTermination>");
71 testMap.put("targetData",
72 "<SipIfTermination><udpPortInUse>true</udpPortInUse><udpPort>5060</udpPort><tcpPortInUse>true</tcpPortInUse><tcpPort>5060</tcpPort><id>2</id></SipIfTermination>");
73 cmp.compare(testMap, ctx);
74 assert (ctx.getAttribute("STATUS").equals("SUCCESS"));
78 public void TestCompareForComments() throws SvcLogicException {
79 log.debug("TestCompareNode.TestCompareForComments()");
80 testMap.put("compareDataType", "XML");
81 testMap.put("sourceData", "<SipIfTermination><id>2</id><!--this is a commnect --></SipIfTermination>");
82 testMap.put("targetData", "<SipIfTermination><id>2</id></SipIfTermination>");
83 cmp.compare(testMap, ctx);
84 assert (ctx.getAttribute("STATUS").equals("SUCCESS"));