2  * ============LICENSE_START=======================================================
 
   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
 
  13  *      http://www.apache.org/licenses/LICENSE-2.0
 
  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.
 
  21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
 
  22  * ============LICENSE_END=========================================================
 
  25 package org.onap.sdnc.config.audit.node;
 
  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;
 
  34 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 
  35 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
 
  37 public class TestCompareNodeXml {
 
  38     private static final Logger log = LoggerFactory.getLogger(TestCompareNodeXml.class);
 
  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"));
 
  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"));
 
  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"));