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;
 
  37 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 
  38 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
 
  40 public class TestCompareNodeJson {
 
  41     private static final Logger log = LoggerFactory.getLogger(TestCompareNodeJson.class);
 
  42     private CompareNode cmp;
 
  43     private SvcLogicContext ctx;
 
  44     private HashMap<String, String> testMap;
 
  49         cmp = new CompareNode();
 
  50         ctx = new SvcLogicContext();
 
  51         testMap = new HashMap<String, String>();
 
  56     public void TestCompareJsonForSamePayload() throws SvcLogicException {
 
  57         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}";
 
  58         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}";
 
  59         testMap.put("compareDataType", "RestConf");
 
  60         testMap.put("sourceData", controlJson);
 
  61         testMap.put("targetData", testJson);
 
  62         cmp.compare(testMap, ctx);
 
  63         assert (ctx.getAttribute("STATUS").equals("SUCCESS"));
 
  67     public void TestCompareCliForNoPayload() throws SvcLogicException {
 
  68         cmp.compare(testMap, ctx);
 
  69         assertEquals ("FAILURE",ctx.getAttribute("STATUS"));
 
  73     public void TestCompareCliForNullCompareType() throws SvcLogicException {
 
  74         testMap.put("compareDataType", "RestConf");
 
  75         cmp.compare(testMap, ctx);
 
  76         assertEquals ("FAILURE",ctx.getAttribute("STATUS"));
 
  80     public void TestCompareJsonFordifferentPayload() throws SvcLogicException {
 
  81         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}";
 
  82         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}";
 
  83         testMap.put("compareDataType", "RestConf");
 
  84         testMap.put("sourceData", controlJson);
 
  85         testMap.put("targetData", testJson);
 
  86         cmp.compare(testMap, ctx);
 
  87         assert (ctx.getAttribute("STATUS").equals("FAILURE"));
 
  91     public void TestCompareJsonFordifferentPayloadWithXMLDataType() throws SvcLogicException {
 
  92         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}";
 
  93         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}";
 
  94         testMap.put("compareDataType", "XML");
 
  95         testMap.put("sourceData", controlJson);
 
  96         testMap.put("targetData", testJson);
 
  97         cmp.compare(testMap, ctx);
 
  98         assertEquals ("FAILURE",ctx.getAttribute("STATUS"));