diff options
author | Sandeep Shah <sandeep.shah2@techmahindra.com> | 2019-05-26 10:37:21 -0500 |
---|---|---|
committer | Sandeep Shah <sandeep.shah2@techmahindra.com> | 2019-05-26 10:37:21 -0500 |
commit | 6d6ccec6604ea2cd672bb1c453d6d1f96e9c0518 (patch) | |
tree | 29385083320a688d357d55c86836ae7cfb571763 | |
parent | 3a86df02c0c53b9c4c1138084a18bb724d22c4ef (diff) |
Fix bug with DMAAP listener for SDNR OOFPCIPOC
Replaced 2 dmaap consumers with one consumer for DMAAP topic
SDNR-CL. Also updated corresponding JUNIT file.
Issue-ID: CCSDK-1364
Signed-off-by: SandeepLinux <sandeep.shah2@techmahindra.com>
Change-Id: I840a38d04423954102865a68b0e216c745ed161b
-rw-r--r-- | dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/OofPciPocDmaapConsumers.java (renamed from dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/ANRChangesFromPolicyToSDNRDmaapConsumer.java) | 251 | ||||
-rw-r--r-- | dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/PciChangesFromPolicyToSDNRDmaapConsumer.java | 314 | ||||
-rw-r--r-- | dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestANRChangesFromPolicyToSDNRDmaapConsumer.java | 142 | ||||
-rw-r--r-- | dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestOofPciPocDmaapConsumers.java | 314 | ||||
-rw-r--r-- | dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestPciChangesFromPolicyToSDNRDmaapConsumer.java | 181 |
5 files changed, 520 insertions, 682 deletions
diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/ANRChangesFromPolicyToSDNRDmaapConsumer.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/OofPciPocDmaapConsumers.java index 5bc2c601..2e6ae742 100644 --- a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/ANRChangesFromPolicyToSDNRDmaapConsumer.java +++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/OofPciPocDmaapConsumers.java @@ -40,35 +40,41 @@ import org.slf4j.LoggerFactory; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -public class ANRChangesFromPolicyToSDNRDmaapConsumer extends SdncDmaapConsumerImpl { +public class OofPciPocDmaapConsumers extends SdncDmaapConsumerImpl { - private static final Logger LOG = LoggerFactory.getLogger(ANRChangesFromPolicyToSDNRDmaapConsumer.class); + private static final Logger LOG = LoggerFactory.getLogger(OofPciPocDmaapConsumers.class); private static final String SDNC_ENDPOINT = "SDNC.endpoint"; private static final String TEMPLATE = "SDNC.template"; private static final String DMAAPLISTENERROOT = "DMAAPLISTENERROOT"; + private static final String UTF_8 = "UTF-8"; private static final String PARAMETER_NAME = "parameter-name"; private static final String STRING_VALUE = "string-value"; - private static final String GENERIC_NEIGHBOR_CONFIGURATION_INPUT = "generic-neighbor-configuration-input."; - private static final String GENERIC_NEIGHBOR_CONFIGURATION_INPUT_NEIGHBOR_LIST_IN_USE = GENERIC_NEIGHBOR_CONFIGURATION_INPUT.concat("neighbor-list-in-use"); + private static final String PHYSICAL_CELL_ID_INPUT_FAP_SERVICE = "configuration-phy-cell-id-input.fap-service"; private static final String EVENT_HEADER = "event-header"; private static final String ACTION = "Action"; - private static final String PAYLOAD = "Payload"; private static final String CONFIGURATIONS = "Configurations"; - private static final String MODIFY_CONFIG_ANR = "ModifyConfigANR"; - private static final String MAP_FILE_NAME = "anr-changes-from-policy-to-sdnr"; + private static final String MODIFY_CONFIG = "ModifyConfig"; private static final String DATA = "data"; private static final String FAP_SERVICE = "FAPService"; + + private static final String PAYLOAD = "Payload"; + private static final String PCI_CHANGES_MAP_FILE_NAME = "pci-changes-from-policy-to-sdnr"; private static final String SLI_PARAMETERS = "sli_parameters"; private static final String RPC_NAME = "rpc-name"; private static final String BODY = "body"; private static final String INPUT = "input"; + + private static final String GENERIC_NEIGHBOR_CONFIGURATION_INPUT = "generic-neighbor-configuration-input."; + private static final String GENERIC_NEIGHBOR_CONFIGURATION_INPUT_NEIGHBOR_LIST_IN_USE = GENERIC_NEIGHBOR_CONFIGURATION_INPUT.concat("neighbor-list-in-use"); + private static final String MODIFY_CONFIG_ANR = "ModifyConfigANR"; + private static final String ANR_CHANGES_MAP_FILE_NAME = "anr-changes-from-policy-to-sdnr"; private String rootDir; protected VelocityEngine velocityEngine; - public ANRChangesFromPolicyToSDNRDmaapConsumer() { + public OofPciPocDmaapConsumers() { velocityEngine = new VelocityEngine(); Properties props = new Properties(); rootDir = System.getenv(DMAAPLISTENERROOT); @@ -87,15 +93,17 @@ public class ANRChangesFromPolicyToSDNRDmaapConsumer extends SdncDmaapConsumerIm /* * for testing purposes */ - ANRChangesFromPolicyToSDNRDmaapConsumer(Properties props) { + OofPciPocDmaapConsumers(Properties props) { velocityEngine = new VelocityEngine(); velocityEngine.init(props); } - protected String publish(String templatePath, String jsonString, JsonNode dataNode) throws IOException, InvalidMessageException + protected String publish(String templatePath, String jsonString, JsonNode configurationsOrDataNode, boolean invokePciChangesPublish, boolean invokeAnrChangesPublish) throws IOException, InvalidMessageException { - if (templatePath.contains("anr-pci-changes-from-policy-to-sdnr")){ - return publishANRChangesFromPolicyToSDNR(templatePath, dataNode); + if (invokePciChangesPublish){ + return publishPciChangesFromPolicyToSDNR(templatePath, configurationsOrDataNode); + } else if (invokeAnrChangesPublish){ + return publishANRChangesFromPolicyToSDNR(templatePath, configurationsOrDataNode); } else { return publishFullMessage(templatePath, jsonString); } @@ -121,17 +129,17 @@ public class ANRChangesFromPolicyToSDNRDmaapConsumer extends SdncDmaapConsumerIm context.put("full_message", rpcMsgbody); Writer writer = new StringWriter(); - velocityEngine.mergeTemplate(templatePath, "UTF-8", context, writer); + velocityEngine.mergeTemplate(templatePath, UTF_8, context, writer); writer.flush(); return writer.toString(); } - + private String publishANRChangesFromPolicyToSDNR(String templatePath, JsonNode dataNode) throws IOException, InvalidMessageException { VelocityContext context = new VelocityContext(); - - String RPC_NAME_KEY_IN_VT = "rpc_name"; + + String RPC_NAME_KEY_IN_VT = "rpc_name"; String RPC_NAME_VALUE_IN_VT = "generic-neighbor-configuration"; String CELL_CONFIG = "CellConfig"; @@ -181,7 +189,7 @@ public class ANRChangesFromPolicyToSDNRDmaapConsumer extends SdncDmaapConsumerIm context.put(RPC_NAME_KEY_IN_VT, RPC_NAME_VALUE_IN_VT); Writer writer = new StringWriter(); - velocityEngine.mergeTemplate(templatePath, "UTF-8", context, writer); + velocityEngine.mergeTemplate(templatePath, UTF_8, context, writer); writer.flush(); return writer.toString(); @@ -191,34 +199,101 @@ public class ANRChangesFromPolicyToSDNRDmaapConsumer extends SdncDmaapConsumerIm } } + + private String publishPciChangesFromPolicyToSDNR(String templatePath, JsonNode configurationsJsonNode) throws IOException, InvalidMessageException + { + String RPC_NAME_KEY_IN_VT = "rpc_name"; + String RPC_NAME_VALUE_IN_VT = "configuration-phy-cell-id"; + String ALIAS = "alias"; + String X0005b9Lte = "X0005b9Lte"; + + VelocityContext context = new VelocityContext(); + + JSONObject numberOfEntries = new JSONObject(); + JSONArray sliParametersArray = new JSONArray(); + + JsonNode configurations = configurationsJsonNode.get(CONFIGURATIONS); + + int entryCount = 0; + + if(configurations.isArray()) { + for(JsonNode dataNode:configurations) { + sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, PHYSICAL_CELL_ID_INPUT_FAP_SERVICE+"["+entryCount+"]."+ALIAS) + .put(STRING_VALUE, dataNode.get(DATA).get(FAP_SERVICE).get(ALIAS))); + sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, PHYSICAL_CELL_ID_INPUT_FAP_SERVICE+"["+entryCount+"]."+"cid") + .put(STRING_VALUE, dataNode.get(DATA).get(FAP_SERVICE).get("CellConfig").get("LTE").get("RAN").get("Common").get("CellIdentity"))); + sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, PHYSICAL_CELL_ID_INPUT_FAP_SERVICE+"["+entryCount+"]."+"phy-cell-id-in-use") + .put(STRING_VALUE, dataNode.get(DATA).get(FAP_SERVICE).get(X0005b9Lte).get("phyCellIdInUse"))); + sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, PHYSICAL_CELL_ID_INPUT_FAP_SERVICE+"["+entryCount+"]."+"pnf-name") + .put(STRING_VALUE, dataNode.get(DATA).get(FAP_SERVICE).get(X0005b9Lte).get("pnfName"))); + entryCount++; + } + + numberOfEntries.put(PARAMETER_NAME, PHYSICAL_CELL_ID_INPUT_FAP_SERVICE+"-number-of-entries"); + numberOfEntries.put(STRING_VALUE, entryCount); + + sliParametersArray.put(numberOfEntries); + + context.put(SLI_PARAMETERS, sliParametersArray); + + context.put(RPC_NAME_KEY_IN_VT, RPC_NAME_VALUE_IN_VT); + + Writer writer = new StringWriter(); + velocityEngine.mergeTemplate(templatePath, UTF_8, context, writer); + writer.flush(); + + return writer.toString(); + + }else { + throw new InvalidMessageException("Configurations is not of Type Array. Could not read configuration changes"); + } + + } @Override public void processMsg(String msg) throws InvalidMessageException { - if (msg == null) { + if (msg == null) { throw new InvalidMessageException("Null message"); } ObjectMapper oMapper = new ObjectMapper(); - JsonNode anrChangesRootNode; + JsonNode dmaapMessageRootNode; try { - anrChangesRootNode = oMapper.readTree(msg); + dmaapMessageRootNode = oMapper.readTree(msg); } catch (Exception e) { throw new InvalidMessageException("Cannot parse json object", e); } + - JsonNode rpcname = anrChangesRootNode.get(RPC_NAME); - if(rpcname == null) { - LOG.info("Missing rpc-name node."); + JsonNode rpcnameNode = dmaapMessageRootNode.get(RPC_NAME); + if(rpcnameNode == null) { + LOG.info("Unable to identify the respective consumer to invoke. Please verify the dmaap message.."); return; } - if(!MODIFY_CONFIG_ANR.toLowerCase().equals(rpcname.textValue())) { + String rpcname = rpcnameNode.textValue(); + + if(!MODIFY_CONFIG.toLowerCase().equals(rpcname) && !MODIFY_CONFIG_ANR.toLowerCase().equals(rpcname)) { LOG.info("Unknown rpc name {}", rpcname); return; } - JsonNode body = anrChangesRootNode.get(BODY); + if(MODIFY_CONFIG.toLowerCase().equals(rpcname)) { + invokePCIChangesConsumer(dmaapMessageRootNode, oMapper, msg); + return; + } + + if(MODIFY_CONFIG_ANR.toLowerCase().equals(rpcname)) { + invokeANRChangesConsumer(dmaapMessageRootNode, oMapper, msg); + return; + } + + } + + private void invokeANRChangesConsumer(JsonNode dmaapMessageRootNode, ObjectMapper oMapper, + String msg) throws InvalidMessageException { + JsonNode body = dmaapMessageRootNode.get(BODY); if(body == null) { LOG.info("Missing body node."); return; @@ -261,7 +336,7 @@ public class ANRChangesFromPolicyToSDNRDmaapConsumer extends SdncDmaapConsumerIm throw new InvalidMessageException("Cannot parse payload value", e); } - String mapFilename = rootDir + MAP_FILE_NAME + ".map"; + String mapFilename = rootDir + ANR_CHANGES_MAP_FILE_NAME + ".map"; Map<String, String> fieldMap = loadMap(mapFilename); if (fieldMap == null) { return; @@ -284,31 +359,117 @@ public class ANRChangesFromPolicyToSDNRDmaapConsumer extends SdncDmaapConsumerIm if(dataNode.get(DATA).get(FAP_SERVICE) == null) { LOG.info("Could not make a rpc call. Missing fapService node for dataNode element::", dataNode.textValue()); }else { - try { - - String rpcMsgbody = publish(templateName, msg, dataNode); - String odlUrlBase = getProperty("sdnc.odl.url-base"); - String odlUser = getProperty("sdnc.odl.user"); - String odlPassword = getProperty("sdnc.odl.password"); - - if ((odlUrlBase != null) && (odlUrlBase.length() > 0)) { - SdncOdlConnection conn = SdncOdlConnection.newInstance(odlUrlBase + "/" + sdncEndpoint, odlUser, odlPassword); - - conn.send("POST", "application/json", rpcMsgbody); - } else { - LOG.info("POST message body would be:\n" + rpcMsgbody); - } - } catch (Exception e) { - LOG.error("Unable to process message", e); - } + buildAndInvokeANRChangesRPC(sdncEndpoint, templateName,msg, dataNode); } } }else { throw new InvalidMessageException("Configurations is not of Type Array. Could not read configuration changes"); } - } + } + + private void invokePCIChangesConsumer(JsonNode dmaapMessageRootNode, ObjectMapper oMapper, + String msg) throws InvalidMessageException { + JsonNode body = dmaapMessageRootNode.get(BODY); + if(body == null) { + LOG.info("Missing body node."); + return; + } + + JsonNode input = body.get(INPUT); + if(input == null) { + LOG.info("Missing input node."); + return; + } + + JsonNode action = input.get(ACTION); + if(action == null) { + LOG.info("Missing action node."); + return; + } + + if(!MODIFY_CONFIG.equals(action.textValue())) { + LOG.info("Unknown Action {}", action); + return; + } + + JsonNode payload = input.get(PAYLOAD); + if(payload == null) { + LOG.info("Missing payload node."); + return; + } + + String configurations = payload.asText(); + + if(!configurations.contains(CONFIGURATIONS)) { + LOG.info("Missing configurations node."); + return; + } + + JsonNode configurationsJsonNode; + try { + configurationsJsonNode = oMapper.readTree(configurations); + } catch (Exception e) { + throw new InvalidMessageException("Cannot parse payload value", e); + } + + String mapFilename = rootDir + PCI_CHANGES_MAP_FILE_NAME + ".map"; + Map<String, String> fieldMap = loadMap(mapFilename); + if (fieldMap == null) { + return; + } + + if (!fieldMap.containsKey(SDNC_ENDPOINT)) { + return; + } + String sdncEndpoint = fieldMap.get(SDNC_ENDPOINT); + + if (!fieldMap.containsKey(TEMPLATE)) { + throw new InvalidMessageException("No SDNC template known for message "); + } + String templateName = fieldMap.get(TEMPLATE); + + buildAndInvokePCIChangesRPC(sdncEndpoint, templateName, msg, configurationsJsonNode); + } + + private void buildAndInvokePCIChangesRPC(String sdncEndpoint, String templateName, String msg, JsonNode configurationsOrDataNode) { + try { + String rpcMsgbody = publish(templateName, msg, configurationsOrDataNode, true, false); + String odlUrlBase = getProperty("sdnc.odl.url-base"); + String odlUser = getProperty("sdnc.odl.user"); + String odlPassword = getProperty("sdnc.odl.password"); + + if ((odlUrlBase != null) && (odlUrlBase.length() > 0)) { + SdncOdlConnection conn = SdncOdlConnection.newInstance(odlUrlBase + "/" + sdncEndpoint, odlUser, odlPassword); + + conn.send("POST", "application/json", rpcMsgbody); + } else { + LOG.info("POST message body would be:\n" + rpcMsgbody); + } + } catch (Exception e) { + LOG.error("Unable to process message", e); + } + } + + private void buildAndInvokeANRChangesRPC(String sdncEndpoint, String templateName, String msg, JsonNode configurationsOrDataNode) { + try { + String rpcMsgbody = publish(templateName, msg, configurationsOrDataNode, false, true); + String odlUrlBase = getProperty("sdnc.odl.url-base"); + String odlUser = getProperty("sdnc.odl.user"); + String odlPassword = getProperty("sdnc.odl.password"); + + if ((odlUrlBase != null) && (odlUrlBase.length() > 0)) { + SdncOdlConnection conn = SdncOdlConnection.newInstance(odlUrlBase + "/" + sdncEndpoint, odlUser, odlPassword); + + conn.send("POST", "application/json", rpcMsgbody); + } else { + LOG.info("POST message body would be:\n" + rpcMsgbody); + } + } catch (Exception e) { + LOG.error("Unable to process message", e); + } + } - private Map<String, String> loadMap(String mapFilename) { + private Map<String, String> loadMap(String mapFilename) { File mapFile = new File(mapFilename); if (!mapFile.canRead()) { diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/PciChangesFromPolicyToSDNRDmaapConsumer.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/PciChangesFromPolicyToSDNRDmaapConsumer.java deleted file mode 100644 index 8c44377f..00000000 --- a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/PciChangesFromPolicyToSDNRDmaapConsumer.java +++ /dev/null @@ -1,314 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.northbound.dmaapclient; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; -import java.time.Instant; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; -import org.apache.velocity.VelocityContext; -import org.apache.velocity.app.VelocityEngine; -import org.json.JSONArray; -import org.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class PciChangesFromPolicyToSDNRDmaapConsumer extends SdncDmaapConsumerImpl { - - private static final Logger LOG = LoggerFactory.getLogger(PciChangesFromPolicyToSDNRDmaapConsumer.class); - private static final String SDNC_ENDPOINT = "SDNC.endpoint"; - private static final String TEMPLATE = "SDNC.template"; - private static final String DMAAPLISTENERROOT = "DMAAPLISTENERROOT"; - - private static final String PARAMETER_NAME = "parameter-name"; - private static final String STRING_VALUE = "string-value"; - private static final String PHYSICAL_CELL_ID_INPUT_FAP_SERVICE = "configuration-phy-cell-id-input.fap-service"; - private static final String EVENT_HEADER = "event-header"; - private static final String ACTION = "Action"; - private static final String PAYLOAD = "Payload"; - private static final String CONFIGURATIONS = "Configurations"; - private static final String MODIFY_CONFIG = "ModifyConfig"; - private static final String MAP_FILE_NAME = "pci-changes-from-policy-to-sdnr"; - private static final String DATA = "data"; - private static final String FAP_SERVICE = "FAPService"; - private static final String SLI_PARAMETERS = "sli_parameters"; - private static final String RPC_NAME = "rpc-name"; - private static final String BODY = "body"; - private static final String INPUT = "input"; - - private String rootDir; - - protected VelocityEngine velocityEngine; - - public PciChangesFromPolicyToSDNRDmaapConsumer() { - velocityEngine = new VelocityEngine(); - Properties props = new Properties(); - rootDir = System.getenv(DMAAPLISTENERROOT); - - if ((rootDir == null) || (rootDir.length() == 0)) { - rootDir = "/opt/app/dmaap-listener/lib/"; - } - else { - rootDir = rootDir + "/lib/"; - } - - props.put("file.resource.loader.path", rootDir); - velocityEngine.init(props); - } - - /* - * for testing purposes - */ - PciChangesFromPolicyToSDNRDmaapConsumer(Properties props) { - velocityEngine = new VelocityEngine(); - velocityEngine.init(props); - } - - protected String publish(String templatePath, String jsonString, JsonNode configurationsJsonNode) throws IOException, InvalidMessageException - { - if (templatePath.contains("anr-pci-changes-from-policy-to-sdnr")){ - return publishPciChangesFromPolicyToSDNR(templatePath, configurationsJsonNode); - } else { - return publishFullMessage(templatePath, jsonString); - } - } - - private String publishFullMessage(String templatePath, String jsonString) throws IOException - { - JSONObject jsonObj = new JSONObject(jsonString); - VelocityContext context = new VelocityContext(); - for(Object key : jsonObj.keySet()) - { - context.put((String)key, jsonObj.get((String)key)); - } - - String id = jsonObj.getJSONObject(EVENT_HEADER).get("id").toString(); - context.put("req_id", id); - - context.put("curr_time", Instant.now()); - - ObjectMapper oMapper = new ObjectMapper(); - - String rpcMsgbody = oMapper.writeValueAsString(jsonString); - context.put("full_message", rpcMsgbody); - - Writer writer = new StringWriter(); - velocityEngine.mergeTemplate(templatePath, "UTF-8", context, writer); - writer.flush(); - - return writer.toString(); - } - - private String publishPciChangesFromPolicyToSDNR(String templatePath, JsonNode configurationsJsonNode) throws IOException, InvalidMessageException - { - String RPC_NAME_KEY_IN_VT = "rpc_name"; - String RPC_NAME_VALUE_IN_VT = "configuration-phy-cell-id"; - String ALIAS = "alias"; - String X0005b9Lte = "X0005b9Lte"; - - VelocityContext context = new VelocityContext(); - - JSONObject numberOfEntries = new JSONObject(); - JSONArray sliParametersArray = new JSONArray(); - - JsonNode configurations = configurationsJsonNode.get(CONFIGURATIONS); - - int entryCount = 0; - - if(configurations.isArray()) { - for(JsonNode dataNode:configurations) { - sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, PHYSICAL_CELL_ID_INPUT_FAP_SERVICE+"["+entryCount+"]."+ALIAS) - .put(STRING_VALUE, dataNode.get(DATA).get(FAP_SERVICE).get(ALIAS))); - sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, PHYSICAL_CELL_ID_INPUT_FAP_SERVICE+"["+entryCount+"]."+"cid") - .put(STRING_VALUE, dataNode.get(DATA).get(FAP_SERVICE).get("CellConfig").get("LTE").get("RAN").get("Common").get("CellIdentity"))); - sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, PHYSICAL_CELL_ID_INPUT_FAP_SERVICE+"["+entryCount+"]."+"phy-cell-id-in-use") - .put(STRING_VALUE, dataNode.get(DATA).get(FAP_SERVICE).get(X0005b9Lte).get("phyCellIdInUse"))); - sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, PHYSICAL_CELL_ID_INPUT_FAP_SERVICE+"["+entryCount+"]."+"pnf-name") - .put(STRING_VALUE, dataNode.get(DATA).get(FAP_SERVICE).get(X0005b9Lte).get("pnfName"))); - entryCount++; - } - - numberOfEntries.put(PARAMETER_NAME, PHYSICAL_CELL_ID_INPUT_FAP_SERVICE+"-number-of-entries"); - numberOfEntries.put(STRING_VALUE, entryCount); - - sliParametersArray.put(numberOfEntries); - - context.put(SLI_PARAMETERS, sliParametersArray); - - context.put(RPC_NAME_KEY_IN_VT, RPC_NAME_VALUE_IN_VT); - - Writer writer = new StringWriter(); - velocityEngine.mergeTemplate(templatePath, "UTF-8", context, writer); - writer.flush(); - - return writer.toString(); - - }else { - throw new InvalidMessageException("Configurations is not of Type Array. Could not read configuration changes"); - } - - } - - @Override - public void processMsg(String msg) throws InvalidMessageException { - - if (msg == null) { - throw new InvalidMessageException("Null message"); - } - - ObjectMapper oMapper = new ObjectMapper(); - JsonNode pciChangesRootNode; - try { - pciChangesRootNode = oMapper.readTree(msg); - } catch (Exception e) { - throw new InvalidMessageException("Cannot parse json object", e); - } - - JsonNode rpcname = pciChangesRootNode.get(RPC_NAME); - if(rpcname == null) { - LOG.info("Missing rpc-name node."); - return; - } - - if(!MODIFY_CONFIG.toLowerCase().equals(rpcname.textValue())) { - LOG.info("Unknown rpc name {}", rpcname); - return; - } - - JsonNode body = pciChangesRootNode.get(BODY); - if(body == null) { - LOG.info("Missing body node."); - return; - } - - JsonNode input = body.get(INPUT); - if(input == null) { - LOG.info("Missing input node."); - return; - } - - JsonNode action = input.get(ACTION); - if(action == null) { - LOG.info("Missing action node."); - return; - } - - if(!MODIFY_CONFIG.equals(action.textValue())) { - LOG.info("Unknown Action {}", action); - return; - } - - JsonNode payload = input.get(PAYLOAD); - if(payload == null) { - LOG.info("Missing payload node."); - return; - } - - String configurations = payload.asText(); - - if(!configurations.contains(CONFIGURATIONS)) { - LOG.info("Missing configurations node."); - return; - } - - JsonNode configurationsJsonNode; - try { - configurationsJsonNode = oMapper.readTree(configurations); - } catch (Exception e) { - throw new InvalidMessageException("Cannot parse payload value", e); - } - - String mapFilename = rootDir + MAP_FILE_NAME + ".map"; - Map<String, String> fieldMap = loadMap(mapFilename); - if (fieldMap == null) { - return; - } - - if (!fieldMap.containsKey(SDNC_ENDPOINT)) { - return; - } - String sdncEndpoint = fieldMap.get(SDNC_ENDPOINT); - - if (!fieldMap.containsKey(TEMPLATE)) { - throw new InvalidMessageException("No SDNC template known for message "); - } - String templateName = fieldMap.get(TEMPLATE); - - try { - String rpcMsgbody = publish(templateName, msg, configurationsJsonNode); - String odlUrlBase = getProperty("sdnc.odl.url-base"); - String odlUser = getProperty("sdnc.odl.user"); - String odlPassword = getProperty("sdnc.odl.password"); - - if ((odlUrlBase != null) && (odlUrlBase.length() > 0)) { - SdncOdlConnection conn = SdncOdlConnection.newInstance(odlUrlBase + "/" + sdncEndpoint, odlUser, odlPassword); - - conn.send("POST", "application/json", rpcMsgbody); - } else { - LOG.info("POST message body would be:\n" + rpcMsgbody); - } - } catch (Exception e) { - LOG.error("Unable to process message", e); - } - } - - private Map<String, String> loadMap(String mapFilename) { - File mapFile = new File(mapFilename); - - if (!mapFile.canRead()) { - LOG.error(String.format("Cannot read map file (%s)", mapFilename)); - return null; - } - - Map<String, String> results = new HashMap<>(); - try (BufferedReader mapReader = new BufferedReader(new FileReader(mapFile))) { - - String curLine; - - while ((curLine = mapReader.readLine()) != null) { - curLine = curLine.trim(); - - if ((curLine.length() > 0) && (!curLine.startsWith("#")) && curLine.contains("=>")) { - String[] entry = curLine.split("=>"); - if (entry.length == 2) { - results.put(entry[0].trim(), entry[1].trim()); - } - } - } - mapReader.close(); - } catch (Exception e) { - LOG.error("Caught exception reading map " + mapFilename, e); - return null; - } - - return results; - } - -} diff --git a/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestANRChangesFromPolicyToSDNRDmaapConsumer.java b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestANRChangesFromPolicyToSDNRDmaapConsumer.java deleted file mode 100644 index 66b63a17..00000000 --- a/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestANRChangesFromPolicyToSDNRDmaapConsumer.java +++ /dev/null @@ -1,142 +0,0 @@ -package org.onap.ccsdk.sli.northbound.dmaapclient; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.Properties; - -import org.junit.Before; -import org.junit.Test; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class TestANRChangesFromPolicyToSDNRDmaapConsumer { - private static final String anrChangesFromPolicyToSDNRInput = "{\n" + - " \"body\": {\n" + - " \"input\": {\n" + - " \"CommonHeader\": {\n" + - " \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" + - " \"APIVer\": \"1.0\",\n" + - " \"RequestID\": \"722ee65a-8afd-48df-bf57-c152ae45bacc\",\n" + - " \"SubRequestID\": \"1\",\n" + - " \"RequestTrack\": {},\n" + - " \"Flags\": {}\n" + - " },\n" + - "\"Action\": \"ModifyConfigANR\",\n" + - " \"Payload\": \"{ \\\"Configurations\\\":[ { \\\"data\\\":{ \\\"FAPService\\\":{ \\\"alias\\\":\\\"Cell1\\\", \\\"CellConfig\\\":{ \\\"LTE\\\":{ \\\"RAN\\\":{ \\\"Common\\\":{ \\\"CellIdentity\\\":\\\"1\\\" }, \\\"NeighborListInUse\\\" : { \\\"LTECellNumberOfEntries\\\" : \\\"1\\\" , \\\"LTECell\\\" : [{ \\\"PLMNID\\\" :\\\"plmnid1\\\", \\\"CID\\\":\\\"Chn0001\\\", \\\"PhyCellID\\\":\\\"3\\\", \\\"PNFName\\\":\\\"ncserver01\\\", \\\"Blacklisted\\\":\\\"false\\\"}] } } } } } } } ] }\"\n" + - " }\n" + - " },\n" + - " \"version\": \"1.0\",\n" + - " \"rpc-name\": \"modifyconfiganr\",\n" + - " \"correlation-id\": \"722ee65a-8afd-48df-bf57-c152ae45bacc-1\",\n" + - " \"type\": \"request\"\n" + - "}\n" + - ""; - - @Before - public void setUp() throws Exception { - } - - @Test - public void testRPCMessageBodyResponse() throws Exception { - Properties props = new Properties(); - - ObjectMapper oMapper = new ObjectMapper(); - JsonNode anrChangesRootNode = oMapper.readTree(anrChangesFromPolicyToSDNRInput); - JsonNode body = anrChangesRootNode.get("body"); - JsonNode input = body.get("input"); - JsonNode payload = input.get("Payload"); - String payloadText = payload.asText(); - JsonNode configurationsJsonNode = oMapper.readTree(payloadText); - JsonNode configurations = configurationsJsonNode.get("Configurations"); - - for(JsonNode dataNode:configurations) { - String rpcMsgbody = new ANRChangesFromPolicyToSDNRDmaapConsumer(props).publish("src/main/resources/anr-pci-changes-from-policy-to-sdnr.vt", anrChangesFromPolicyToSDNRInput,dataNode); - - JsonNode rootNode; - try { - rootNode = oMapper.readTree(rpcMsgbody); - } catch (Exception e) { - throw new InvalidMessageException("Cannot parse json object", e); - } - - assertTrue(rootNode.get("input").get("module-name") != null); - assertTrue(rootNode.get("input").get("rpc-name") != null); - assertTrue(rootNode.get("input").get("mode") != null); - assertTrue(rootNode.get("input").get("sli-parameter") != null); - } - } - - @Test(expected = InvalidMessageException.class) - public void testProcessMsgNullMessage() throws Exception { - ANRChangesFromPolicyToSDNRDmaapConsumer consumer = new ANRChangesFromPolicyToSDNRDmaapConsumer(); - consumer.processMsg(null); - } - - @Test(expected = InvalidMessageException.class) - public void testProcessMsgInvalidMessage() throws Exception { - ANRChangesFromPolicyToSDNRDmaapConsumer consumer = new ANRChangesFromPolicyToSDNRDmaapConsumer(); - consumer.processMsg("test"); - } - - @Test - public void testProcessMsgMissingActionHeader() throws Exception { - ANRChangesFromPolicyToSDNRDmaapConsumer consumer = new ANRChangesFromPolicyToSDNRDmaapConsumer(); - consumer.processMsg("{\n" + - " \"body\": {\n" + - " \"input\": {\n" + - " \"CommonHeader\": {\n" + - " \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" + - " \"APIVer\": \"1.0\",\n" + - " \"RequestID\": \"722ee65a-8afd-48df-bf57-c152ae45bacc\",\n" + - " \"SubRequestID\": \"1\",\n" + - " \"RequestTrack\": {},\n" + - " \"Flags\": {}\n" + - " },\n" + - "\"NoAction\": \"ModifyConfigANR\",\n" + - " \"Payload\": \"{ \\\"Configurations\\\":[ { \\\"data\\\":{ \\\"FAPService\\\":{ \\\"alias\\\":\\\"Cell1\\\", \\\"CellConfig\\\":{ \\\"LTE\\\":{ \\\"RAN\\\":{ \\\"Common\\\":{ \\\"CellIdentity\\\":\\\"1\\\" }, \\\"NeighborListInUse\\\" : { \\\"LTECellNumberOfEntries\\\" : \\\"1\\\" , \\\"LTECell\\\" : [{ \\\"PLMNID\\\" :\\\"plmnid1\\\", \\\"CID\\\":\\\"Chn0001\\\", \\\"PhyCellID\\\":\\\"3\\\", \\\"PNFName\\\":\\\"ncserver01\\\", \\\"Blacklisted\\\":\\\"false\\\"}] } } } } } } } ] }\"\n" + - " }\n" + - " },\n" + - " \"version\": \"1.0\",\n" + - " \"rpc-name\": \"modifyconfiganr\",\n" + - " \"correlation-id\": \"722ee65a-8afd-48df-bf57-c152ae45bacc-1\",\n" + - " \"type\": \"request\"\n" + - "}\n" + - ""); - } - - @Test - public void testProcessMsgInvalidPayloadConfigurations() throws Exception { - String msg = "{\n" + - " \"body\": {\n" + - " \"input\": {\n" + - " \"CommonHeader\": {\n" + - " \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" + - " \"APIVer\": \"1.0\",\n" + - " \"RequestID\": \"722ee65a-8afd-48df-bf57-c152ae45bacc\",\n" + - " \"SubRequestID\": \"1\",\n" + - " \"RequestTrack\": {},\n" + - " \"Flags\": {}\n" + - " },\n" + - "\"Action\": \"ModifyConfigANR\",\n" + - " \"Payload\": \"{ \\\"Configurations\\\":{ { \\\"data\\\":{ \\\"FAPService\\\":{ \\\"alias\\\":\\\"Cell1\\\", \\\"CellConfig\\\":{ \\\"LTE\\\":{ \\\"RAN\\\":{ \\\"Common\\\":{ \\\"CellIdentity\\\":\\\"1\\\" }, \\\"NeighborListInUse\\\" : { \\\"LTECellNumberOfEntries\\\" : \\\"1\\\" , \\\"LTECell\\\" : [{ \\\"PLMNID\\\" :\\\"plmnid1\\\", \\\"CID\\\":\\\"Chn0001\\\", \\\"PhyCellID\\\":\\\"3\\\", \\\"PNFName\\\":\\\"ncserver01\\\", \\\"Blacklisted\\\":\\\"false\\\"}} } } } } } } } ] }\"\n" + - " }\n" + - " },\n" + - " \"version\": \"1.0\",\n" + - " \"rpc-name\": \"modifyconfiganr\",\n" + - " \"correlation-id\": \"722ee65a-8afd-48df-bf57-c152ae45bacc-1\",\n" + - " \"type\": \"request\"\n" + - "}\n" + - ""; - - try { - ANRChangesFromPolicyToSDNRDmaapConsumer consumer = new ANRChangesFromPolicyToSDNRDmaapConsumer(); - consumer.processMsg(msg); - - } catch (final InvalidMessageException e) { - final String errorMsg = "Cannot parse payload value"; - assertEquals(errorMsg, e.getMessage()); - } - } -} diff --git a/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestOofPciPocDmaapConsumers.java b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestOofPciPocDmaapConsumers.java new file mode 100644 index 00000000..cd2ea6eb --- /dev/null +++ b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestOofPciPocDmaapConsumers.java @@ -0,0 +1,314 @@ +package org.onap.ccsdk.sli.northbound.dmaapclient; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.Properties; + +import org.junit.Before; +import org.junit.Test; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class TestOofPciPocDmaapConsumers { + + private static final String pciChangesFromPolicyToSDNRInput = "{\n" + + " \"body\": {\n" + + " \"input\": {\n" + + " \"CommonHeader\": {\n" + + " \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" + + " \"APIVer\": \"1.0\",\n" + + " \"RequestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" + + " \"SubRequestID\": \"1\",\n" + + " \"RequestTrack\": {},\n" + + " \"Flags\": {}\n" + + " },\n" + + " \"Action\": \"ModifyConfig\",\n" + + " \"Payload\": \"{\\\"Configurations\\\":[{\\\"data\\\":{\\\"FAPService\\\":{\\\"alias\\\":\\\"Chn0330\\\",\\\"X0005b9Lte\\\":{\\\"phyCellIdInUse\\\":6,\\\"pnfName\\\":\\\"ncserver23\\\"},\\\"CellConfig\\\":{\\\"LTE\\\":{\\\"RAN\\\":{\\\"Common\\\":{\\\"CellIdentity\\\":\\\"Chn0330\\\"}}}}}}},{\\\"data\\\":{\\\"FAPService\\\":{\\\"alias\\\":\\\"Chn0331\\\",\\\"X0005b9Lte\\\":{\\\"phyCellIdInUse\\\":7,\\\"pnfName\\\":\\\"ncserver23\\\"},\\\"CellConfig\\\":{\\\"LTE\\\":{\\\"RAN\\\":{\\\"Common\\\":{\\\"CellIdentity\\\":\\\"Chn0331\\\"}}}}}}}]}\"\n" + + " }\n" + + " },\n" + + " \"version\": \"1.0\",\n" + + " \"rpc-name\": \"modifyconfig\",\n" + + " \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" + + " \"type\": \"request\"\n" + + "}"; + + private static final String anrChangesFromPolicyToSDNRInput = "{\n" + + " \"body\": {\n" + + " \"input\": {\n" + + " \"CommonHeader\": {\n" + + " \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" + + " \"APIVer\": \"1.0\",\n" + + " \"RequestID\": \"722ee65a-8afd-48df-bf57-c152ae45bacc\",\n" + + " \"SubRequestID\": \"1\",\n" + + " \"RequestTrack\": {},\n" + + " \"Flags\": {}\n" + + " },\n" + + "\"Action\": \"ModifyConfigANR\",\n" + + " \"Payload\": \"{ \\\"Configurations\\\":[ { \\\"data\\\":{ \\\"FAPService\\\":{ \\\"alias\\\":\\\"Cell1\\\", \\\"CellConfig\\\":{ \\\"LTE\\\":{ \\\"RAN\\\":{ \\\"Common\\\":{ \\\"CellIdentity\\\":\\\"1\\\" }, \\\"NeighborListInUse\\\" : { \\\"LTECellNumberOfEntries\\\" : \\\"1\\\" , \\\"LTECell\\\" : [{ \\\"PLMNID\\\" :\\\"plmnid1\\\", \\\"CID\\\":\\\"Chn0001\\\", \\\"PhyCellID\\\":\\\"3\\\", \\\"PNFName\\\":\\\"ncserver01\\\", \\\"Blacklisted\\\":\\\"false\\\"}] } } } } } } } ] }\"\n" + + " }\n" + + " },\n" + + " \"version\": \"1.0\",\n" + + " \"rpc-name\": \"modifyconfiganr\",\n" + + " \"correlation-id\": \"722ee65a-8afd-48df-bf57-c152ae45bacc-1\",\n" + + " \"type\": \"request\"\n" + + "}\n" + + ""; + + @Before + public void setUp() throws Exception { + } + + /* ---------- PCI Changes DMAAP messages test cases ------------------- */ + + @Test + public void testPCIChangesDmaapRPCMessageBodyResponse() throws Exception { + Properties props = new Properties(); + + ObjectMapper oMapper = new ObjectMapper(); + JsonNode pciChangesRootNode = oMapper.readTree(pciChangesFromPolicyToSDNRInput); + JsonNode body = pciChangesRootNode.get("body"); + JsonNode input = body.get("input"); + JsonNode payload = input.get("Payload"); + String payloadText = payload.asText(); + JsonNode configurationsJsonNode = oMapper.readTree(payloadText); + + String rpcMsgbody = new OofPciPocDmaapConsumers(props).publish("src/main/resources/anr-pci-changes-from-policy-to-sdnr.vt", pciChangesFromPolicyToSDNRInput,configurationsJsonNode, true, false); + + JsonNode rootNode; + try { + rootNode = oMapper.readTree(rpcMsgbody); + } catch (Exception e) { + throw new InvalidMessageException("Cannot parse json object", e); + } + + assertTrue(rootNode.get("input").get("module-name") != null); + assertTrue(rootNode.get("input").get("rpc-name") != null); + assertTrue(rootNode.get("input").get("mode") != null); + assertTrue(rootNode.get("input").get("sli-parameter") != null); + + } + + @Test(expected = InvalidMessageException.class) + public void testPCIChangesDmaapProcessMsgNullMessage() throws Exception { + OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers(); + consumer.processMsg(null); + } + + @Test(expected = InvalidMessageException.class) + public void testPCIChangesDmaapProcessMsgInvalidMessage() throws Exception { + OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers(); + consumer.processMsg("test"); + } + + @Test + public void testPCIChangesDmaapProcessMsgMissingActionHeader() throws Exception { + OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers(); + consumer.processMsg("{\n" + + " \"body\": {\n" + + " \"input\": {\n" + + " \"CommonHeader\": {\n" + + " \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" + + " \"APIVer\": \"1.0\",\n" + + " \"RequestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" + + " \"SubRequestID\": \"1\",\n" + + " \"RequestTrack\": {},\n" + + " \"Flags\": {}\n" + + " },\n" + + " \"RenamedAction\": \"ModifyConfig\",\n" + + " \"Payload\": {\n" + + " \"Configurations \": {\n" + + " \"data \": {\n" + + " \"FAPService \": {\n" + + " \"alias\": \"Chn0330\",\n" + + " \"X0005b9Lte\": {\n" + + " \"phyCellIdInUse\": 6,\n" + + " \"pnfName\": \"ncserver23\"\n" + + " },\n" + + " \"CellConfig\": {\n" + + " \"LTE\": {\n" + + " \"RAN\": {\n" + + " \"Common\": {\n" + + " \"CellIdentity\": \"Chn0330\"\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " }\n" + + " }\n" + + " },\n" + + " \"version\": \"1.0\",\n" + + " \"rpc-name\": \"modifyconfig\",\n" + + " \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" + + " \"type\": \"request\"\n" + + "}"); + } + + @Test + public void testPCIChangesDmaapProcessMsgInvalidPayloadConfigurations() throws Exception { + String msg = "{\n" + + " \"body\": {\n" + + " \"input\": {\n" + + " \"CommonHeader\": {\n" + + " \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" + + " \"APIVer\": \"1.0\",\n" + + " \"RequestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" + + " \"SubRequestID\": \"1\",\n" + + " \"RequestTrack\": {},\n" + + " \"Flags\": {}\n" + + " },\n" + + " \"Action\": \"ModifyConfig\",\n" + + " \"Payload\": {\n" + + " \"Configurations \": {\n" + + " \"data \": {\n" + + " \"FAPService \": {\n" + + " \"alias\": \"Chn0330\",\n" + + " \"X0005b9Lte\": {\n" + + " \"phyCellIdInUse\": 6,\n" + + " \"pnfName\": \"ncserver23\"\n" + + " },\n" + + " \"CellConfig\": {\n" + + " \"LTE\": {\n" + + " \"RAN\": {\n" + + " \"Common\": {\n" + + " \"CellIdentity\": \"Chn0330\"\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " }\n" + + " }\n" + + " },\n" + + " \"version\": \"1.0\",\n" + + " \"rpc-name\": \"modifyconfig\",\n" + + " \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" + + " \"type\": \"request\"\n" + + "}"; + + try { + OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers(); + consumer.processMsg(msg); + + } catch (final InvalidMessageException e) { + final String errorMsg = "Configurations is not of Type Array. Could not read configuration changes"; + assertEquals(errorMsg, e.getMessage()); + } + } + + /* ---------- PCI Changes DMAAP messages test cases ------------------- */ + + /* ---------- ANR Changes DMAAP messages test cases ------------------- */ + + @Test + public void testANRChangesDmaapRPCMessageBodyResponse() throws Exception { + Properties props = new Properties(); + + ObjectMapper oMapper = new ObjectMapper(); + JsonNode anrChangesRootNode = oMapper.readTree(anrChangesFromPolicyToSDNRInput); + JsonNode body = anrChangesRootNode.get("body"); + JsonNode input = body.get("input"); + JsonNode payload = input.get("Payload"); + String payloadText = payload.asText(); + JsonNode configurationsJsonNode = oMapper.readTree(payloadText); + JsonNode configurations = configurationsJsonNode.get("Configurations"); + + for(JsonNode dataNode:configurations) { + String rpcMsgbody = new OofPciPocDmaapConsumers(props).publish("src/main/resources/anr-pci-changes-from-policy-to-sdnr.vt", anrChangesFromPolicyToSDNRInput,dataNode, false, true); + + JsonNode rootNode; + try { + rootNode = oMapper.readTree(rpcMsgbody); + } catch (Exception e) { + throw new InvalidMessageException("Cannot parse json object", e); + } + + assertTrue(rootNode.get("input").get("module-name") != null); + assertTrue(rootNode.get("input").get("rpc-name") != null); + assertTrue(rootNode.get("input").get("mode") != null); + assertTrue(rootNode.get("input").get("sli-parameter") != null); + } + } + + @Test(expected = InvalidMessageException.class) + public void testANRChangesDmaapProcessMsgNullMessage() throws Exception { + OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers(); + consumer.processMsg(null); + } + + @Test(expected = InvalidMessageException.class) + public void testANRChangesDmaapProcessMsgInvalidMessage() throws Exception { + OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers(); + consumer.processMsg("test"); + } + + @Test + public void testANRChangesDmaapProcessMsgMissingActionHeader() throws Exception { + OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers(); + consumer.processMsg("{\n" + + " \"body\": {\n" + + " \"input\": {\n" + + " \"CommonHeader\": {\n" + + " \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" + + " \"APIVer\": \"1.0\",\n" + + " \"RequestID\": \"722ee65a-8afd-48df-bf57-c152ae45bacc\",\n" + + " \"SubRequestID\": \"1\",\n" + + " \"RequestTrack\": {},\n" + + " \"Flags\": {}\n" + + " },\n" + + "\"NoAction\": \"ModifyConfigANR\",\n" + + " \"Payload\": \"{ \\\"Configurations\\\":[ { \\\"data\\\":{ \\\"FAPService\\\":{ \\\"alias\\\":\\\"Cell1\\\", \\\"CellConfig\\\":{ \\\"LTE\\\":{ \\\"RAN\\\":{ \\\"Common\\\":{ \\\"CellIdentity\\\":\\\"1\\\" }, \\\"NeighborListInUse\\\" : { \\\"LTECellNumberOfEntries\\\" : \\\"1\\\" , \\\"LTECell\\\" : [{ \\\"PLMNID\\\" :\\\"plmnid1\\\", \\\"CID\\\":\\\"Chn0001\\\", \\\"PhyCellID\\\":\\\"3\\\", \\\"PNFName\\\":\\\"ncserver01\\\", \\\"Blacklisted\\\":\\\"false\\\"}] } } } } } } } ] }\"\n" + + " }\n" + + " },\n" + + " \"version\": \"1.0\",\n" + + " \"rpc-name\": \"modifyconfiganr\",\n" + + " \"correlation-id\": \"722ee65a-8afd-48df-bf57-c152ae45bacc-1\",\n" + + " \"type\": \"request\"\n" + + "}\n" + + ""); + } + + @Test + public void testANRChangesDmaapProcessMsgInvalidPayloadConfigurations() throws Exception { + String msg = "{\n" + + " \"body\": {\n" + + " \"input\": {\n" + + " \"CommonHeader\": {\n" + + " \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" + + " \"APIVer\": \"1.0\",\n" + + " \"RequestID\": \"722ee65a-8afd-48df-bf57-c152ae45bacc\",\n" + + " \"SubRequestID\": \"1\",\n" + + " \"RequestTrack\": {},\n" + + " \"Flags\": {}\n" + + " },\n" + + "\"Action\": \"ModifyConfigANR\",\n" + + " \"Payload\": \"{ \\\"Configurations\\\":{ { \\\"data\\\":{ \\\"FAPService\\\":{ \\\"alias\\\":\\\"Cell1\\\", \\\"CellConfig\\\":{ \\\"LTE\\\":{ \\\"RAN\\\":{ \\\"Common\\\":{ \\\"CellIdentity\\\":\\\"1\\\" }, \\\"NeighborListInUse\\\" : { \\\"LTECellNumberOfEntries\\\" : \\\"1\\\" , \\\"LTECell\\\" : [{ \\\"PLMNID\\\" :\\\"plmnid1\\\", \\\"CID\\\":\\\"Chn0001\\\", \\\"PhyCellID\\\":\\\"3\\\", \\\"PNFName\\\":\\\"ncserver01\\\", \\\"Blacklisted\\\":\\\"false\\\"}} } } } } } } } ] }\"\n" + + " }\n" + + " },\n" + + " \"version\": \"1.0\",\n" + + " \"rpc-name\": \"modifyconfiganr\",\n" + + " \"correlation-id\": \"722ee65a-8afd-48df-bf57-c152ae45bacc-1\",\n" + + " \"type\": \"request\"\n" + + "}\n" + + ""; + + try { + OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers(); + consumer.processMsg(msg); + + } catch (final InvalidMessageException e) { + final String errorMsg = "Cannot parse payload value"; + assertEquals(errorMsg, e.getMessage()); + } + } + + /* ---------- ANR Changes DMAAP messages test cases ------------------- */ +} diff --git a/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestPciChangesFromPolicyToSDNRDmaapConsumer.java b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestPciChangesFromPolicyToSDNRDmaapConsumer.java deleted file mode 100644 index a42bc48f..00000000 --- a/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestPciChangesFromPolicyToSDNRDmaapConsumer.java +++ /dev/null @@ -1,181 +0,0 @@ -package org.onap.ccsdk.sli.northbound.dmaapclient; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.Properties; - -import org.junit.Before; -import org.junit.Test; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class TestPciChangesFromPolicyToSDNRDmaapConsumer { - private static final String pciChangesFromPolicyToSDNRInput = "{\n" + - " \"body\": {\n" + - " \"input\": {\n" + - " \"CommonHeader\": {\n" + - " \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" + - " \"APIVer\": \"1.0\",\n" + - " \"RequestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" + - " \"SubRequestID\": \"1\",\n" + - " \"RequestTrack\": {},\n" + - " \"Flags\": {}\n" + - " },\n" + - " \"Action\": \"ModifyConfig\",\n" + - " \"Payload\": \"{\\\"Configurations\\\":[{\\\"data\\\":{\\\"FAPService\\\":{\\\"alias\\\":\\\"Chn0330\\\",\\\"X0005b9Lte\\\":{\\\"phyCellIdInUse\\\":6,\\\"pnfName\\\":\\\"ncserver23\\\"},\\\"CellConfig\\\":{\\\"LTE\\\":{\\\"RAN\\\":{\\\"Common\\\":{\\\"CellIdentity\\\":\\\"Chn0330\\\"}}}}}}},{\\\"data\\\":{\\\"FAPService\\\":{\\\"alias\\\":\\\"Chn0331\\\",\\\"X0005b9Lte\\\":{\\\"phyCellIdInUse\\\":7,\\\"pnfName\\\":\\\"ncserver23\\\"},\\\"CellConfig\\\":{\\\"LTE\\\":{\\\"RAN\\\":{\\\"Common\\\":{\\\"CellIdentity\\\":\\\"Chn0331\\\"}}}}}}}]}\"\n" + - " }\n" + - " },\n" + - " \"version\": \"1.0\",\n" + - " \"rpc-name\": \"modifyconfig\",\n" + - " \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" + - " \"type\": \"request\"\n" + - "}"; - - @Before - public void setUp() throws Exception { - } - - @Test - public void testRPCMessageBodyResponse() throws Exception { - Properties props = new Properties(); - - ObjectMapper oMapper = new ObjectMapper(); - JsonNode pciChangesRootNode = oMapper.readTree(pciChangesFromPolicyToSDNRInput); - JsonNode body = pciChangesRootNode.get("body"); - JsonNode input = body.get("input"); - JsonNode payload = input.get("Payload"); - String payloadText = payload.asText(); - JsonNode configurationsJsonNode = oMapper.readTree(payloadText); - - String rpcMsgbody = new PciChangesFromPolicyToSDNRDmaapConsumer(props).publish("src/main/resources/anr-pci-changes-from-policy-to-sdnr.vt", pciChangesFromPolicyToSDNRInput,configurationsJsonNode); - - JsonNode rootNode; - try { - rootNode = oMapper.readTree(rpcMsgbody); - } catch (Exception e) { - throw new InvalidMessageException("Cannot parse json object", e); - } - - assertTrue(rootNode.get("input").get("module-name") != null); - assertTrue(rootNode.get("input").get("rpc-name") != null); - assertTrue(rootNode.get("input").get("mode") != null); - assertTrue(rootNode.get("input").get("sli-parameter") != null); - - } - - @Test(expected = InvalidMessageException.class) - public void testProcessMsgNullMessage() throws Exception { - PciChangesFromPolicyToSDNRDmaapConsumer consumer = new PciChangesFromPolicyToSDNRDmaapConsumer(); - consumer.processMsg(null); - } - - @Test(expected = InvalidMessageException.class) - public void testProcessMsgInvalidMessage() throws Exception { - PciChangesFromPolicyToSDNRDmaapConsumer consumer = new PciChangesFromPolicyToSDNRDmaapConsumer(); - consumer.processMsg("test"); - } - - @Test - public void testProcessMsgMissingActionHeader() throws Exception { - PciChangesFromPolicyToSDNRDmaapConsumer consumer = new PciChangesFromPolicyToSDNRDmaapConsumer(); - consumer.processMsg("{\n" + - " \"body\": {\n" + - " \"input\": {\n" + - " \"CommonHeader\": {\n" + - " \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" + - " \"APIVer\": \"1.0\",\n" + - " \"RequestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" + - " \"SubRequestID\": \"1\",\n" + - " \"RequestTrack\": {},\n" + - " \"Flags\": {}\n" + - " },\n" + - " \"RenamedAction\": \"ModifyConfig\",\n" + - " \"Payload\": {\n" + - " \"Configurations \": {\n" + - " \"data \": {\n" + - " \"FAPService \": {\n" + - " \"alias\": \"Chn0330\",\n" + - " \"X0005b9Lte\": {\n" + - " \"phyCellIdInUse\": 6,\n" + - " \"pnfName\": \"ncserver23\"\n" + - " },\n" + - " \"CellConfig\": {\n" + - " \"LTE\": {\n" + - " \"RAN\": {\n" + - " \"Common\": {\n" + - " \"CellIdentity\": \"Chn0330\"\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - "\n" + - " }\n" + - " }\n" + - " },\n" + - " \"version\": \"1.0\",\n" + - " \"rpc-name\": \"modifyconfig\",\n" + - " \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" + - " \"type\": \"request\"\n" + - "}"); - } - - @Test - public void testProcessMsgInvalidPayloadConfigurations() throws Exception { - String msg = "{\n" + - " \"body\": {\n" + - " \"input\": {\n" + - " \"CommonHeader\": {\n" + - " \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" + - " \"APIVer\": \"1.0\",\n" + - " \"RequestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" + - " \"SubRequestID\": \"1\",\n" + - " \"RequestTrack\": {},\n" + - " \"Flags\": {}\n" + - " },\n" + - " \"Action\": \"ModifyConfig\",\n" + - " \"Payload\": {\n" + - " \"Configurations \": {\n" + - " \"data \": {\n" + - " \"FAPService \": {\n" + - " \"alias\": \"Chn0330\",\n" + - " \"X0005b9Lte\": {\n" + - " \"phyCellIdInUse\": 6,\n" + - " \"pnfName\": \"ncserver23\"\n" + - " },\n" + - " \"CellConfig\": {\n" + - " \"LTE\": {\n" + - " \"RAN\": {\n" + - " \"Common\": {\n" + - " \"CellIdentity\": \"Chn0330\"\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - "\n" + - " }\n" + - " }\n" + - " },\n" + - " \"version\": \"1.0\",\n" + - " \"rpc-name\": \"modifyconfig\",\n" + - " \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" + - " \"type\": \"request\"\n" + - "}"; - - try { - PciChangesFromPolicyToSDNRDmaapConsumer consumer = new PciChangesFromPolicyToSDNRDmaapConsumer(); - consumer.processMsg(msg); - - } catch (final InvalidMessageException e) { - final String errorMsg = "Configurations is not of Type Array. Could not read configuration changes"; - assertEquals(errorMsg, e.getMessage()); - } - } -} |