efd23439f506fa27a42ee65d6f5bfcc2e95b220c
[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 java.util.Properties;
26
27 import org.junit.Test;
28 import org.openecomp.sdnc.config.audit.node.CompareNode;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 import org.openecomp.sdnc.sli.SvcLogicContext;
33 import org.openecomp.sdnc.sli.SvcLogicException;
34
35
36 public class TestCompareNodeXml
37 {
38     private static final Logger log = LoggerFactory.getLogger(TestCompareNodeXml.class);
39
40     //@Test
41     public void TestCompareExtactXML()
42     {
43         log.debug("TestCompareNode.TestCompareExtactXML()");
44         SvcLogicContext ctx  = new SvcLogicContext();
45         HashMap<String, String> testMap = new HashMap<String, String>();
46         CompareNode cmp  = new CompareNode();
47         try
48         {
49             String s="<configuration  xmlns="
50                     + "\"http://xml.juniper.net/xnm/1.1/xnm\""
51                     + " junos:commit-seconds="
52                     +"\"1473957536\" "
53                     +"junos:commit-localtime="
54                     +"\"2016-09-15 16:38:56 UTC\" "
55                     + "junos:commit-user="
56                     +"\"root\""
57                     +"><name>Test</name></configuration>";
58
59             String t ="<configuration  xmlns="
60                     + "\"http://xml.juniper.net/xnm/1.1/xnm\""
61                     + " junos:commit-seconds="
62                     +"\"1473957536\" "
63                     +"junos:commit-localtime="
64                     +"\"2016-09-15 16:38:56 UTC\" "
65                     + "junos:commit-user="
66                     +"\"root\""
67                     +"><name>Test</name></configuration>";
68
69             System.out.println("s=" + s);
70
71             testMap.put("compareDataType", "RESTCONF-XML");
72             testMap.put("requestIdentifier", "123");
73             testMap.put("sourceData", s);
74             testMap.put("targetData", t);
75             cmp.compare(testMap, ctx);
76             assert(ctx.getAttribute("123." + "STATUS").equals("SUCCESS"));
77         }
78         catch (SvcLogicException e)
79         {
80             // TODO Auto-generated catch block
81             e.printStackTrace();
82         }
83     }
84     //@Test
85     public void TestCompareforAttributeOrder() throws IOException
86     {
87         log.debug("TestCompareNode.TestCompareforAttributeOrder()");
88         SvcLogicContext ctx  = new SvcLogicContext();
89         HashMap<String, String> testMap = new HashMap<String, String>();
90         CompareNode cmp  = new CompareNode();
91         testMap.put("compareDataType", "XML");
92         testMap.put("sourceData", "<SipIfTermination><id>2</id><udpPortInUse>true</udpPortInUse><udpPort>5060</udpPort><tcpPortInUse>true</tcpPortInUse><tcpPort>5060</tcpPort></SipIfTermination>");
93         testMap.put("targetData", "<SipIfTermination><udpPortInUse>true</udpPortInUse><udpPort>5060</udpPort><tcpPortInUse>true</tcpPortInUse><tcpPort>5060</tcpPort><id>2</id></SipIfTermination>");
94         try
95         {
96             cmp.compare(testMap, ctx);
97         }
98         catch (SvcLogicException e)
99         {
100             e.printStackTrace();
101         }
102         assert(ctx.getAttribute("STATUS").equals("SUCCESS"));
103     }
104
105     //@Test
106     public void TestCompareForComments()
107     {
108         log.debug("TestCompareNode.TestCompareForComments()");
109         SvcLogicContext ctx  = new SvcLogicContext();
110         HashMap<String, String> testMap = new HashMap<String, String>();
111         CompareNode cmp  = new CompareNode();
112
113         try
114         {
115             testMap.put("compareDataType", "XML");
116             testMap.put("sourceData", "<SipIfTermination><id>2</id><!--this is a commnect --></SipIfTermination>");
117             testMap.put("targetData", "<SipIfTermination><id>2</id></SipIfTermination>");
118             cmp.compare(testMap, ctx);
119             assert(ctx.getAttribute("STATUS").equals("SUCCESS"));
120         }
121         catch (SvcLogicException e)
122         {
123             e.printStackTrace();
124         }
125     }
126
127 }