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;
37 import static org.junit.Assert.assertEquals;
38 import static org.junit.Assert.assertNotNull;
40 public class TestCompareNodeXml {
41 private static final Logger log = LoggerFactory.getLogger(TestCompareNodeXml.class);
42 private CompareNode cmp ;
43 private HashMap<String, String> testMap;
44 private SvcLogicContext ctx;
49 cmp = new CompareNode();
50 ctx = new SvcLogicContext();
51 testMap = new HashMap<String, String>();
55 public void TestCompareExtactXML() throws SvcLogicException {
56 log.debug("TestCompareNode.TestCompareExtactXML()");
57 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>";
58 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>";
59 testMap.put("compareDataType", "RESTCONF-XML");
60 testMap.put("requestIdentifier", "123");
61 testMap.put("sourceData", s);
62 testMap.put("targetData", t);
63 cmp.compare(testMap, ctx);
64 assert (ctx.getAttribute("123." + "STATUS").equals("SUCCESS"));
69 public void TestCompareforAttributeOrder() throws IOException, SvcLogicException {
70 log.debug("TestCompareNode.TestCompareforAttributeOrder()");
71 testMap.put("compareDataType", "XML");
72 testMap.put("sourceData",
73 "<SipIfTermination><id>2</id><udpPortInUse>true</udpPortInUse><udpPort>5060</udpPort><tcpPortInUse>true</tcpPortInUse><tcpPort>5060</tcpPort></SipIfTermination>");
74 testMap.put("targetData",
75 "<SipIfTermination><udpPortInUse>true</udpPortInUse><udpPort>5060</udpPort><tcpPortInUse>true</tcpPortInUse><tcpPort>5060</tcpPort><id>2</id></SipIfTermination>");
76 cmp.compare(testMap, ctx);
77 assert (ctx.getAttribute("STATUS").equals("SUCCESS"));
78 assertNotNull(testMap);
82 public void TestCompareForComments() throws SvcLogicException {
83 log.debug("TestCompareNode.TestCompareForComments()");
84 testMap.put("compareDataType", "XML");
85 testMap.put("sourceData", "<SipIfTermination><id>2</id><!--this is a commnect --></SipIfTermination>");
86 testMap.put("targetData", "<SipIfTermination><id>2</id></SipIfTermination>");
87 cmp.compare(testMap, ctx);
88 assert (ctx.getAttribute("STATUS").equals("SUCCESS"));
89 assertNotNull(testMap);