diff options
Diffstat (limited to 'sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPCMVESMsgConsumer.java')
-rw-r--r-- | sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPCMVESMsgConsumer.java | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPCMVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPCMVESMsgConsumer.java index 0cd7f0228..2c4fb647b 100644 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPCMVESMsgConsumer.java +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPCMVESMsgConsumer.java @@ -30,7 +30,13 @@ import java.io.IOException; import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Paths; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import static org.junit.Assert.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import java.util.Iterator; +import java.util.Map; public class TestDMaaPCMVESMsgConsumer { @@ -62,6 +68,14 @@ public class TestDMaaPCMVESMsgConsumer { dMaaPCMVESMsgConsumer.processMsg(cmEvent); } + @Test(expected = InvalidMessageException.class) + public void processMsgThatHasInvalidNotificationType() + throws URISyntaxException, IOException, InvalidMessageException { + File cmFileInvalid = new File(TestDMaaPCMVESMsgConsumer.class.getResource("/msgs/cm_invalid_type.json").toURI()); + String cmEvent = readFileToString(cmFileInvalid); + dMaaPCMVESMsgConsumer.processMsg(cmEvent); + } + @Test(expected = JsonProcessingException.class) public void processMsgThatIsNotValidJson() throws URISyntaxException, IOException, InvalidMessageException { File cmFileInvalid = new File(TestDMaaPCMVESMsgConsumer.class.getResource("/msgs/not_a_json.json").toURI()); @@ -69,12 +83,155 @@ public class TestDMaaPCMVESMsgConsumer { dMaaPCMVESMsgConsumer.processMsg(cmEvent); } + @Test + public void processMsgWithOneElementMoiChangesArray() throws URISyntaxException, IOException { + File cmFileValid = new File(TestDMaaPCMVESMsgConsumer.class.getResource("/msgs/cm_valid.json").toURI()); + String cmEvent = readFileToString(cmFileValid); + try { + JsonNode rootNode = convertMessageToJsonNode(cmEvent); + Iterator<JsonNode> nodes = rootNode + .at("/event/stndDefinedFields/data/moiChanges") + .elements(); + Map<String, String> payloadMap = + dMaaPCMVESMsgConsumer.preparePayloadMapFromMoiChangesArray(rootNode, nodes); + + assertEquals("samsung-O-DU-1122", payloadMap.get("@node-id@")); + assertEquals("0", payloadMap.get("@counter@")); + assertEquals("2019-01-09T12:30:07.722Z", payloadMap.get("@timestamp@")); + assertEquals("src_device_id_1732f1ad-53fd-4fd1-8b73-a677987d4e8f", payloadMap.get("@object-id@")); + assertEquals("notifyMOIChanges", payloadMap.get("@notification-type@")); + assertEquals("123", payloadMap.get("@notification-id@")); + assertEquals("MANAGEMENT_OPERATION", payloadMap.get("@source-indicator@")); + assertEquals("https://samsung.com/3GPP/simulation/network-function/ves=1", payloadMap.get("@path@")); + assertEquals("REPLACE", payloadMap.get("@operation@")); + assertEquals("{pnf-registration:true,faults-enabled:true}", payloadMap.get("@value@")); + + } catch (Exception e) { + fail("Test fail with message: " + e.getMessage()); + } + } + + @Test + public void processMsgWithTwoElementMoiChangesArray() throws URISyntaxException, IOException { + File cmFileValid = + new File(TestDMaaPCMVESMsgConsumer.class.getResource("/msgs/cm_valid_two_element_moi_changes_array.json") + .toURI()); + String cmEvent = readFileToString(cmFileValid); + try { + JsonNode rootNode = convertMessageToJsonNode(cmEvent); + Iterator<JsonNode> nodes = rootNode + .at("/event/stndDefinedFields/data/moiChanges") + .elements(); + Map<String, String> payloadMap = + dMaaPCMVESMsgConsumer.preparePayloadMapFromMoiChangesArray(rootNode, nodes); + + assertEquals("samsung-O-DU-1122", payloadMap.get("@node-id@")); + assertEquals("0", payloadMap.get("@counter@")); + assertEquals("2019-01-09T12:30:07.722Z", payloadMap.get("@timestamp@")); + assertEquals("src_device_id_1732f1ad-53fd-4fd1-8b73-a677987d4e8f", payloadMap.get("@object-id@")); + assertEquals("notifyMOIChanges", payloadMap.get("@notification-type@")); + assertEquals("123", payloadMap.get("@notification-id@")); + assertEquals("MANAGEMENT_OPERATION", payloadMap.get("@source-indicator@")); + assertEquals("https://samsung.com/3GPP/simulation/network-function/ves=1", payloadMap.get("@path@")); + assertEquals("REPLACE", payloadMap.get("@operation@")); + assertEquals("{pnf-registration:true,faults-enabled:true}", payloadMap.get("@value@")); + + Map<String, String> payloadMap2 = null; + while (nodes.hasNext()) { + payloadMap2 = dMaaPCMVESMsgConsumer.preparePayloadMapFromMoiChangesArray(rootNode, nodes); + } + assertEquals("samsung-O-DU-1122", payloadMap2.get("@node-id@")); + assertEquals("124", payloadMap2.get("@notification-id@")); + assertEquals("RESOURCE_OPERATION", payloadMap2.get("@source-indicator@")); + assertEquals("https://samsung.com/3GPP/simulation/network-function/ves=2", payloadMap2.get("@path@")); + assertEquals("CREATE", payloadMap2.get("@operation@")); + assertEquals("{pnf-registration:false,faults-enabled:false}", payloadMap2.get("@value@")); + + } catch (Exception e) { + fail("Test fail with message: " + e.getMessage()); + } + } + + @Test + public void processMsgNotifyMoiCreationType() throws URISyntaxException, IOException { + File cmFileValid = new File(TestDMaaPCMVESMsgConsumer.class.getResource("/msgs/cm_moi_creation.json").toURI()); + String cmEvent = readFileToString(cmFileValid); + try { + JsonNode rootNode = convertMessageToJsonNode(cmEvent); + Map<String, String> payloadMap = dMaaPCMVESMsgConsumer.preparePayloadMapFromMoi(rootNode,"/event/stndDefinedFields/data/attributeList"); + assertEquals("samsung-O-DU-1122", payloadMap.get("@node-id@")); + assertEquals("0", payloadMap.get("@counter@")); + assertEquals("2019-01-09T12:30:07.722Z", payloadMap.get("@timestamp@")); + assertEquals("src_device_id_1732f1ad-53fd-4fd1-8b73-a677987d4e8f", payloadMap.get("@object-id@")); + assertEquals("notifyMOICreation", payloadMap.get("@notification-type@")); + assertNull(payloadMap.get("@notification-id@")); + assertEquals("MANAGEMENT_OPERATION", payloadMap.get("@source-indicator@")); + assertNull(payloadMap.get("@path@")); + assertEquals("NULL", payloadMap.get("@operation@")); + assertEquals("{pnf-registration:true,faults-enabled:true}", payloadMap.get("@value@")); + + } catch (Exception e) { + fail("Test fail with message: " + e.getMessage()); + } + } + + @Test + public void processMsgNotifyMoiDeletionType() throws URISyntaxException, IOException { + File cmFileValid = new File(TestDMaaPCMVESMsgConsumer.class.getResource("/msgs/cm_moi_deletion.json").toURI()); + String cmEvent = readFileToString(cmFileValid); + try { + JsonNode rootNode = convertMessageToJsonNode(cmEvent); + Map<String, String> payloadMap = dMaaPCMVESMsgConsumer.preparePayloadMapFromMoi(rootNode,"/event/stndDefinedFields/data/attributeList"); + assertEquals("samsung-O-DU-1122", payloadMap.get("@node-id@")); + assertEquals("0", payloadMap.get("@counter@")); + assertEquals("2019-01-09T12:30:07.722Z", payloadMap.get("@timestamp@")); + assertEquals("src_device_id_1732f1ad-53fd-4fd1-8b73-a677987d4e8f", payloadMap.get("@object-id@")); + assertEquals("notifyMOIDeletion", payloadMap.get("@notification-type@")); + assertNull(payloadMap.get("@notification-id@")); + assertEquals("MANAGEMENT_OPERATION", payloadMap.get("@source-indicator@")); + assertNull(payloadMap.get("@path@")); + assertEquals("NULL", payloadMap.get("@operation@")); + assertEquals("{pnf-registration:true,faults-enabled:true}", payloadMap.get("@value@")); + + } catch (Exception e) { + fail("Test fail with message: " + e.getMessage()); + } + } + + @Test + public void processMsgNotifyMoiAttributeValueChangesType() throws URISyntaxException, IOException { + File cmFileValid = + new File(TestDMaaPCMVESMsgConsumer.class.getResource("/msgs/cm_moi_attribute_value_changes.json").toURI()); + String cmEvent = readFileToString(cmFileValid); + try { + JsonNode rootNode = convertMessageToJsonNode(cmEvent); + Map<String, String> payloadMap = dMaaPCMVESMsgConsumer.preparePayloadMapFromMoi(rootNode,"/event/stndDefinedFields/data/attributeListValueChanges"); + assertEquals("samsung-O-DU-1122", payloadMap.get("@node-id@")); + assertEquals("0", payloadMap.get("@counter@")); + assertEquals("2019-01-09T12:30:07.722Z", payloadMap.get("@timestamp@")); + assertEquals("src_device_id_1732f1ad-53fd-4fd1-8b73-a677987d4e8f", payloadMap.get("@object-id@")); + assertEquals("notifyMOIAttributeValueChanges", payloadMap.get("@notification-type@")); + assertNull(payloadMap.get("@notification-id@")); + assertEquals("UNKNOWN", payloadMap.get("@source-indicator@")); + assertNull(payloadMap.get("@path@")); + assertEquals("NULL", payloadMap.get("@operation@")); + assertEquals("[{attributeNameValuePairSet:{faults-enabled:true}}]", payloadMap.get("@value@")); + + } catch (Exception e) { + fail("Test fail with message: " + e.getMessage()); + } + } + private String readFileToString(File file) throws IOException { StringBuilder fileContent = new StringBuilder(); Files.lines(Paths.get(file.toURI())).forEach(fileContent::append); return fileContent.toString(); } + private JsonNode convertMessageToJsonNode(String message) throws JsonProcessingException { + return new ObjectMapper().readTree(message); + } + @After public void after() { generalConfigForTest.close(); |