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.util.HashMap;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.sdnc.config.audit.node.CompareNode;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import static org.junit.Assert.assertEquals;
36 import static org.junit.Assert.assertNotNull;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
41 public class TestCompareNodeJson {
42 private static final Logger log = LoggerFactory.getLogger(TestCompareNodeJson.class);
43 private CompareNode cmp;
44 private SvcLogicContext ctx;
45 private HashMap<String, String> testMap;
50 cmp = new CompareNode();
51 ctx = new SvcLogicContext();
52 testMap = new HashMap<String, String>();
57 public void TestCompareJsonForSamePayload() throws SvcLogicException {
58 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}";
59 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}";
60 testMap.put("compareDataType", "RestConf");
61 testMap.put("sourceData", controlJson);
62 testMap.put("targetData", testJson);
63 cmp.compare(testMap, ctx);
64 assert (ctx.getAttribute("STATUS").equals("SUCCESS"));
65 assertNotNull(testMap);
69 public void TestCompareCliForNoPayload() throws SvcLogicException {
70 cmp.compare(testMap, ctx);
71 assertEquals ("FAILURE",ctx.getAttribute("STATUS"));
75 public void TestCompareCliForNullCompareType() throws SvcLogicException {
76 testMap.put("compareDataType", "RestConf");
77 cmp.compare(testMap, ctx);
78 assertEquals ("FAILURE",ctx.getAttribute("STATUS"));
82 public void TestCompareJsonFordifferentPayload() throws SvcLogicException {
83 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}";
84 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}";
85 testMap.put("compareDataType", "RestConf");
86 testMap.put("sourceData", controlJson);
87 testMap.put("targetData", testJson);
88 cmp.compare(testMap, ctx);
89 assert (ctx.getAttribute("STATUS").equals("FAILURE"));
90 assertNotNull(testJson);
94 public void TestCompareJsonFordifferentPayloadWithXMLDataType() throws SvcLogicException {
95 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}";
96 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}";
97 testMap.put("compareDataType", "XML");
98 testMap.put("sourceData", controlJson);
99 testMap.put("targetData", testJson);
100 cmp.compare(testMap, ctx);
101 assertEquals ("FAILURE",ctx.getAttribute("STATUS"));