diff options
author | Jakub Dominik <j.dominik@samsung.com> | 2021-10-14 15:12:55 +0200 |
---|---|---|
committer | Dan Timoney <dtimoney@att.com> | 2021-11-18 13:19:44 +0000 |
commit | 98aeaac496ac868a97ce9096c1c51ce9a133992a (patch) | |
tree | e3e4a52f786f4dbe271485366f0a0c8d74edc85f /sdnr/wt/mountpoint-registrar/provider/src/test/java | |
parent | 5d3bfaac4bc7a8b7b030757e1f35795667915a2b (diff) |
Extend SDNC persistent service to store CM
Extend SDNC persistent service to store received CM events into Elasticsearch and MariaDB
Issue-ID: CCSDK-3497
Signed-off-by: Jakub Dominik <j.dominik@samsung.com>
Change-Id: I39983e59ef6512ad6c3864d47aebe1d615897146
Signed-off-by: Michael DÜrre <michael.duerre@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/mountpoint-registrar/provider/src/test/java')
4 files changed, 351 insertions, 0 deletions
diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMBasicHeaderFieldsNotification.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMBasicHeaderFieldsNotification.java new file mode 100644 index 000000000..5446da048 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMBasicHeaderFieldsNotification.java @@ -0,0 +1,45 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt mountpoint-registrar + * ================================================================================================= + * Copyright (C) 2021 Samsung Electronics 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.features.sdnr.wt.mountpointregistrar.test; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.CMBasicHeaderFieldsNotification; + +public class TestCMBasicHeaderFieldsNotification { + + private CMBasicHeaderFieldsNotification cmBasicFields; + + @Test + public void testCMBasicFieldsBuilder() { + cmBasicFields = cmBasicFields.builder() + .withCMNodeId("test-node") + .withCMSequence("1") + .withCMOccurrenceTime("2021-10-18T15:25:19.948Z") + .withSourceId("src_device_id_1732") + .withNotificationType("notifyMOIChanges") + .build(); + + assertEquals("test-node", cmBasicFields.getCmNodeId()); + assertEquals("1", cmBasicFields.getCmSequence()); + assertEquals("src_device_id_1732", cmBasicFields.getSourceId()); + assertEquals("2021-10-18T15:25:19.948Z", cmBasicFields.getCmOccurrenceTime()); + assertEquals("notifyMOIChanges", cmBasicFields.getNotificationType()); + } +}
\ No newline at end of file diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMNotificationBuilder.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMNotificationBuilder.java new file mode 100644 index 000000000..3b74df321 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMNotificationBuilder.java @@ -0,0 +1,79 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt mountpoint-registrar + * ================================================================================================= + * Copyright (C) 2021 Samsung Electronics 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.features.sdnr.wt.mountpointregistrar.test; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.CMBasicHeaderFieldsNotification; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.CMNotification; + +public class TestCMNotificationBuilder { + + private CMNotification cmNotification; + + @Test + public void testCMNotificationBuilderWithAllDefinedFields() { + cmNotification = cmNotification.builder() + .withCMBasicHeaderFieldsNotification(CMBasicHeaderFieldsNotification.builder() + .withCMNodeId("test-node") + .withCMSequence("1") + .withCMOccurrenceTime("2021-10-18T15:25:19.948Z") + .withSourceId("src_device_id_1732") + .withNotificationType("notifyMOIChanges") + .build()) + .withCMNotificationId("123") + .withCMSourceIndicator("UNKNOWN") + .withCMPath("http://samsung.com/ves=1") + .withCMOperation("CREATE") + .withCMValue("value") + .build(); + + assertEquals("test-node", cmNotification.getBasicHeaderFields().getCmNodeId()); + assertEquals("1", cmNotification.getBasicHeaderFields().getCmSequence()); + assertEquals("src_device_id_1732", cmNotification.getBasicHeaderFields().getSourceId()); + assertEquals("2021-10-18T15:25:19.948Z", cmNotification.getBasicHeaderFields().getCmOccurrenceTime()); + assertEquals("notifyMOIChanges", cmNotification.getBasicHeaderFields().getNotificationType()); + assertEquals("123", cmNotification.getCmNotificationId()); + assertEquals("UNKNOWN", cmNotification.getCmSourceIndicator()); + assertEquals("http://samsung.com/ves=1", cmNotification.getCmPath()); + assertEquals("CREATE", cmNotification.getCmOperation()); + assertEquals("value", cmNotification.getCmValue()); + } + + @Test + public void testCMNotificationBuilderWithDefaultCMOperation() { + cmNotification = cmNotification.builder() + .withCMBasicHeaderFieldsNotification(CMBasicHeaderFieldsNotification.builder() + .withCMNodeId("test-node") + .withCMSequence("1") + .withCMOccurrenceTime("2021-10-18T15:25:19.948Z") + .withSourceId("src_device_id_1732") + .withNotificationType("notifyMOIChanges") + .build()) + .withCMNotificationId("123") + .withCMSourceIndicator("UNKNOWN") + .withCMPath("http://samsung.com/ves=1") + .build(); + + assertEquals("test-node", cmNotification.getBasicHeaderFields().getCmNodeId()); + assertEquals("NULL", cmNotification.getCmOperation()); + assertNull(cmNotification.getCmValue()); + } +}
\ No newline at end of file diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMNotificationClient.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMNotificationClient.java new file mode 100644 index 000000000..12ccd4c62 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMNotificationClient.java @@ -0,0 +1,70 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt mountpoint-registrar + * ================================================================================================= + * Copyright (C) 2021 Samsung Electronics 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.features.sdnr.wt.mountpointregistrar.test; + +import static org.junit.Assert.assertTrue; + +import java.util.Map; +import javax.annotation.Nonnull; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.http.BaseHTTPResponse; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.CMBasicHeaderFieldsNotification; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.CMNotification; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.CMNotificationClient; + +public class TestCMNotificationClient extends CMNotificationClient { + public static String baseUrl = "http://localhost:8181"; + CMNotificationClient testClient; + + public TestCMNotificationClient() { + super(baseUrl); + } + + @Test + public void testCMNotificationClient() { + testClient = new TestCMNotificationClient(); + testClient.setAuthorization("admin", "admin"); + + String msg = testClient.prepareMessageFromPayloadMap( + CMNotificationClient.createCMNotificationPayloadMap( + CMNotification.builder() + .withCMBasicHeaderFieldsNotification(CMBasicHeaderFieldsNotification.builder() + .withCMNodeId("test-node") + .withCMSequence("1") + .withCMOccurrenceTime("2021-10-18T15:25:19.948Z") + .withSourceId("src_device_id_1732") + .withNotificationType("notifyMOIChanges") + .build()) + .withCMNotificationId("123") + .withCMSourceIndicator("UNKNOWN") + .withCMPath("http://samsung.com/ves=1") + .withCMOperation("CREATE") + .withCMValue("value") + .build() + )); + assertTrue(testClient.sendNotification(msg)); + } + + @Override + @Nonnull + public BaseHTTPResponse sendRequest(String uri, String method, String body, Map<String, String> headers) { + System.out.println("In overridden sendRequest in TestCMNotificationClient"); + return new BaseHTTPResponse(200, body); + } +}
\ No newline at end of file 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(); |