added test case to TestParsingNode.java
[appc.git] / appc-config / appc-config-audit / provider / src / test / java / org / onap / sdnc / config / audit / node / TestCompareNodeJson.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
14  * 
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  * 
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.
22  * 
23  * ============LICENSE_END=========================================================
24  */
25
26 package org.onap.sdnc.config.audit.node;
27
28 import java.util.HashMap;
29
30 import org.junit.Test;
31 import org.onap.sdnc.config.audit.node.CompareNode;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import static org.junit.Assert.assertEquals;
35
36 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
38
39 public class TestCompareNodeJson {
40     private static final Logger log = LoggerFactory.getLogger(TestCompareNodeJson.class);
41
42     @Test
43     public void TestCompareJsonForSamePayload() throws SvcLogicException {
44         SvcLogicContext ctx = new SvcLogicContext();
45         HashMap<String, String> testMap = new HashMap<String, String>();
46         CompareNode cmp = new CompareNode();
47         String controlJson = "{\n\"input\": {\n   \"appc-request-header\": {\n       \"svc-request-id\": \"000000000\", \n \"svc-action\": \"prepare\"   \n }, \n\"request-information\": {\n \"request-id\": \"000000000\", \n\"request-action\": \"VsbgServiceActivateRequest\", \n\"request-sub-action\": \"PREPARE\",  \n \"source\": \"Version2\" \n} \n} \n}";
48         String testJson = "{\n\"input\": {\n  \"appc-request-header\": {\n \"svc-request-id\": \"000000000\", \n \"svc-action\": \"prepare\"   \n }, \n\"request-information\": {\n \"request-id\": \"000000000\", \n\"request-action\": \"VsbgServiceActivateRequest\", \n\"request-sub-action\": \"PREPARE\",  \n \"source\": \"Version2\" \n} \n} \n}";
49         testMap.put("compareDataType", "RestConf");
50         testMap.put("sourceData", controlJson);
51         testMap.put("targetData", testJson);
52         cmp.compare(testMap, ctx);
53         assert (ctx.getAttribute("STATUS").equals("SUCCESS"));
54     }
55     
56     @Test
57     public void TestCompareCliForNoPayload() throws SvcLogicException {
58         SvcLogicContext ctx = new SvcLogicContext();
59         HashMap<String, String> testMap = new HashMap<String, String>();
60         CompareNode cmp = new CompareNode();
61         cmp.compare(testMap, ctx);
62         assertEquals ("FAILURE",ctx.getAttribute("STATUS"));
63     }
64     
65     @Test
66     public void TestCompareCliForNullCompareType() throws SvcLogicException {
67         SvcLogicContext ctx = new SvcLogicContext();
68         HashMap<String, String> testMap = new HashMap<String, String>();
69         CompareNode cmp = new CompareNode();
70         testMap.put("compareDataType", "RestConf");
71         cmp.compare(testMap, ctx);
72         assertEquals ("FAILURE",ctx.getAttribute("STATUS"));
73     }
74
75     @Test
76     public void TestCompareJsonFordifferentPayload() throws SvcLogicException {
77         SvcLogicContext ctx = new SvcLogicContext();
78         HashMap<String, String> testMap = new HashMap<String, String>();
79         CompareNode cmp = new CompareNode();
80         String controlJson = "{\n\"input\": {\n   \"appc-request-header\": {\n       \"svc-request-id\": \"000000000\", \n \"svc-action\": \"prepare\"   \n }, \n\"request-information\": {\n \"request-id\": \"000000000\", \n\"request-action\": \"VsbgServiceActivateRequest\", \n\"request-sub-action\": \"PREPARE\",  \n \"source\": \"Version2\" \n} \n} \n}";
81         String testJson = "{\n\"input\": {\n  \"appc-request-header\": { \n \"svc-action\": \"prepare\"   \n }, \n\"request-information\": {\n \"request-id\": \"0000000000\", \n\"request-action\": \"VsbgServiceActivateRequest\", \n\"request-sub-action\": \"PREPARE\",  \n \"source\": \"Version2\" \n} \n} \n}";
82         testMap.put("compareDataType", "RestConf");
83         testMap.put("sourceData", controlJson);
84         testMap.put("targetData", testJson);
85         cmp.compare(testMap, ctx);
86         assert (ctx.getAttribute("STATUS").equals("FAILURE"));
87     }
88     
89     @Test
90     public void TestCompareJsonFordifferentPayloadWithXMLDataType() throws SvcLogicException {
91         SvcLogicContext ctx = new SvcLogicContext();
92         HashMap<String, String> testMap = new HashMap<String, String>();
93         CompareNode cmp = new CompareNode();
94         String controlJson = "{\n\"input\": {\n   \"appc-request-header\": {\n       \"svc-request-id\": \"000000000\", \n \"svc-action\": \"prepare\"   \n }, \n\"request-information\": {\n \"request-id\": \"000000000\", \n\"request-action\": \"VsbgServiceActivateRequest\", \n\"request-sub-action\": \"PREPARE\",  \n \"source\": \"Version2\" \n} \n} \n}";
95         String testJson = "{\n\"input\": {\n  \"appc-request-header\": { \n \"svc-action\": \"prepare\"   \n }, \n\"request-information\": {\n \"request-id\": \"0000000000\", \n\"request-action\": \"VsbgServiceActivateRequest\", \n\"request-sub-action\": \"PREPARE\",  \n \"source\": \"Version2\" \n} \n} \n}";
96         testMap.put("compareDataType", "XML");
97         testMap.put("sourceData", controlJson);
98         testMap.put("targetData", testJson);
99         cmp.compare(testMap, ctx);
100         assertEquals ("FAILURE",ctx.getAttribute("STATUS"));
101     }
102 }