From 3323a01bc3633dd723c1c7e9ad9488f89029bd1f Mon Sep 17 00:00:00 2001 From: Ravi Pendurty Date: Tue, 14 Mar 2023 18:02:29 +0530 Subject: Use Strimzi Kafka and Kafka native APIs dmaapClient library is no longer used as DMaaP-MR is being deprecated Issue-ID: CCSDK-3784 Signed-off-by: Ravi Pendurty Change-Id: I12b9b7c8c57ad983a162e04ad8e76a57978fa9ee Signed-off-by: Ravi Pendurty --- .../test/GeneralConfigForTest.java | 66 ----- .../test/PNFRegistrationConfigTest.java | 98 -------- .../test/TestCMBasicHeaderFieldsNotification.java | 45 ---- .../test/TestCMNotificationBuilder.java | 79 ------ .../test/TestCMNotificationClient.java | 70 ------ .../test/TestDMaaPCMVESMsgConsumer.java | 239 ------------------ .../test/TestDMaaPFaultVESMsgConsumer.java | 148 ----------- .../test/TestDMaaPPNFRegVESMsgConsumer.java | 270 -------------------- .../test/TestDMaaPVESMsgConsumerMain.java | 170 ------------- .../mountpointregistrar/test/TestFaultConfig.java | 98 -------- .../test/TestFaultNotificationClient.java | 60 ----- .../test/TestGeneralConfig.java | 54 ---- .../test/TestPNFMountPointClient.java | 63 ----- .../test/TestProvisioningConfig.java | 95 -------- .../TestCMBasicHeaderFieldsNotification.java | 45 ++++ .../test/client/TestCMNotificationBuilder.java | 79 ++++++ .../test/client/TestCMNotificationClient.java | 70 ++++++ .../test/client/TestFaultNotificationClient.java | 60 +++++ .../test/client/TestPNFMountPointClient.java | 63 +++++ .../test/config/GeneralConfigForTest.java | 65 +++++ .../test/config/PNFRegistrationConfigTest.java | 75 ++++++ .../test/config/TestFaultConfig.java | 76 ++++++ .../test/config/TestGeneralConfig.java | 53 ++++ .../test/config/TestProvisioningConfig.java | 69 ++++++ .../test/config/TestStrimziKafkaConfig.java | 73 ++++++ .../consumer/TestStrimziKafkaCMVESMsgConsumer.java | 239 ++++++++++++++++++ .../TestStrimziKafkaFaultVESMsgConsumer.java | 150 ++++++++++++ .../TestStrimziKafkaPNFRegVESMsgConsumer.java | 271 +++++++++++++++++++++ .../TestStrimziKafkaStndDefinedVESMsgConsumer.java | 239 ++++++++++++++++++ .../TestStrimziKafkaVESMsgConsumerMain.java | 175 +++++++++++++ 30 files changed, 1802 insertions(+), 1555 deletions(-) delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/GeneralConfigForTest.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/PNFRegistrationConfigTest.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMBasicHeaderFieldsNotification.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMNotificationBuilder.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMNotificationClient.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPCMVESMsgConsumer.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPFaultVESMsgConsumer.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPPNFRegVESMsgConsumer.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPVESMsgConsumerMain.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestFaultConfig.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestFaultNotificationClient.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestGeneralConfig.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestPNFMountPointClient.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestProvisioningConfig.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestCMBasicHeaderFieldsNotification.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestCMNotificationBuilder.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestCMNotificationClient.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestFaultNotificationClient.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestPNFMountPointClient.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/GeneralConfigForTest.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/PNFRegistrationConfigTest.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestFaultConfig.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestGeneralConfig.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestProvisioningConfig.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestStrimziKafkaConfig.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaCMVESMsgConsumer.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaFaultVESMsgConsumer.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaPNFRegVESMsgConsumer.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaStndDefinedVESMsgConsumer.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaVESMsgConsumerMain.java (limited to 'sdnr/wt/mountpoint-registrar/provider/src/test') diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/GeneralConfigForTest.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/GeneralConfigForTest.java deleted file mode 100644 index 3413e9766..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/GeneralConfigForTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2020 highstreet technologies GmbH 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 com.google.common.io.Files; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.GeneralConfig; - -public class GeneralConfigForTest implements AutoCloseable { - - // @formatter:off - private static final String TESTCONFIG_CONTENT = "[general]\n" - + "dmaapEnabled=false\n" - + "baseUrl=http://localhost:8181\n" - + "sdnrUser=admin\n" - + "sdnrPasswd=admin\n" - + ""; - // @formatter:on - - private GeneralConfig cfg ; - private String filename; - - GeneralConfigForTest(String filename) throws IOException { - - Files.asCharSink(new File(filename), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); - ConfigurationFileRepresentation globalCfg = new ConfigurationFileRepresentation(filename); - this.filename = filename; - this.cfg = new GeneralConfig(globalCfg); - - } - - public GeneralConfig getCfg() { - return cfg; - } - - - @Override - public - void close() { - File file = new File(filename); - if (file.exists()) { - System.out.println("File exists, Deleting it"); - file.delete(); - } - - } -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/PNFRegistrationConfigTest.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/PNFRegistrationConfigTest.java deleted file mode 100644 index d3f4a13d6..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/PNFRegistrationConfigTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH 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 com.google.common.io.Files; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import org.junit.After; -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.PNFRegistrationConfig; - -public class PNFRegistrationConfigTest { - - // @formatter:off - private static final String TESTCONFIG_CONTENT = "[pnfRegistration]\n" - + "TransportType=HTTPNOAUTH\n" - + "Protocol=http\n" - + "username=username\n" - + "password=password\n" - + "host=onap-dmap:3904\n" - + "topic=unauthenticated.VES_PNFREG_OUTPUT\n" - + "contenttype=application/json\n" - + "group=myG\n" - + "id=C1\n" - + "timeout=20000\n" - + "limit=10000\n" - + "fetchPause=5000\n" - + "jersey.config.client.readTimeout=25000\n" - + "jersey.config.client.connectTimeout=25000\n" - + "jersey.config.client.proxy.uri=http://http-proxy\n" - + "jersey.config.client.proxy.username=proxy-user\n" - + "jersey.config.client.proxy.password=proxy-password\n" - + ""; - // @formatter:on - private ConfigurationFileRepresentation cfg; - private static final String configFile = "test.properties"; - - @Test - public void test() { - try { - Files.asCharSink(new File(configFile), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); - cfg = new ConfigurationFileRepresentation(configFile); - PNFRegistrationConfig pnfCfg = new PNFRegistrationConfig(cfg); - assertEquals("pnfRegistration", pnfCfg.getSectionName()); - assertEquals("HTTPNOAUTH", pnfCfg.getTransportType()); - assertEquals("onap-dmap:3904", pnfCfg.getHostPort()); - assertEquals("unauthenticated.VES_PNFREG_OUTPUT", pnfCfg.getTopic()); - assertEquals("application/json", pnfCfg.getContenttype()); - assertEquals("myG", pnfCfg.getConsumerGroup()); - assertEquals("C1", pnfCfg.getConsumerId()); - assertEquals("20000", pnfCfg.getTimeout()); - assertEquals("10000", pnfCfg.getLimit()); - assertEquals("5000", pnfCfg.getFetchPause()); - assertEquals("http", pnfCfg.getProtocol()); - assertEquals("username", pnfCfg.getUsername()); - assertEquals("password", pnfCfg.getPassword()); - assertEquals("25000", pnfCfg.getClientReadTimeout()); - assertEquals("25000", pnfCfg.getClientConnectTimeout()); - assertEquals("http://http-proxy", pnfCfg.getHTTPProxyURI()); - assertEquals("proxy-user", pnfCfg.getHTTPProxyUsername()); - assertEquals("proxy-password", pnfCfg.getHTTPProxyPassword()); - - } catch (IOException e) { - e.printStackTrace(); - } - - } - - @After - public void cleanUp() { - File file = new File(configFile); - if (file.exists()) { - System.out.println("File exists, Deleting it"); - file.delete(); - } - - } - -} 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 deleted file mode 100644 index 5446da048..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMBasicHeaderFieldsNotification.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * ============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 deleted file mode 100644 index 3b74df321..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMNotificationBuilder.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * ============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 deleted file mode 100644 index 12ccd4c62..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMNotificationClient.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * ============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 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 deleted file mode 100644 index 2c4fb647b..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPCMVESMsgConsumer.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * 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 com.fasterxml.jackson.core.JsonProcessingException; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPCMVESMsgConsumer; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.InvalidMessageException; - -import java.io.File; -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 { - - private static final String CONFIGURATION_FILE = "cm_test.properties"; - private DMaaPCMVESMsgConsumer dMaaPCMVESMsgConsumer; - private GeneralConfigForTest generalConfigForTest; - - @Before - public void setUp() throws Exception { - generalConfigForTest = new GeneralConfigForTest(CONFIGURATION_FILE); - dMaaPCMVESMsgConsumer = new DMaaPCMVESMsgConsumer(generalConfigForTest.getCfg()); - } - - @Test - public void processValidMsg() throws URISyntaxException, IOException { - File cmFileValid = new File(TestDMaaPCMVESMsgConsumer.class.getResource("/msgs/cm_valid.json").toURI()); - String cmEvent = readFileToString(cmFileValid); - try { - dMaaPCMVESMsgConsumer.processMsg(cmEvent); - } catch (Exception e) { - fail("Test fail with message: " + e.getMessage()); - } - } - - @Test(expected = InvalidMessageException.class) - public void processMsgThatMissesField() throws URISyntaxException, IOException, InvalidMessageException { - File cmFileInvalid = new File(TestDMaaPCMVESMsgConsumer.class.getResource("/msgs/cm_invalid.json").toURI()); - String cmEvent = readFileToString(cmFileInvalid); - 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()); - String cmEvent = readFileToString(cmFileInvalid); - 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 nodes = rootNode - .at("/event/stndDefinedFields/data/moiChanges") - .elements(); - Map 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 nodes = rootNode - .at("/event/stndDefinedFields/data/moiChanges") - .elements(); - Map 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 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 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 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 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(); - } -} \ 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/TestDMaaPFaultVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPFaultVESMsgConsumer.java deleted file mode 100644 index cf25e1e7b..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPFaultVESMsgConsumer.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH 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 java.io.IOException; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPFaultVESMsgConsumer; - -public class TestDMaaPFaultVESMsgConsumer { - - private static final String DEFAULT_SDNRUSER = "admin"; - private static final String DEFAULT_SDNRPASSWD = "admin"; - private static final String DEFAULT_SDNRBASEURL = "http://localhost:8181"; - private static final String CONFIGURATIONFILE = "test2.properties"; - - // @formatter:off - private static final String faultVESMsg = "" - + "{\"event\":" + " {\"commonEventHeader\":" - + " { \"domain\":\"fault\"," - + " \"eventId\":\"1e9a28bcd119_50007_2019-11-20T14:59:47.3Z\"," - + " \"eventName\":\"fault_O_RAN_COMPONENT_Alarms\"," - + " \"eventType\":\"O_RAN_COMPONENT_Alarms\"," - + " \"sequence\":1," - + " \"priority\":\"Low\"," - + " \"reportingEntityId\":\"\"," - + " \"reportingEntityName\":\"1e9a28bcd119_50007\"," - + " \"sourceId\":\"\"," - + " \"sourceName\":\"1e9a28bcd119_50007\"," - + " \"startEpochMicrosec\":1614004128699785," - + " \"lastEpochMicrosec\":1614004128699785," - + " \"nfNamingCode\":\"sdn controller\"," - + " \"nfVendorName\":\"sdn\"," - + " \"timeZoneOffset\":\"+00:00\"," - + " \"version\":\"4.0.1\"," - + " \"vesEventListenerVersion\":\"7.0.1\"" - + " }," - + " \"faultFields\":" - + " {" - + " \"faultFieldsVersion\":\"4.0\"," - + " \"alarmCondition\":\"8\"," - + " \"alarmInterfaceA\":\"dkom32\"," - + " \"eventSourceType\":\"O_RAN_COMPONENT\"," - + " \"specificProblem\":\"dsonj32 don32 mdson32pk654\"," - + " \"eventSeverity\":\"@eventSeverity@\"," - + " \"vfStatus\":\"Active\"," - + " \"alarmAdditionalInformation\":" - + " {" - + " \"eventTime\":\"2019-11-20T14:59:47.3Z\"," - + " \"equipType\":\"O-RAN-sim\"," - + " \"vendor\":\"Melacon\"," - + " \"model\":\"Simulated Device\"" - + " }" - + " }" - + " }" - + "}"; - // @formatter:on - // @formatter:off - private static final String faultVESMsg_Incomplete = "" - + "{\"event\":" - + " {\"commonEventHeader\":" - + " { \"domain\":\"fault\"," - + " \"eventId\":\"1e9a28bcd119_50007_2019-11-20T14:59:47.3Z\"," - + " \"eventName\":\"fault_O_RAN_COMPONENT_Alarms\"," - + " \"eventType\":\"O_RAN_COMPONENT_Alarms\"," - + " \"sequence\":1," - + " \"priority\":\"Low\"," - + " \"reportingEntityId\":\"\"," - + " \"reportingEntityName\":\"1e9a28bcd119_50007\"," - + " \"sourceId\":\"\"," - + " \"sourceName\":\"1e9a28bcd119_50007\"," - + " \"startEpochMicrosec\":1612349525626," - + " \"lastEpochMicrosec\":1612349525626," - + " \"nfNamingCode\":\"sdn controller\"," - + " \"nfVendorName\":\"sdn\"," - + " \"timeZoneOffset\":\"+00:00\"," - + " \"version\":\"4.0.1\"," - + " \"vesEventListenerVersion\":\"7.0.1\"," - + " }," - + " \"faultFields\":" - + " {" - + " \"faultFieldsVersion\":\"4.0\"," - + " \"alarmCondition\":\"8\"," - + " \"alarmInterfaceA\":\"dkom32\"," - + " \"eventSourceType\":\"O_RAN_COMPONENT\"," - + " \"specificProblem\":\"dsonj32 don32 mdson32pk654\"," - + " \"eventSeverity\":\"CRITICAL\"," - + " \"vfStatus\":\"Active\"," - + " \"alarmAdditionalInformation\":" - + " {" - + " \"eventTime\":\"2019-11-20T14:59:47.3Z\"," - + " \"equipType\":\"O-RAN-sim\"," - + " \"vendor\":\"Melacon\"," - + " \"model\":\"Simulated Device\"" - + " }" - + " }" - + " }" - + "}"; - // @formatter:on - - private GeneralConfigForTest cfgTest; - - @Before - public void before() throws IOException { - cfgTest = new GeneralConfigForTest(CONFIGURATIONFILE); - } - @After - public void after() { - cfgTest.close(); - } - - - @Test - public void test() throws IOException { - DMaaPFaultVESMsgConsumer faultMsgConsumer = new DMaaPFaultVESMsgConsumer(cfgTest.getCfg()); - try { - - faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "CRITICAL")); - faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "Major")); - faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "minor")); - faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "NonAlarmed")); - faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "warning")); - faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "Unknown")); - faultMsgConsumer.processMsg(faultVESMsg_Incomplete); - } catch (Exception e) { - e.printStackTrace(); - System.out.println("Exception while processing Fault Message - " + e.getMessage()); - } - } - -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPPNFRegVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPPNFRegVESMsgConsumer.java deleted file mode 100644 index 2c07caa1c..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPPNFRegVESMsgConsumer.java +++ /dev/null @@ -1,270 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH 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 java.io.IOException; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPPNFRegVESMsgConsumer; - -public class TestDMaaPPNFRegVESMsgConsumer { - - private static final String DEFAULT_SDNRUSER = "admin"; - private static final String DEFAULT_SDNRPASSWD = "admin"; - private static final String DEFAULT_SDNRBASEURL = "http://localhost:8181"; - private static final String CONFIGURATIONFILE = "test4.properties"; - - // @formatter:off - private static final String pnfRegMsg_TLS = "{\n" - + " \"event\": {\n" - + " \"commonEventHeader\": {\n" - + " \"domain\": \"pnfRegistration\",\n" - + " \"eventId\": \"NSHMRIACQ01M01123401_1234 BestInClass\",\n" - + " \"eventName\": \"pnfRegistration_EventType5G\",\n" - + " \"eventType\": \"EventType5G\",\n" - + " \"sequence\": 0,\n" - + " \"priority\": \"Low\",\n" - + " \"reportingEntityId\": \"\",\n" - + " \"reportingEntityName\": \"pendurty-virtual-machine\",\n" - + " \"sourceId\": \"\",\n" - + " \"sourceName\": \"NSHMRIACQ01M01123401\",\n" - + " \"startEpochMicrosec\": 1571300004203,\n" - + " \"lastEpochMicrosec\": 1571300004203,\n" - + " \"nfNamingCode\": \"1234\",\n" - + " \"nfVendorName\": \"VENDORA\",\n" - + " \"timeZoneOffset\": \"+00:00\",\n" - + " \"version\": \"4.0.1\",\n" - + " \"vesEventListenerVersion\":\"7.0.1\"\n" - + " },\n" - + " \"pnfRegistrationFields\": {\n" - + " \"pnfRegistrationFieldsVersion\": \"2.0\",\n" - + " \"additionalFields\": \n" - + " { \n" - + " \"protocol\":\"TLS\",\n" - + " \"keyId\":\"netconf\",\n" - + " \"oamPort\":\"50000\",\n" - + " \"betweenAttemptsTimeout\":\"2000\",\n" - + " \"keepaliveDelay\":\"120\",\n" - + " \"sleep-factor\":\"1.5\",\n" - + " \"reconnectOnChangedSchema\":\"false\",\n" - + " \"connectionTimeout\":\"20000\",\n" - + " \"maxConnectionAttempts\":\"100\",\n" - + " \"username\":\"netconf\",\n" - + " \"tcpOnly\":\"false\"\n" - + " },\n" - + " \"lastServiceDate\":\"2019-08-16\",\n" - + " \"macAddress\":\"02:42:f7:d4:62:ce\",\n" - + " \"manufactureDate\":\"2019-08-16\",\n" - + " \"modelNumbsdnrer\": \"1234 BestInClass\",\n" - + " \"oamV4IpAddress\": \"10.10.10.11\",\n" - + " \"oamPort\":\"17380\",\n" - + " \"oamV6IpAddress\": \"0:0:0:0:0:ffff:a0a:011\",\n" - + " \"serialNumber\": \"VENDORA-1234-10.10.10.11-1234 BestInClass\",\n" - + " \"softwareVersion\": \"2.3.5\",\n" - + " \"unitFamily\": \"VENDORA-1234\",\n" - + " \"unitType\": \"1234\",\n" - + " \"vendorName\": \"VENDORA\"\n" - + " }\n" - + " }\n" - + "}\n" - + ""; - private static final String pnfRegMsg_SSH = "{\n" - + " \"event\": {\n" - + " \"commonEventHeader\": {\n" - + " \"domain\": \"pnfRegistration\",\n" - + " \"eventId\": \"NSHMRIACQ01M01123401_1234 BestInClass\",\n" - + " \"eventName\": \"pnfRegistration_EventType5G\",\n" - + " \"eventType\": \"EventType5G\",\n" - + " \"sequence\": 0,\n" - + " \"priority\": \"Low\",\n" - + " \"reportingEntityId\": \"\",\n" - + " \"reportingEntityName\": \"pendurty-virtual-machine\",\n" - + " \"sourceId\": \"\",\n" - + " \"sourceName\": \"NSHMRIACQ01M01123401\",\n" - + " \"startEpochMicrosec\": 1571300004203,\n" - + " \"lastEpochMicrosec\": 1571300004203,\n" - + " \"nfNamingCode\": \"1234\",\n" - + " \"nfVendorName\": \"VENDORA\",\n" - + " \"timeZoneOffset\": \"+00:00\",\n" - + " \"version\": \"4.0.1\",\n" - + " \"vesEventListenerVersion\":\"7.0.1\"\n" - + " },\n" - + " \"pnfRegistrationFields\": {\n" - + " \"pnfRegistrationFieldsVersion\": \"2.0\",\n" - + " \"additionalFields\": \n" - + " { \n" - + " \"protocol\":\"SSH\",\n" - + " \"password\":\"netconf\",\n" - + " \"oamPort\":\"50000\",\n" - + " \"betweenAttemptsTimeout\":\"2000\",\n" - + " \"keepaliveDelay\":\"120\",\n" - + " \"sleep-factor\":\"1.5\",\n" - + " \"reconnectOnChangedSchema\":\"false\",\n" - + " \"connectionTimeout\":\"20000\",\n" - + " \"maxConnectionAttempts\":\"100\",\n" - + " \"username\":\"netconf\",\n" - + " \"tcpOnly\":\"false\"\n" - + " },\n" - + " \"lastServiceDate\":\"2019-08-16\",\n" - + " \"macAddress\":\"02:42:f7:d4:62:ce\",\n" - + " \"manufactureDate\":\"2019-08-16\",\n" - + " \"modelNumbsdnrer\": \"1234 BestInClass\",\n" - + " \"oamV4IpAddress\": \"10.10.10.11\",\n" - + " \"oamPort\":\"17380\",\n" - + " \"oamV6IpAddress\": \"0:0:0:0:0:ffff:a0a:011\",\n" - + " \"serialNumber\": \"VENDORA-1234-10.10.10.11-1234 BestInClass\",\n" - + " \"softwareVersion\": \"2.3.5\",\n" - + " \"unitFamily\": \"VENDORA-1234\",\n" - + " \"unitType\": \"1234\",\n" - + " \"vendorName\": \"VENDORA\"\n" - + " }\n" - + " }\n" - + "}\n" - + ""; - private static final String pnfRegMsg_OTHER = "{\n" - + " \"event\": {\n" - + " \"commonEventHeader\": {\n" - + " \"domain\": \"pnfRegistration\",\n" - + " \"eventId\": \"NSHMRIACQ01M01123401_1234 BestInClass\",\n" - + " \"eventName\": \"pnfRegistration_EventType5G\",\n" - + " \"eventType\": \"EventType5G\",\n" - + " \"sequence\": 0,\n" - + " \"priority\": \"Low\",\n" - + " \"reportingEntityId\": \"\",\n" - + " \"reportingEntityName\": \"pendurty-virtual-machine\",\n" - + " \"sourceId\": \"\",\n" - + " \"sourceName\": \"NSHMRIACQ01M01123401\",\n" - + " \"startEpochMicrosec\": 1571300004203,\n" - + " \"lastEpochMicrosec\": 1571300004203,\n" - + " \"nfNamingCode\": \"1234\",\n" - + " \"nfVendorName\": \"VENDORA\",\n" - + " \"timeZoneOffset\": \"+00:00\",\n" - + " \"version\": \"4.0.1\",\n" - + " \"vesEventListenerVersion\":\"7.0.1\"\n" - + " },\n" - + " \"pnfRegistrationFields\": {\n" - + " \"pnfRegistrationFieldsVersion\": \"2.0\",\n" - + " \"additionalFields\": \n" - + " { \n" - + " \"protocol\":\"OTHER\",\n" - + " \"password\":\"netconf\",\n" - + " \"oamPort\":\"50000\",\n" - + " \"betweenAttemptsTimeout\":\"2000\",\n" - + " \"keepaliveDelay\":\"120\",\n" - + " \"sleep-factor\":\"1.5\",\n" - + " \"reconnectOnChangedSchema\":\"false\",\n" - + " \"connectionTimeout\":\"20000\",\n" - + " \"maxConnectionAttempts\":\"100\",\n" - + " \"username\":\"netconf\",\n" - + " \"tcpOnly\":\"false\"\n" - + " },\n" - + " \"lastServiceDate\":\"2019-08-16\",\n" - + " \"macAddress\":\"02:42:f7:d4:62:ce\",\n" - + " \"manufactureDate\":\"2019-08-16\",\n" - + " \"modelNumbsdnrer\": \"1234 BestInClass\",\n" - + " \"oamV4IpAddress\": \"10.10.10.11\",\n" - + " \"oamPort\":\"17380\",\n" - + " \"oamV6IpAddress\": \"0:0:0:0:0:ffff:a0a:011\",\n" - + " \"serialNumber\": \"VENDORA-1234-10.10.10.11-1234 BestInClass\",\n" - + " \"softwareVersion\": \"2.3.5\",\n" - + " \"unitFamily\": \"VENDORA-1234\",\n" - + " \"unitType\": \"1234\",\n" - + " \"vendorName\": \"VENDORA\"\n" - + " }\n" - + " }\n" - + "}\n" - + ""; - private static final String pnfRegMsg = "{\n" - + " \"event\": {\n" - + " \"commonEventHeader\": {\n" - + " \"domain\": \"pnfRegistration\",\n" - + " \"eventId\": \"NSHMRIACQ01M01123401_1234 BestInClass\",\n" - + " \"eventName\": \"pnfRegistration_EventType5G\",\n" - + " \"eventType\": \"EventType5G\",\n" - + " \"sequence\": 0,\n" - + " \"priority\": \"Low\",\n" - + " \"reportingEntityId\": \"\",\n" - + " \"reportingEntityName\": \"pendurty-virtual-machine\",\n" - + " \"sourceId\": \"\",\n" - + " \"sourceName\": \"NSHMRIACQ01M01123401\",\n" - + " \"startEpochMicrosec\": 1571300004203,\n" - + " \"lastEpochMicrosec\": 1571300004203,\n" - + " \"nfNamingCode\": \"1234\",\n" - + " \"nfVendorName\": \"VENDORA\",\n" - + " \"timeZoneOffset\": \"+00:00\",\n" - + " \"version\": \"4.0.1\",\n" - + " \"vesEventListenerVersion\":\"7.0.1\"\n" - + " },\n" - + " \"pnfRegistrationFields\": {\n" - + " \"pnfRegistrationFieldsVersion\": \"2.0\",\n" - + " \"lastServiceDate\":\"2019-08-16\",\n" - + " \"macAddress\":\"02:42:f7:d4:62:ce\",\n" - + " \"manufactureDate\":\"2019-08-16\",\n" - + " \"modelNumbsdnrer\": \"1234 BestInClass\",\n" - + " \"oamV4IpAddress\": \"10.10.10.11\",\n" - + " \"oamPort\":\"17380\",\n" - //+ " \"oamV6IpAddress\": \"\",\n" - + " \"serialNumber\": \"VENDORA-1234-10.10.10.11-1234 BestInClass\",\n" - + " \"softwareVersion\": \"2.3.5\",\n" - + " \"unitFamily\": \"VENDORA-1234\",\n" - + " \"unitType\": \"1234\",\n" - + " \"vendorName\": \"VENDORA\"\n" - + " }\n" - + " }\n" - + "}\n" - + ""; - // @formatter:on - - private GeneralConfigForTest cfgTest; - - @Before - public void before() throws IOException { - cfgTest = new GeneralConfigForTest(CONFIGURATIONFILE); - } - - @After - public void after() { - cfgTest.close(); - } - - @Test - public void processMsgTest() { - - DMaaPPNFRegVESMsgConsumer pnfRegMsgConsumer = new DMaaPPNFRegVESMsgConsumer(cfgTest.getCfg()); - try { - pnfRegMsgConsumer.processMsg(pnfRegMsg); - pnfRegMsgConsumer.processMsg(pnfRegMsg_SSH); - pnfRegMsgConsumer.processMsg(pnfRegMsg_TLS); - pnfRegMsgConsumer.processMsg(pnfRegMsg_OTHER); - } catch (Exception e) { - e.printStackTrace(); - System.out.println("Exception while processing PNF Registration Message - " + e.getMessage()); - } - } - - @Test - public void Test1() { - DMaaPPNFRegVESMsgConsumer pnfConsumer = new DMaaPPNFRegVESMsgConsumer(cfgTest.getCfg()); - System.out.println(pnfConsumer.getBaseUrl()); - System.out.println(pnfConsumer.getSDNRUser()); - System.out.println(pnfConsumer.getSDNRPasswd()); - } - -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPVESMsgConsumerMain.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPVESMsgConsumerMain.java deleted file mode 100644 index ecfb8d081..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPVESMsgConsumerMain.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * 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.assertNotNull; -import com.google.common.io.Files; -import java.io.File; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.junit.After; -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.*; - -public class TestDMaaPVESMsgConsumerMain { - - private static final String CONFIGURATIONFILE = "test1.properties"; - private static final String TESTCONFIG_GENERAL = "[general]\n" - + "dmaapEnabled=false\n" - + "baseUrl=http://localhost:8181\n" - + "sdnrUser=admin\n" - + "sdnrPasswd=admin\n" - + "\n" - + "[pnfRegistration]\n" - + "pnfRegConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.impl.DMaaPPNFRegVESMsgConsumer\n" - + "TransportType=HTTPNOAUTH\n" - + "host=onap-dmap:3904\n" - + "topic=unauthenticated.VES_PNFREG_OUTPUT\n" - + "contenttype=application/json\n" - + "group=myG\n" - + "id=C1\n" - + "timeout=20000\n" - + "limit=10000\n" - + "\n" - + "[fault]\n" - + "faultConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPFaultVESMsgConsumer.java\n" - + "TransportType=HTTPNOAUTH\n" - + "host=onap-dmap:3904\n" - + "topic=unauthenticated.SEC_FAULT_OUTPUT\n" - + "contenttype=application/json\n" - + "group=myG\n" - + "id=C1\n" - + "timeout=20000\n" - + "limit=10000\n" - + "fetchPause=10000\n" - + "\n" - + ""; - - private static final String TESTCONFIG_GENERAL_INVALID = "[general]\n" - + "dmaapEnabled=false\n" - + "baseUrl=http://localhost:8181\n" - + "sdnrUser=admin\n" - + "sdnrPasswd=admin\n" - + "\n" - + "[pnfRegistration]\n" - + "pnfRegConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPPNFRegVESMsgConsumer.java\n" - + "TransportType=HTTPNOAUTH\n" - + "host=onap-dmap:3904\n" - + "topic=unauthenticated.VES_PNFREG_OUTPUT\n" - + "contenttype=application/json\n" - + "group=myG\n" - + "id=C1\n" - + "timeout=20000\n" - + "limit=10000\n" - + "\n" - + "[fault]\n" - + "faultConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPFaultVESMsgConsumer.java\n" - + "TransportType=HTTPNOAUTH\n" - + "host=onap-dmap:3904\n" - + "topic=unauthenticated.SEC_FAULT_OUTPUT\n" - + "contenttype=application/json\n" - + "group=myG\n" - + "id=C1\n" - + "timeout=HELLO\n" - + "limit=10000\n" - + "fetchPause=WORLD\n" - + "\n" - + ""; - public GeneralConfig generalConfig; - Map configMap = new HashMap<>(); - DMaaPVESMsgConsumerMain dmaapMain; - - - public void preTest1() { - try { - Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_GENERAL); - ConfigurationFileRepresentation configFileRepresentation = - new ConfigurationFileRepresentation(CONFIGURATIONFILE); - - generalConfig = new GeneralConfig(configFileRepresentation); - PNFRegistrationConfig pnfRegConfig = new PNFRegistrationConfig(configFileRepresentation); - FaultConfig faultConfig = new FaultConfig(configFileRepresentation); - ProvisioningConfig provisioningConfig = new ProvisioningConfig(configFileRepresentation); - - configMap.put("pnfRegistration", pnfRegConfig); - configMap.put("fault", faultConfig); - configMap.put("provisioning", provisioningConfig); - } catch (Exception e) { - System.out.println("Failed in preTest execution " + e.getMessage()); - } - } - - public void preTest2() { - try { - Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_GENERAL_INVALID); - ConfigurationFileRepresentation configFileRepresentation = - new ConfigurationFileRepresentation(CONFIGURATIONFILE); - - generalConfig = new GeneralConfig(configFileRepresentation); - PNFRegistrationConfig pnfRegConfig = new PNFRegistrationConfig(configFileRepresentation); - FaultConfig faultConfig = new FaultConfig(configFileRepresentation); - ProvisioningConfig provisioningConfig = new ProvisioningConfig(configFileRepresentation); - - configMap.put("pnfRegistration", pnfRegConfig); - configMap.put("fault", faultConfig); - configMap.put("provisioning", provisioningConfig); - } catch (Exception e) { - System.out.println("Failed in preTest execution " + e.getMessage()); - } - } - - @Test - public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration() { - preTest1(); - assertNotNull(configMap); - dmaapMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig); - } - - @Test - public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration1() { - preTest2(); - assertNotNull(configMap); - dmaapMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig); - } - - @After - public void postTest() { - File file = new File(CONFIGURATIONFILE); - if (file.exists()) { - System.out.println("File exists, Deleting it"); - file.delete(); - } - List consumers = dmaapMain.getConsumers(); - for (DMaaPVESMsgConsumer consumer : consumers) { - // stop all consumers - consumer.stopConsumer(); - } - } -} - - diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestFaultConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestFaultConfig.java deleted file mode 100644 index 422d24935..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestFaultConfig.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH 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 com.google.common.io.Files; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import org.junit.After; -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.FaultConfig; - -public class TestFaultConfig { - - // @formatter:off - private static final String TESTCONFIG_CONTENT = "[fault]\n" - + "TransportType=HTTPNOAUTH\n" - + "Protocol=http\n" - + "username=username\n" - + "password=password\n" - + "host=onap-dmap:3904\n" - + "topic=unauthenticated.SEC_FAULT_OUTPUT\n" - + "contenttype=application/json\n" - + "group=myG\n" - + "id=C1\n" - + "timeout=20000\n" - + "limit=10000\n" - + "fetchPause=5000\n" - + "jersey.config.client.readTimeout=25000\n" - + "jersey.config.client.connectTimeout=25000\n" - + "jersey.config.client.proxy.uri=http://http-proxy\n" - + "jersey.config.client.proxy.username=proxy-user\n" - + "jersey.config.client.proxy.password=proxy-password\n" - + "\n" - + ""; - // @formatter:on - - private ConfigurationFileRepresentation cfg; - private static final String CONFIGURATIONFILE = "test2.properties"; - @Test - public void test() { - try { - Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); - cfg = new ConfigurationFileRepresentation(CONFIGURATIONFILE); - FaultConfig faultCfg = new FaultConfig(cfg); - assertEquals("fault", faultCfg.getSectionName()); - assertEquals("HTTPNOAUTH", faultCfg.getTransportType()); - assertEquals("onap-dmap:3904", faultCfg.getHostPort()); - assertEquals("unauthenticated.SEC_FAULT_OUTPUT", faultCfg.getTopic()); - assertEquals("application/json", faultCfg.getContenttype()); - assertEquals("myG", faultCfg.getConsumerGroup()); - assertEquals("C1", faultCfg.getConsumerId()); - assertEquals("20000", faultCfg.getTimeout()); - assertEquals("10000", faultCfg.getLimit()); - assertEquals("5000", faultCfg.getFetchPause()); - assertEquals("http", faultCfg.getProtocol()); - assertEquals("username", faultCfg.getUsername()); - assertEquals("password", faultCfg.getPassword()); - assertEquals("25000", faultCfg.getClientReadTimeout()); - assertEquals("25000", faultCfg.getClientConnectTimeout()); - assertEquals("http://http-proxy", faultCfg.getHTTPProxyURI()); - assertEquals("proxy-user", faultCfg.getHTTPProxyUsername()); - assertEquals("proxy-password", faultCfg.getHTTPProxyPassword()); - - } catch (IOException e) { - e.printStackTrace(); - } - } - - @After - public void cleanUp() { - File file = new File(CONFIGURATIONFILE); - if (file.exists()) { - System.out.println("File exists, Deleting it"); - file.delete(); - } - - } - -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestFaultNotificationClient.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestFaultNotificationClient.java deleted file mode 100644 index fa289aa4b..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestFaultNotificationClient.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * 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.io.IOException; -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.FaultNotificationClient; - -public class TestFaultNotificationClient extends FaultNotificationClient { - - public static String baseUrl = "http://localhost:8181"; - FaultNotificationClient testClient; - - - public TestFaultNotificationClient() { - super(baseUrl); - - } - - @Test - public void testFaultNotificationClient() { - testClient = new TestFaultNotificationClient(); - testClient.setAuthorization("admin", "admin"); - Map payloadMap = FaultNotificationClient.createFaultNotificationPayloadMap( - "TEST_50001", "1", "2019-11-20T09:25:19.948Z", - "SEDNKSAHQ01M01nSky01", "lossOfSignal", "Critical"); - String msg = testClient.prepareMessageFromPayloadMap(payloadMap); - assertTrue(testClient.sendNotification(msg)); - assertTrue(testClient.sendNotification(msg)); - } - - @Override - @Nonnull - public BaseHTTPResponse sendRequest(String uri, String method, String body, Map headers) - throws IOException { - System.out.println("In overridden sendRequest in TestFaultNotificationClient"); - return new BaseHTTPResponse(200, body); - } -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestGeneralConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestGeneralConfig.java deleted file mode 100644 index f73f3a5bf..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestGeneralConfig.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH 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 java.io.IOException; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.GeneralConfig; - -public class TestGeneralConfig { - - private static final String CONFIGURATIONFILE = "test1.properties"; - - private GeneralConfigForTest config; - - @Before - public void before() throws IOException { - config = new GeneralConfigForTest(CONFIGURATIONFILE); - } - - @Test - public void test() throws IOException { - GeneralConfig cfg = config.getCfg(); - - assertEquals(false, cfg.getEnabled()); - assertEquals("http://localhost:8181", cfg.getBaseUrl()); - assertEquals("admin", cfg.getSDNRUser()); - assertEquals("admin", cfg.getSDNRPasswd()); - assertEquals("general", cfg.getSectionName()); - } - - @After - public void cleanUp() { - config.close(); - } -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestPNFMountPointClient.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestPNFMountPointClient.java deleted file mode 100644 index 0858a7faa..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestPNFMountPointClient.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * 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.io.IOException; -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.PNFMountPointClient; - -public class TestPNFMountPointClient extends PNFMountPointClient { - - public static String baseUrl = "http://localhost:8181"; - PNFMountPointClient testClient; - - - public TestPNFMountPointClient() { - super(baseUrl); - - } - - @Test - public void testPNFMountPointClient() { - testClient = new TestPNFMountPointClient(); - testClient.setAuthorization("admin", "admin"); - Map payloadMap = PNFMountPointClient.createPNFNotificationPayloadMap( - "TEST 50001", "127.0.0.1", "17830", "TLS", - "admin", "admin", "key_id"); - String msg = testClient.prepareMessageFromPayloadMap(payloadMap); - - assertTrue(testClient.sendNotification(msg)); - assertTrue(testClient.sendNotification(msg)); - - } - - @Override - @Nonnull - public BaseHTTPResponse sendRequest(String uri, String method, String body, Map headers) - throws IOException { - System.out.println("In overridden sendRequest in TestPNFMountPointClient, uri = "+uri); - return new BaseHTTPResponse(200, body); - } - -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestProvisioningConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestProvisioningConfig.java deleted file mode 100644 index 42c204aec..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestProvisioningConfig.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * 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 com.google.common.io.Files; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; - -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.ProvisioningConfig; - -public class TestProvisioningConfig { - - private static final String TESTCONFIG_CONTENT = "[provisioning]\n" - + "TransportType=HTTPNOAUTH\n" - + "Protocol=http\n" - + "username=username\n" - + "password=password\n" - + "host=onap-dmap:3904\n" - + "topic=unauthenticated.SEC_3GPP_PROVISIONING_OUTPUT\n" - + "contenttype=application/json\n" - + "group=myG\n" - + "id=C1\n" - + "timeout=20000\n" - + "limit=10000\n" - + "fetchPause=5000\n" - + "jersey.config.client.readTimeout=25000\n" - + "jersey.config.client.connectTimeout=25000\n" - + "jersey.config.client.proxy.uri=http://http-proxy\n" - + "jersey.config.client.proxy.username=proxy-user\n" - + "jersey.config.client.proxy.password=proxy-password\n" - + ""; - - private static final String TEMP_DIR = System.getProperty("java.io.tmpdir"); - private static File configFile; - - @Test - public void testConfigValuesAssignment() throws IOException { - configFile = new File(TEMP_DIR, "test.properties"); - Files.asCharSink(configFile, StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); - ConfigurationFileRepresentation cfg = new ConfigurationFileRepresentation(configFile); - ProvisioningConfig provisioningConfig = new ProvisioningConfig(cfg); - assertEquals("provisioning", provisioningConfig.getSectionName()); - assertEquals("HTTPNOAUTH", provisioningConfig.getTransportType()); - assertEquals("onap-dmap:3904", provisioningConfig.getHostPort()); - assertEquals("unauthenticated.SEC_3GPP_PROVISIONING_OUTPUT", provisioningConfig.getTopic()); - assertEquals("application/json", provisioningConfig.getContenttype()); - assertEquals("myG", provisioningConfig.getConsumerGroup()); - assertEquals("C1", provisioningConfig.getConsumerId()); - assertEquals("20000", provisioningConfig.getTimeout()); - assertEquals("10000", provisioningConfig.getLimit()); - assertEquals("5000", provisioningConfig.getFetchPause()); - assertEquals("http", provisioningConfig.getProtocol()); - assertEquals("username", provisioningConfig.getUsername()); - assertEquals("password", provisioningConfig.getPassword()); - assertEquals("25000", provisioningConfig.getClientReadTimeout()); - assertEquals("25000", provisioningConfig.getClientConnectTimeout()); - assertEquals("http://http-proxy", provisioningConfig.getHTTPProxyURI()); - assertEquals("proxy-user", provisioningConfig.getHTTPProxyUsername()); - assertEquals("proxy-password", provisioningConfig.getHTTPProxyPassword()); - } - - @After - public void cleanUp() { - if (configFile.exists()) { - System.out.println(String.format("File %s exists, deleting it", configFile.getName())); - configFile.delete(); - } - } - -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestCMBasicHeaderFieldsNotification.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestCMBasicHeaderFieldsNotification.java new file mode 100644 index 000000000..5ad73e25c --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/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.client; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.cm.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/client/TestCMNotificationBuilder.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestCMNotificationBuilder.java new file mode 100644 index 000000000..9badc02cb --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/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.client; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.cm.CMBasicHeaderFieldsNotification; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.cm.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/client/TestCMNotificationClient.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestCMNotificationClient.java new file mode 100644 index 000000000..8cea25f1f --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/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.client; + +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.vesdomain.cm.CMBasicHeaderFieldsNotification; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.cm.CMNotification; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.cm.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 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/client/TestFaultNotificationClient.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestFaultNotificationClient.java new file mode 100644 index 000000000..a33970269 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestFaultNotificationClient.java @@ -0,0 +1,60 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * 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.client; + +import static org.junit.Assert.assertTrue; +import java.io.IOException; +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.vesdomain.fault.FaultNotificationClient; + +public class TestFaultNotificationClient extends FaultNotificationClient { + + public static String baseUrl = "http://localhost:8181"; + FaultNotificationClient testClient; + + + public TestFaultNotificationClient() { + super(baseUrl); + + } + + @Test + public void testFaultNotificationClient() { + testClient = new TestFaultNotificationClient(); + testClient.setAuthorization("admin", "admin"); + Map payloadMap = FaultNotificationClient.createFaultNotificationPayloadMap( + "TEST_50001", "1", "2019-11-20T09:25:19.948Z", + "SEDNKSAHQ01M01nSky01", "lossOfSignal", "Critical"); + String msg = testClient.prepareMessageFromPayloadMap(payloadMap); + assertTrue(testClient.sendNotification(msg)); + assertTrue(testClient.sendNotification(msg)); + } + + @Override + @Nonnull + public BaseHTTPResponse sendRequest(String uri, String method, String body, Map headers) + throws IOException { + System.out.println("In overridden sendRequest in TestFaultNotificationClient"); + return new BaseHTTPResponse(200, body); + } +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestPNFMountPointClient.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestPNFMountPointClient.java new file mode 100644 index 000000000..c43800044 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestPNFMountPointClient.java @@ -0,0 +1,63 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * 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.client; + +import static org.junit.Assert.assertTrue; +import java.io.IOException; +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.vesdomain.pnfreg.PNFMountPointClient; + +public class TestPNFMountPointClient extends PNFMountPointClient { + + public static String baseUrl = "http://localhost:8181"; + PNFMountPointClient testClient; + + + public TestPNFMountPointClient() { + super(baseUrl); + + } + + @Test + public void testPNFMountPointClient() { + testClient = new TestPNFMountPointClient(); + testClient.setAuthorization("admin", "admin"); + Map payloadMap = PNFMountPointClient.createPNFNotificationPayloadMap( + "TEST 50001", "127.0.0.1", "17830", "TLS", + "admin", "admin", "key_id"); + String msg = testClient.prepareMessageFromPayloadMap(payloadMap); + + assertTrue(testClient.sendNotification(msg)); + assertTrue(testClient.sendNotification(msg)); + + } + + @Override + @Nonnull + public BaseHTTPResponse sendRequest(String uri, String method, String body, Map headers) + throws IOException { + System.out.println("In overridden sendRequest in TestPNFMountPointClient, uri = "+uri); + return new BaseHTTPResponse(200, body); + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/GeneralConfigForTest.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/GeneralConfigForTest.java new file mode 100644 index 000000000..23c009a5b --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/GeneralConfigForTest.java @@ -0,0 +1,65 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2020 highstreet technologies GmbH 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.config; + +import com.google.common.io.Files; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.GeneralConfig; + +public class GeneralConfigForTest implements AutoCloseable { + + // @formatter:off + private static final String TESTCONFIG_CONTENT = "[general]\n" + + "baseUrl=http://localhost:8181\n" + + "sdnrUser=admin\n" + + "sdnrPasswd=admin\n" + + ""; + // @formatter:on + + private GeneralConfig cfg ; + private String filename; + + public GeneralConfigForTest(String filename) throws IOException { + + Files.asCharSink(new File(filename), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); + ConfigurationFileRepresentation globalCfg = new ConfigurationFileRepresentation(filename); + this.filename = filename; + this.cfg = new GeneralConfig(globalCfg); + + } + + public GeneralConfig getCfg() { + return cfg; + } + + + @Override + public + void close() { + File file = new File(filename); + if (file.exists()) { + System.out.println("File exists, Deleting it"); + file.delete(); + } + + } +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/PNFRegistrationConfigTest.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/PNFRegistrationConfigTest.java new file mode 100644 index 000000000..b76e71372 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/PNFRegistrationConfigTest.java @@ -0,0 +1,75 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH 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.config; + +import static org.junit.Assert.assertEquals; +import com.google.common.io.Files; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.junit.After; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.PNFRegistrationConfig; + +public class PNFRegistrationConfigTest { + + // @formatter:off + private static final String TESTCONFIG_CONTENT = "[pnfRegistration]\n" + + "topic=unauthenticated.VES_PNFREG_OUTPUT\n" + + "consumerGroup=myG\n" + + "consumerID=C1\n" + + "timeout=20000\n" + + "limit=10000\n" + + "fetchPause=5000\n" + + ""; + // @formatter:on + private ConfigurationFileRepresentation cfg; + private static final String configFile = "test.properties"; + + @Test + public void test() { + try { + Files.asCharSink(new File(configFile), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); + cfg = new ConfigurationFileRepresentation(configFile); + PNFRegistrationConfig pnfCfg = new PNFRegistrationConfig(cfg); + assertEquals("pnfRegistration", pnfCfg.getSectionName()); + assertEquals("unauthenticated.VES_PNFREG_OUTPUT", pnfCfg.getTopic()); + assertEquals("myG", pnfCfg.getConsumerGroup()); + assertEquals("C1", pnfCfg.getConsumerId()); + assertEquals("20000", pnfCfg.getTimeout()); + assertEquals("10000", pnfCfg.getLimit()); + assertEquals("5000", pnfCfg.getFetchPause()); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + @After + public void cleanUp() { + File file = new File(configFile); + if (file.exists()) { + System.out.println("File exists, Deleting it"); + file.delete(); + } + + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestFaultConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestFaultConfig.java new file mode 100644 index 000000000..8741370aa --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestFaultConfig.java @@ -0,0 +1,76 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH 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.config; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import com.google.common.io.Files; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.junit.After; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.FaultConfig; + +public class TestFaultConfig { + + // @formatter:off + private static final String TESTCONFIG_CONTENT = "[fault]\n" + + "topic=unauthenticated.SEC_FAULT_OUTPUT\n" + + "contenttype=application/json\n" + + "consumerGroup=myG\n" + + "consumerID=C1\n" + + "timeout=20000\n" + + "limit=10000\n" + + "fetchPause=5000\n" + + ""; + // @formatter:on + + private ConfigurationFileRepresentation cfg; + private static final String CONFIGURATIONFILE = "test2.properties"; + + @Test + public void test() { + try { + Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); + cfg = new ConfigurationFileRepresentation(CONFIGURATIONFILE); + FaultConfig faultCfg = new FaultConfig(cfg); + assertEquals("fault", faultCfg.getSectionName()); + assertEquals("unauthenticated.SEC_FAULT_OUTPUT", faultCfg.getTopic()); + assertEquals("myG", faultCfg.getConsumerGroup()); + assertEquals("C1", faultCfg.getConsumerId()); + assertEquals("20000", faultCfg.getTimeout()); + assertEquals("10000", faultCfg.getLimit()); + assertEquals("5000", faultCfg.getFetchPause()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @After + public void cleanUp() { + File file = new File(CONFIGURATIONFILE); + if (file.exists()) { + System.out.println("File exists, Deleting it"); + file.delete(); + } + + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestGeneralConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestGeneralConfig.java new file mode 100644 index 000000000..9324f794d --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestGeneralConfig.java @@ -0,0 +1,53 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH 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.config; + +import static org.junit.Assert.assertEquals; +import java.io.IOException; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.GeneralConfig; + +public class TestGeneralConfig { + + private static final String CONFIGURATIONFILE = "test1.properties"; + + private GeneralConfigForTest config; + + @Before + public void before() throws IOException { + config = new GeneralConfigForTest(CONFIGURATIONFILE); + } + + @Test + public void test() throws IOException { + GeneralConfig cfg = config.getCfg(); + + assertEquals("http://localhost:8181", cfg.getBaseUrl()); + assertEquals("admin", cfg.getSDNRUser()); + assertEquals("admin", cfg.getSDNRPasswd()); + assertEquals("general", cfg.getSectionName()); + } + + @After + public void cleanUp() { + config.close(); + } +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestProvisioningConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestProvisioningConfig.java new file mode 100644 index 000000000..0a1ab241b --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestProvisioningConfig.java @@ -0,0 +1,69 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * 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.config; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import com.google.common.io.Files; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.junit.After; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.ProvisioningConfig; + +public class TestProvisioningConfig { + + private static final String TESTCONFIG_CONTENT = "[provisioning]\n" + + + "topic=unauthenticated.SEC_3GPP_PROVISIONING_OUTPUT\n" + + "consumerGroup=myG\n" + + "consumerID=C1\n" + + "timeout=20000\n" + + "limit=10000\n" + + "fetchPause=5000\n" + + ""; + + private static final String TEMP_DIR = System.getProperty("java.io.tmpdir"); + private static File configFile; + + @Test + public void testConfigValuesAssignment() throws IOException { + configFile = new File(TEMP_DIR, "test.properties"); + Files.asCharSink(configFile, StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); + ConfigurationFileRepresentation cfg = new ConfigurationFileRepresentation(configFile); + ProvisioningConfig provisioningConfig = new ProvisioningConfig(cfg); + assertEquals("provisioning", provisioningConfig.getSectionName()); + assertEquals("unauthenticated.SEC_3GPP_PROVISIONING_OUTPUT", provisioningConfig.getTopic()); + assertEquals("myG", provisioningConfig.getConsumerGroup()); + assertEquals("C1", provisioningConfig.getConsumerId()); + assertEquals("20000", provisioningConfig.getTimeout()); + assertEquals("10000", provisioningConfig.getLimit()); + assertEquals("5000", provisioningConfig.getFetchPause()); + } + + @After + public void cleanUp() { + if (configFile.exists()) { + System.out.println(String.format("File %s exists, deleting it", configFile.getName())); + configFile.delete(); + } + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestStrimziKafkaConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestStrimziKafkaConfig.java new file mode 100644 index 000000000..b3546ea06 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestStrimziKafkaConfig.java @@ -0,0 +1,73 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH 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.config; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import com.google.common.io.Files; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.junit.After; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.StrimziKafkaConfig; + +public class TestStrimziKafkaConfig { + + // @formatter:off + private static final String TESTCONFIG_CONTENT = "[strimzi-kafka]\n" + + "strimziEnabled=false\n" + + "bootstrapServers=onap-strimzi-kafka-0:9094,onap-strimzi-kafka-1:9094\n" + + "securityProtocol=PLAINTEXT\n" + + "saslMechanism=PLAIN\n" + + "saslJaasConfig=PLAIN\n" + + ""; + // @formatter:on + + private ConfigurationFileRepresentation cfg; + private static final String CONFIGURATIONFILE = "test2.properties"; + + @Test + public void test() { + try { + Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); + cfg = new ConfigurationFileRepresentation(CONFIGURATIONFILE); + StrimziKafkaConfig sKafkaCfg = new StrimziKafkaConfig(cfg); + assertEquals("strimzi-kafka", sKafkaCfg.getSectionName()); + assertEquals("onap-strimzi-kafka-0:9094,onap-strimzi-kafka-1:9094", sKafkaCfg.getBootstrapServers()); + assertEquals("PLAINTEXT", sKafkaCfg.getSecurityProtocol()); + assertEquals(false, sKafkaCfg.getEnabled()); + assertEquals("PLAIN", sKafkaCfg.getSaslJaasConfig()); + assertEquals("PLAIN", sKafkaCfg.getSaslMechanism()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @After + public void cleanUp() { + File file = new File(CONFIGURATIONFILE); + if (file.exists()) { + System.out.println("File exists, Deleting it"); + file.delete(); + } + + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaCMVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaCMVESMsgConsumer.java new file mode 100644 index 000000000..c3beb29f7 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaCMVESMsgConsumer.java @@ -0,0 +1,239 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * 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.consumer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Iterator; +import java.util.Map; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.InvalidMessageException; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.config.GeneralConfigForTest; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.cm.StrimziKafkaCMVESMsgConsumer; + +public class TestStrimziKafkaCMVESMsgConsumer { + + private static final String CONFIGURATION_FILE = "cm_test.properties"; + private StrimziKafkaCMVESMsgConsumer sKafkaCMVESMsgConsumer; + private GeneralConfigForTest generalConfigForTest; + + @Before + public void setUp() throws Exception { + generalConfigForTest = new GeneralConfigForTest(CONFIGURATION_FILE); + sKafkaCMVESMsgConsumer = new StrimziKafkaCMVESMsgConsumer(generalConfigForTest.getCfg()); + } + + @Test + public void processValidMsg() throws URISyntaxException, IOException { + File cmFileValid = new File(TestStrimziKafkaCMVESMsgConsumer.class.getResource("/msgs/cm_valid.json").toURI()); + String cmEvent = readFileToString(cmFileValid); + try { + sKafkaCMVESMsgConsumer.processMsg(cmEvent); + } catch (Exception e) { + fail("Test fail with message: " + e.getMessage()); + } + } + + @Test(expected = InvalidMessageException.class) + public void processMsgThatMissesField() throws URISyntaxException, IOException, InvalidMessageException { + File cmFileInvalid = new File(TestStrimziKafkaCMVESMsgConsumer.class.getResource("/msgs/cm_invalid.json").toURI()); + String cmEvent = readFileToString(cmFileInvalid); + sKafkaCMVESMsgConsumer.processMsg(cmEvent); + } + + @Test(expected = InvalidMessageException.class) + public void processMsgThatHasInvalidNotificationType() + throws URISyntaxException, IOException, InvalidMessageException { + File cmFileInvalid = new File(TestStrimziKafkaCMVESMsgConsumer.class.getResource("/msgs/cm_invalid_type.json").toURI()); + String cmEvent = readFileToString(cmFileInvalid); + sKafkaCMVESMsgConsumer.processMsg(cmEvent); + } + + @Test(expected = JsonProcessingException.class) + public void processMsgThatIsNotValidJson() throws URISyntaxException, IOException, InvalidMessageException { + File cmFileInvalid = new File(TestStrimziKafkaCMVESMsgConsumer.class.getResource("/msgs/not_a_json.json").toURI()); + String cmEvent = readFileToString(cmFileInvalid); + sKafkaCMVESMsgConsumer.processMsg(cmEvent); + } + + @Test + public void processMsgWithOneElementMoiChangesArray() throws URISyntaxException, IOException { + File cmFileValid = new File(TestStrimziKafkaCMVESMsgConsumer.class.getResource("/msgs/cm_valid.json").toURI()); + String cmEvent = readFileToString(cmFileValid); + try { + JsonNode rootNode = convertMessageToJsonNode(cmEvent); + Iterator nodes = rootNode + .at("/event/stndDefinedFields/data/moiChanges") + .elements(); + Map payloadMap = + sKafkaCMVESMsgConsumer.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(TestStrimziKafkaCMVESMsgConsumer.class.getResource("/msgs/cm_valid_two_element_moi_changes_array.json") + .toURI()); + String cmEvent = readFileToString(cmFileValid); + try { + JsonNode rootNode = convertMessageToJsonNode(cmEvent); + Iterator nodes = rootNode + .at("/event/stndDefinedFields/data/moiChanges") + .elements(); + Map payloadMap = + sKafkaCMVESMsgConsumer.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 payloadMap2 = null; + while (nodes.hasNext()) { + payloadMap2 = sKafkaCMVESMsgConsumer.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(TestStrimziKafkaCMVESMsgConsumer.class.getResource("/msgs/cm_moi_creation.json").toURI()); + String cmEvent = readFileToString(cmFileValid); + try { + JsonNode rootNode = convertMessageToJsonNode(cmEvent); + Map payloadMap = sKafkaCMVESMsgConsumer.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(TestStrimziKafkaCMVESMsgConsumer.class.getResource("/msgs/cm_moi_deletion.json").toURI()); + String cmEvent = readFileToString(cmFileValid); + try { + JsonNode rootNode = convertMessageToJsonNode(cmEvent); + Map payloadMap = sKafkaCMVESMsgConsumer.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(TestStrimziKafkaCMVESMsgConsumer.class.getResource("/msgs/cm_moi_attribute_value_changes.json").toURI()); + String cmEvent = readFileToString(cmFileValid); + try { + JsonNode rootNode = convertMessageToJsonNode(cmEvent); + Map payloadMap = sKafkaCMVESMsgConsumer.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(); + } +} \ 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/consumer/TestStrimziKafkaFaultVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaFaultVESMsgConsumer.java new file mode 100644 index 000000000..912b73584 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaFaultVESMsgConsumer.java @@ -0,0 +1,150 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH 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.consumer; + +import java.io.IOException; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.config.GeneralConfigForTest; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.fault.StrimziKafkaFaultVESMsgConsumer; + +public class TestStrimziKafkaFaultVESMsgConsumer { + + private static final String DEFAULT_SDNRUSER = "admin"; + private static final String DEFAULT_SDNRPASSWD = "admin"; + private static final String DEFAULT_SDNRBASEURL = "http://localhost:8181"; + private static final String CONFIGURATIONFILE = "test2.properties"; + + // @formatter:off + private static final String faultVESMsg = "" + + "{\"event\":" + " {\"commonEventHeader\":" + + " { \"domain\":\"fault\"," + + " \"eventId\":\"1e9a28bcd119_50007_2019-11-20T14:59:47.3Z\"," + + " \"eventName\":\"fault_O_RAN_COMPONENT_Alarms\"," + + " \"eventType\":\"O_RAN_COMPONENT_Alarms\"," + + " \"sequence\":1," + + " \"priority\":\"Low\"," + + " \"reportingEntityId\":\"\"," + + " \"reportingEntityName\":\"1e9a28bcd119_50007\"," + + " \"sourceId\":\"\"," + + " \"sourceName\":\"1e9a28bcd119_50007\"," + + " \"startEpochMicrosec\":1614004128699785," + + " \"lastEpochMicrosec\":1614004128699785," + + " \"nfNamingCode\":\"sdn controller\"," + + " \"nfVendorName\":\"sdn\"," + + " \"timeZoneOffset\":\"+00:00\"," + + " \"version\":\"4.0.1\"," + + " \"vesEventListenerVersion\":\"7.0.1\"" + + " }," + + " \"faultFields\":" + + " {" + + " \"faultFieldsVersion\":\"4.0\"," + + " \"alarmCondition\":\"8\"," + + " \"alarmInterfaceA\":\"dkom32\"," + + " \"eventSourceType\":\"O_RAN_COMPONENT\"," + + " \"specificProblem\":\"dsonj32 don32 mdson32pk654\"," + + " \"eventSeverity\":\"@eventSeverity@\"," + + " \"vfStatus\":\"Active\"," + + " \"alarmAdditionalInformation\":" + + " {" + + " \"eventTime\":\"2019-11-20T14:59:47.3Z\"," + + " \"equipType\":\"O-RAN-sim\"," + + " \"vendor\":\"Melacon\"," + + " \"model\":\"Simulated Device\"" + + " }" + + " }" + + " }" + + "}"; + // @formatter:on + // @formatter:off + private static final String faultVESMsg_Incomplete = "" + + "{\"event\":" + + " {\"commonEventHeader\":" + + " { \"domain\":\"fault\"," + + " \"eventId\":\"1e9a28bcd119_50007_2019-11-20T14:59:47.3Z\"," + + " \"eventName\":\"fault_O_RAN_COMPONENT_Alarms\"," + + " \"eventType\":\"O_RAN_COMPONENT_Alarms\"," + + " \"sequence\":1," + + " \"priority\":\"Low\"," + + " \"reportingEntityId\":\"\"," + + " \"reportingEntityName\":\"1e9a28bcd119_50007\"," + + " \"sourceId\":\"\"," + + " \"sourceName\":\"1e9a28bcd119_50007\"," + + " \"startEpochMicrosec\":1612349525626," + + " \"lastEpochMicrosec\":1612349525626," + + " \"nfNamingCode\":\"sdn controller\"," + + " \"nfVendorName\":\"sdn\"," + + " \"timeZoneOffset\":\"+00:00\"," + + " \"version\":\"4.0.1\"," + + " \"vesEventListenerVersion\":\"7.0.1\"," + + " }," + + " \"faultFields\":" + + " {" + + " \"faultFieldsVersion\":\"4.0\"," + + " \"alarmCondition\":\"8\"," + + " \"alarmInterfaceA\":\"dkom32\"," + + " \"eventSourceType\":\"O_RAN_COMPONENT\"," + + " \"specificProblem\":\"dsonj32 don32 mdson32pk654\"," + + " \"eventSeverity\":\"CRITICAL\"," + + " \"vfStatus\":\"Active\"," + + " \"alarmAdditionalInformation\":" + + " {" + + " \"eventTime\":\"2019-11-20T14:59:47.3Z\"," + + " \"equipType\":\"O-RAN-sim\"," + + " \"vendor\":\"Melacon\"," + + " \"model\":\"Simulated Device\"" + + " }" + + " }" + + " }" + + "}"; + // @formatter:on + + private GeneralConfigForTest cfgTest; + + @Before + public void before() throws IOException { + cfgTest = new GeneralConfigForTest(CONFIGURATIONFILE); + } + + @After + public void after() { + cfgTest.close(); + } + + + @Test + public void test() throws IOException { + StrimziKafkaFaultVESMsgConsumer faultMsgConsumer = new StrimziKafkaFaultVESMsgConsumer(cfgTest.getCfg()); + try { + + faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "CRITICAL")); + faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "Major")); + faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "minor")); + faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "NonAlarmed")); + faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "warning")); + faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "Unknown")); + faultMsgConsumer.processMsg(faultVESMsg_Incomplete); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("Exception while processing Fault Message - " + e.getMessage()); + } + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaPNFRegVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaPNFRegVESMsgConsumer.java new file mode 100644 index 000000000..20b6c4ae7 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaPNFRegVESMsgConsumer.java @@ -0,0 +1,271 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH 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.consumer; + +import java.io.IOException; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.config.GeneralConfigForTest; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.pnfreg.StrimziKafkaPNFRegVESMsgConsumer; + +public class TestStrimziKafkaPNFRegVESMsgConsumer { + + private static final String DEFAULT_SDNRUSER = "admin"; + private static final String DEFAULT_SDNRPASSWD = "admin"; + private static final String DEFAULT_SDNRBASEURL = "http://localhost:8181"; + private static final String CONFIGURATIONFILE = "test4.properties"; + + // @formatter:off + private static final String pnfRegMsg_TLS = "{\n" + + " \"event\": {\n" + + " \"commonEventHeader\": {\n" + + " \"domain\": \"pnfRegistration\",\n" + + " \"eventId\": \"NSHMRIACQ01M01123401_1234 BestInClass\",\n" + + " \"eventName\": \"pnfRegistration_EventType5G\",\n" + + " \"eventType\": \"EventType5G\",\n" + + " \"sequence\": 0,\n" + + " \"priority\": \"Low\",\n" + + " \"reportingEntityId\": \"\",\n" + + " \"reportingEntityName\": \"pendurty-virtual-machine\",\n" + + " \"sourceId\": \"\",\n" + + " \"sourceName\": \"NSHMRIACQ01M01123401\",\n" + + " \"startEpochMicrosec\": 1571300004203,\n" + + " \"lastEpochMicrosec\": 1571300004203,\n" + + " \"nfNamingCode\": \"1234\",\n" + + " \"nfVendorName\": \"VENDORA\",\n" + + " \"timeZoneOffset\": \"+00:00\",\n" + + " \"version\": \"4.0.1\",\n" + + " \"vesEventListenerVersion\":\"7.0.1\"\n" + + " },\n" + + " \"pnfRegistrationFields\": {\n" + + " \"pnfRegistrationFieldsVersion\": \"2.0\",\n" + + " \"additionalFields\": \n" + + " { \n" + + " \"protocol\":\"TLS\",\n" + + " \"keyId\":\"netconf\",\n" + + " \"oamPort\":\"50000\",\n" + + " \"betweenAttemptsTimeout\":\"2000\",\n" + + " \"keepaliveDelay\":\"120\",\n" + + " \"sleep-factor\":\"1.5\",\n" + + " \"reconnectOnChangedSchema\":\"false\",\n" + + " \"connectionTimeout\":\"20000\",\n" + + " \"maxConnectionAttempts\":\"100\",\n" + + " \"username\":\"netconf\",\n" + + " \"tcpOnly\":\"false\"\n" + + " },\n" + + " \"lastServiceDate\":\"2019-08-16\",\n" + + " \"macAddress\":\"02:42:f7:d4:62:ce\",\n" + + " \"manufactureDate\":\"2019-08-16\",\n" + + " \"modelNumbsdnrer\": \"1234 BestInClass\",\n" + + " \"oamV4IpAddress\": \"10.10.10.11\",\n" + + " \"oamPort\":\"17380\",\n" + + " \"oamV6IpAddress\": \"0:0:0:0:0:ffff:a0a:011\",\n" + + " \"serialNumber\": \"VENDORA-1234-10.10.10.11-1234 BestInClass\",\n" + + " \"softwareVersion\": \"2.3.5\",\n" + + " \"unitFamily\": \"VENDORA-1234\",\n" + + " \"unitType\": \"1234\",\n" + + " \"vendorName\": \"VENDORA\"\n" + + " }\n" + + " }\n" + + "}\n" + + ""; + private static final String pnfRegMsg_SSH = "{\n" + + " \"event\": {\n" + + " \"commonEventHeader\": {\n" + + " \"domain\": \"pnfRegistration\",\n" + + " \"eventId\": \"NSHMRIACQ01M01123401_1234 BestInClass\",\n" + + " \"eventName\": \"pnfRegistration_EventType5G\",\n" + + " \"eventType\": \"EventType5G\",\n" + + " \"sequence\": 0,\n" + + " \"priority\": \"Low\",\n" + + " \"reportingEntityId\": \"\",\n" + + " \"reportingEntityName\": \"pendurty-virtual-machine\",\n" + + " \"sourceId\": \"\",\n" + + " \"sourceName\": \"NSHMRIACQ01M01123401\",\n" + + " \"startEpochMicrosec\": 1571300004203,\n" + + " \"lastEpochMicrosec\": 1571300004203,\n" + + " \"nfNamingCode\": \"1234\",\n" + + " \"nfVendorName\": \"VENDORA\",\n" + + " \"timeZoneOffset\": \"+00:00\",\n" + + " \"version\": \"4.0.1\",\n" + + " \"vesEventListenerVersion\":\"7.0.1\"\n" + + " },\n" + + " \"pnfRegistrationFields\": {\n" + + " \"pnfRegistrationFieldsVersion\": \"2.0\",\n" + + " \"additionalFields\": \n" + + " { \n" + + " \"protocol\":\"SSH\",\n" + + " \"password\":\"netconf\",\n" + + " \"oamPort\":\"50000\",\n" + + " \"betweenAttemptsTimeout\":\"2000\",\n" + + " \"keepaliveDelay\":\"120\",\n" + + " \"sleep-factor\":\"1.5\",\n" + + " \"reconnectOnChangedSchema\":\"false\",\n" + + " \"connectionTimeout\":\"20000\",\n" + + " \"maxConnectionAttempts\":\"100\",\n" + + " \"username\":\"netconf\",\n" + + " \"tcpOnly\":\"false\"\n" + + " },\n" + + " \"lastServiceDate\":\"2019-08-16\",\n" + + " \"macAddress\":\"02:42:f7:d4:62:ce\",\n" + + " \"manufactureDate\":\"2019-08-16\",\n" + + " \"modelNumbsdnrer\": \"1234 BestInClass\",\n" + + " \"oamV4IpAddress\": \"10.10.10.11\",\n" + + " \"oamPort\":\"17380\",\n" + + " \"oamV6IpAddress\": \"0:0:0:0:0:ffff:a0a:011\",\n" + + " \"serialNumber\": \"VENDORA-1234-10.10.10.11-1234 BestInClass\",\n" + + " \"softwareVersion\": \"2.3.5\",\n" + + " \"unitFamily\": \"VENDORA-1234\",\n" + + " \"unitType\": \"1234\",\n" + + " \"vendorName\": \"VENDORA\"\n" + + " }\n" + + " }\n" + + "}\n" + + ""; + private static final String pnfRegMsg_OTHER = "{\n" + + " \"event\": {\n" + + " \"commonEventHeader\": {\n" + + " \"domain\": \"pnfRegistration\",\n" + + " \"eventId\": \"NSHMRIACQ01M01123401_1234 BestInClass\",\n" + + " \"eventName\": \"pnfRegistration_EventType5G\",\n" + + " \"eventType\": \"EventType5G\",\n" + + " \"sequence\": 0,\n" + + " \"priority\": \"Low\",\n" + + " \"reportingEntityId\": \"\",\n" + + " \"reportingEntityName\": \"pendurty-virtual-machine\",\n" + + " \"sourceId\": \"\",\n" + + " \"sourceName\": \"NSHMRIACQ01M01123401\",\n" + + " \"startEpochMicrosec\": 1571300004203,\n" + + " \"lastEpochMicrosec\": 1571300004203,\n" + + " \"nfNamingCode\": \"1234\",\n" + + " \"nfVendorName\": \"VENDORA\",\n" + + " \"timeZoneOffset\": \"+00:00\",\n" + + " \"version\": \"4.0.1\",\n" + + " \"vesEventListenerVersion\":\"7.0.1\"\n" + + " },\n" + + " \"pnfRegistrationFields\": {\n" + + " \"pnfRegistrationFieldsVersion\": \"2.0\",\n" + + " \"additionalFields\": \n" + + " { \n" + + " \"protocol\":\"OTHER\",\n" + + " \"password\":\"netconf\",\n" + + " \"oamPort\":\"50000\",\n" + + " \"betweenAttemptsTimeout\":\"2000\",\n" + + " \"keepaliveDelay\":\"120\",\n" + + " \"sleep-factor\":\"1.5\",\n" + + " \"reconnectOnChangedSchema\":\"false\",\n" + + " \"connectionTimeout\":\"20000\",\n" + + " \"maxConnectionAttempts\":\"100\",\n" + + " \"username\":\"netconf\",\n" + + " \"tcpOnly\":\"false\"\n" + + " },\n" + + " \"lastServiceDate\":\"2019-08-16\",\n" + + " \"macAddress\":\"02:42:f7:d4:62:ce\",\n" + + " \"manufactureDate\":\"2019-08-16\",\n" + + " \"modelNumbsdnrer\": \"1234 BestInClass\",\n" + + " \"oamV4IpAddress\": \"10.10.10.11\",\n" + + " \"oamPort\":\"17380\",\n" + + " \"oamV6IpAddress\": \"0:0:0:0:0:ffff:a0a:011\",\n" + + " \"serialNumber\": \"VENDORA-1234-10.10.10.11-1234 BestInClass\",\n" + + " \"softwareVersion\": \"2.3.5\",\n" + + " \"unitFamily\": \"VENDORA-1234\",\n" + + " \"unitType\": \"1234\",\n" + + " \"vendorName\": \"VENDORA\"\n" + + " }\n" + + " }\n" + + "}\n" + + ""; + private static final String pnfRegMsg = "{\n" + + " \"event\": {\n" + + " \"commonEventHeader\": {\n" + + " \"domain\": \"pnfRegistration\",\n" + + " \"eventId\": \"NSHMRIACQ01M01123401_1234 BestInClass\",\n" + + " \"eventName\": \"pnfRegistration_EventType5G\",\n" + + " \"eventType\": \"EventType5G\",\n" + + " \"sequence\": 0,\n" + + " \"priority\": \"Low\",\n" + + " \"reportingEntityId\": \"\",\n" + + " \"reportingEntityName\": \"pendurty-virtual-machine\",\n" + + " \"sourceId\": \"\",\n" + + " \"sourceName\": \"NSHMRIACQ01M01123401\",\n" + + " \"startEpochMicrosec\": 1571300004203,\n" + + " \"lastEpochMicrosec\": 1571300004203,\n" + + " \"nfNamingCode\": \"1234\",\n" + + " \"nfVendorName\": \"VENDORA\",\n" + + " \"timeZoneOffset\": \"+00:00\",\n" + + " \"version\": \"4.0.1\",\n" + + " \"vesEventListenerVersion\":\"7.0.1\"\n" + + " },\n" + + " \"pnfRegistrationFields\": {\n" + + " \"pnfRegistrationFieldsVersion\": \"2.0\",\n" + + " \"lastServiceDate\":\"2019-08-16\",\n" + + " \"macAddress\":\"02:42:f7:d4:62:ce\",\n" + + " \"manufactureDate\":\"2019-08-16\",\n" + + " \"modelNumbsdnrer\": \"1234 BestInClass\",\n" + + " \"oamV4IpAddress\": \"10.10.10.11\",\n" + + " \"oamPort\":\"17380\",\n" + //+ " \"oamV6IpAddress\": \"\",\n" + + " \"serialNumber\": \"VENDORA-1234-10.10.10.11-1234 BestInClass\",\n" + + " \"softwareVersion\": \"2.3.5\",\n" + + " \"unitFamily\": \"VENDORA-1234\",\n" + + " \"unitType\": \"1234\",\n" + + " \"vendorName\": \"VENDORA\"\n" + + " }\n" + + " }\n" + + "}\n" + + ""; + // @formatter:on + + private GeneralConfigForTest cfgTest; + + @Before + public void before() throws IOException { + cfgTest = new GeneralConfigForTest(CONFIGURATIONFILE); + } + + @After + public void after() { + cfgTest.close(); + } + + @Test + public void processMsgTest() { + + StrimziKafkaPNFRegVESMsgConsumer pnfRegMsgConsumer = new StrimziKafkaPNFRegVESMsgConsumer(cfgTest.getCfg()); + try { + pnfRegMsgConsumer.processMsg(pnfRegMsg); + pnfRegMsgConsumer.processMsg(pnfRegMsg_SSH); + pnfRegMsgConsumer.processMsg(pnfRegMsg_TLS); + pnfRegMsgConsumer.processMsg(pnfRegMsg_OTHER); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("Exception while processing PNF Registration Message - " + e.getMessage()); + } + } + + @Test + public void Test1() { + StrimziKafkaPNFRegVESMsgConsumer pnfConsumer = new StrimziKafkaPNFRegVESMsgConsumer(cfgTest.getCfg()); + System.out.println(pnfConsumer.getBaseUrl()); + System.out.println(pnfConsumer.getSDNRUser()); + System.out.println(pnfConsumer.getSDNRPasswd()); + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaStndDefinedVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaStndDefinedVESMsgConsumer.java new file mode 100644 index 000000000..0185bf687 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaStndDefinedVESMsgConsumer.java @@ -0,0 +1,239 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2023 highstreet technologies GmbH 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.consumer; + +import com.fasterxml.jackson.core.JsonProcessingException; +import java.io.IOException; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.InvalidMessageException; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.config.GeneralConfigForTest; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.stnddefined.StrimziKafkaStndDefinedFaultVESMsgConsumer; + +public class TestStrimziKafkaStndDefinedVESMsgConsumer { + + private static final String CONFIGURATIONFILE = "test2.properties"; + + // @formatter:off + private static final String stndDefinedVESMsg_NotifyNewAlarm = + "{\n" + + " \"event\": {\n" + + " \"commonEventHeader\": {\n" + + " \"startEpochMicrosec\": 1669022429000000,\n" + + " \"eventId\": \"stndDefined000000001\",\n" + + " \"timeZoneOffset\": \"+00:00\",\n" + + " \"internalHeaderFields\": {\n" + + " \"collectorTimeStamp\": \"Mon, 11 21 2022 09:20:30 UTC\"\n" + + " },\n" + + " \"eventType\": \"5GCell-NodeH_Alarms\",\n" + + " \"priority\": \"Low\",\n" + + " \"version\": \"4.1\",\n" + + " \"nfVendorName\": \"NodeH\",\n" + + " \"reportingEntityName\": \"NodeH-5GCell-1234\",\n" + + " \"sequence\": 5,\n" + + " \"domain\": \"stndDefined\",\n" + + " \"lastEpochMicrosec\": 1669022429000000,\n" + + " \"eventName\": \"StndDefined_5GCell-NodeH_Alarms_MyAlarm\",\n" + + " \"vesEventListenerVersion\": \"7.2.1\",\n" + + " \"sourceName\": \"NodeH-5GCell-1234\",\n" + + " \"stndDefinedNamespace\": \"3GPP-FaultSupervision\",\n" + + " \"nfNamingCode\": \"5GCell\"\n" + + " },\n" + + " \"stndDefinedFields\": {\n" + + " \"stndDefinedFieldsVersion\": \"1.0\",\n" + + " \"data\": {\n" + + " \"additionalInformation\": {\n" + + " \"equipType\": \"5GCell\",\n" + + " \"vendor\": \"NodeH\",\n" + + " \"eventTime\": \"2022-11-21T09:20:29Z\",\n" + + " \"model\": \"SF1234\"\n" + + " },\n" + + " \"backedUpStatus\": false,\n" + + " \"rootCauseIndicator\": false,\n" + + " \"notificationType\": \"notifyNewAlarm\",\n" + + " \"systemDN\": \"DC=com.Node-H,CN=5GCell\",\n" + + " \"alarmType\": \"COMMUNICATIONS_ALARM\",\n" + + " \"probableCause\": \"My cause\",\n" + + " \"perceivedSeverity\": \"@eventSeverity@\",\n" + + " \"eventTime\": \"2022-11-21T09:20:29Z\",\n" + + " \"alarmId\": \"MyAlarm\",\n" + + " \"proposedRepairActions\": \"Repair me\",\n" + + " \"notificationId\": 0,\n" + + " \"href\": \"http://10.0.33.23/3GPPManagement/FaultSupervisionMnS/17.1.0\"\n" + + " },\n" + + " \"schemaReference\": \"https://forge.3gpp.org/rep/sa5/MnS/-/blob/Rel-18/OpenAPI/TS28532_FaultMnS.yaml#components/schemas/NotifyNewAlarm\"\n" + + " }\n" + + " }\n" + + "}"; + // @formatter:on + // @formatter:off + private static final String stndDefinedVESMsg_NotifyClearedAlarm = "{\n" + + " \"event\": {\n" + + " \"commonEventHeader\": {\n" + + " \"startEpochMicrosec\": 1669022429000000,\n" + + " \"eventId\": \"stndDefined000000001\",\n" + + " \"timeZoneOffset\": \"+00:00\",\n" + + " \"internalHeaderFields\": {\n" + + " \"collectorTimeStamp\": \"Mon, 11 21 2022 09:20:30 UTC\"\n" + + " },\n" + + " \"eventType\": \"5GCell-NodeH_Alarms\",\n" + + " \"priority\": \"Low\",\n" + + " \"version\": \"4.1\",\n" + + " \"nfVendorName\": \"NodeH\",\n" + + " \"reportingEntityName\": \"NodeH-5GCell-1234\",\n" + + " \"sequence\": 5,\n" + + " \"domain\": \"stndDefined\",\n" + + " \"lastEpochMicrosec\": 1669022429000000,\n" + + " \"eventName\": \"StndDefined_5GCell-NodeH_Alarms_MyAlarm\",\n" + + " \"vesEventListenerVersion\": \"7.2.1\",\n" + + " \"sourceName\": \"NodeH-5GCell-1234\",\n" + + " \"stndDefinedNamespace\": \"3GPP-FaultSupervision\",\n" + + " \"nfNamingCode\": \"5GCell\"\n" + + " },\n" + + " \"stndDefinedFields\": {\n" + + " \"stndDefinedFieldsVersion\": \"1.0\",\n" + + " \"data\": {\n" + + " \"additionalInformation\": {\n" + + " \"equipType\": \"5GCell\",\n" + + " \"vendor\": \"NodeH\",\n" + + " \"eventTime\": \"2022-11-21T09:20:29Z\",\n" + + " \"model\": \"SF1234\"\n" + + " },\n" + + " \"backedUpStatus\": false,\n" + + " \"rootCauseIndicator\": false,\n" + + " \"notificationType\": \"notifyClearedAlarm\",\n" + + " \"systemDN\": \"DC=com.Node-H,CN=5GCell\",\n" + + " \"alarmType\": \"COMMUNICATIONS_ALARM\",\n" + + " \"probableCause\": \"My cause\",\n" + + " \"perceivedSeverity\": \"@eventSeverity@\",\n" + + " \"eventTime\": \"2022-11-21T09:20:29Z\",\n" + + " \"alarmId\": \"MyAlarm\",\n" + + " \"proposedRepairActions\": \"Repair me\",\n" + + " \"notificationId\": 0,\n" + + " \"href\": \"http://10.0.33.23/3GPPManagement/FaultSupervisionMnS/17.1.0\"\n" + + " },\n" + + " \"schemaReference\": \"https://forge.3gpp.org/rep/sa5/MnS/-/blob/Rel-18/OpenAPI/TS28532_FaultMnS.yaml#components/schemas/NotifyClearedAlarm\"\n" + + " }\n" + + " }\n" + + "}"; + // @formatter:on + + // @formatter:off + private static final String stndDefinedVESMsg_Invalid = "{\n" + + " \"event\": {\n" + + " \"commonEventHeader\": {\n" + + " \"startEpochMicrosec\": 1669022429000000,\n" + + " \"eventId\": \"stndDefined000000001\",\n" + + " \"timeZoneOffset\": \"+00:00\",\n" + + " \"internalHeaderFields\": {\n" + + " \"collectorTimeStamp\": \"Mon, 11 21 2022 09:20:30 UTC\"\n" + + " },\n" + + " \"eventType\": \"5GCell-NodeH_Alarms\",\n" + + " \"priority\": \"Low\",\n" + + " \"version\": \"4.1\",\n" + + " \"nfVendorName\": \"NodeH\",\n" + + " \"reportingEntityName\": \"NodeH-5GCell-1234\",\n" + + " \"sequence\": 5,\n" + + " \"domain\": \"stndDefined\",\n" + + " \"lastEpochMicrosec\": 1669022429000000,\n" + + " \"eventName\": \"StndDefined_5GCell-NodeH_Alarms_MyAlarm\",\n" + + " \"vesEventListenerVersion\": \"7.2.1\",\n" + + " \"sourceName\": \"NodeH-5GCell-1234\",\n" + + " \"stndDefinedNamespace\": \"3GPP-FaultSupervision\",\n" + + " \"nfNamingCode\": \"5GCell\"\n" + + " },\n" + + " \"stndDefinedFields\": {\n" + + " \"stndDefinedFieldsVersion\": \"1.0\",\n" + + " \"data\": {\n" + + " \"additionalInformation\": {\n" + + " \"equipType\": \"5GCell\",\n" + + " \"vendor\": \"NodeH\",\n" + + " \"eventTime\": \"2022-11-21T09:20:29Z\",\n" + + " \"model\": \"SF1234\"\n" + + " },\n" + + " \"backedUpStatus\": false,\n" + + " \"rootCauseIndicator\": false,\n" + + " \"notificationType\": \"notifyChangedAlarm\",\n" + + " \"systemDN\": \"DC=com.Node-H,CN=5GCell\",\n" + + " \"alarmType\": \"COMMUNICATIONS_ALARM\",\n" + + " \"probableCause\": \"My cause\",\n" + + " \"perceivedSeverity\": \"@eventSeverity@\",\n" + + " \"eventTime\": \"2022-11-21T09:20:29Z\",\n" + + " \"alarmId\": \"MyAlarm\",\n" + + " \"proposedRepairActions\": \"Repair me\",\n" + + " \"notificationId\": 0,\n" + + " \"href\": \"http://10.0.33.23/3GPPManagement/FaultSupervisionMnS/17.1.0\"\n" + + " },\n" + + " \"schemaReference\": \"https://forge.3gpp.org/rep/sa5/MnS/-/blob/Rel-18/OpenAPI/TS28532_FaultMnS.yaml#components/schemas/NotifyClearedAlarm\"\n" + + " }\n" + + " }\n" + + "}"; + // @formatter:on + private GeneralConfigForTest cfgTest; + + @Before + public void before() throws IOException { + cfgTest = new GeneralConfigForTest(CONFIGURATIONFILE); + } + + @After + public void after() { + cfgTest.close(); + } + + + @Test + public void testNotifyNewAlarm() throws IOException { + StrimziKafkaStndDefinedFaultVESMsgConsumer stndDefinedFaultMsgConsumer = new StrimziKafkaStndDefinedFaultVESMsgConsumer(cfgTest.getCfg()); + try { + + stndDefinedFaultMsgConsumer.processMsg(stndDefinedVESMsg_NotifyNewAlarm.replace("@eventSeverity@", "CRITICAL")); + stndDefinedFaultMsgConsumer.processMsg(stndDefinedVESMsg_NotifyNewAlarm.replace("@eventSeverity@", "Major")); + stndDefinedFaultMsgConsumer.processMsg(stndDefinedVESMsg_NotifyNewAlarm.replace("@eventSeverity@", "minor")); + stndDefinedFaultMsgConsumer.processMsg(stndDefinedVESMsg_NotifyNewAlarm.replace("@eventSeverity@", "NonAlarmed")); + stndDefinedFaultMsgConsumer.processMsg(stndDefinedVESMsg_NotifyNewAlarm.replace("@eventSeverity@", "warning")); + stndDefinedFaultMsgConsumer.processMsg(stndDefinedVESMsg_NotifyNewAlarm.replace("@eventSeverity@", "Unknown")); + //stndDefinedFaultMsgConsumer.processMsg(faultVESMsg_Incomplete); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("Exception while processing Fault Message - " + e.getMessage()); + } + } + + @Test + public void testNotifyClearedAlarm() throws IOException { + StrimziKafkaStndDefinedFaultVESMsgConsumer stndDefinedFaultMsgConsumer = new StrimziKafkaStndDefinedFaultVESMsgConsumer(cfgTest.getCfg()); + try { + + stndDefinedFaultMsgConsumer.processMsg(stndDefinedVESMsg_NotifyClearedAlarm.replace("@eventSeverity@", "cleared")); + stndDefinedFaultMsgConsumer.processMsg(stndDefinedVESMsg_NotifyClearedAlarm.replace("@eventSeverity@", "Indeterminate")); + //stndDefinedFaultMsgConsumer.processMsg(faultVESMsg_Incomplete); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("Exception while processing Fault Message - " + e.getMessage()); + } + } + + @Test(expected = InvalidMessageException.class) + public void testInvalidStndDefinedMessage() throws InvalidMessageException, JsonProcessingException { + StrimziKafkaStndDefinedFaultVESMsgConsumer stndDefinedFaultMsgConsumer = new StrimziKafkaStndDefinedFaultVESMsgConsumer(cfgTest.getCfg()); + stndDefinedFaultMsgConsumer.processMsg(stndDefinedVESMsg_Invalid.replace("@eventSeverity@", "cleared")); + } +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaVESMsgConsumerMain.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaVESMsgConsumerMain.java new file mode 100644 index 000000000..d218d0d6f --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaVESMsgConsumerMain.java @@ -0,0 +1,175 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * 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.consumer; + +import static org.junit.Assert.assertNotNull; +import com.google.common.io.Files; +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.After; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.FaultConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.GeneralConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.MessageConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.PNFRegistrationConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.ProvisioningConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.*; + +public class TestStrimziKafkaVESMsgConsumerMain { + + private static final String CONFIGURATIONFILE = "test1.properties"; + private static final String TESTCONFIG_GENERAL = "[general]\n" + + "dmaapEnabled=false\n" + + "baseUrl=http://localhost:8181\n" + + "sdnrUser=admin\n" + + "sdnrPasswd=admin\n" + + "\n" + + "[pnfRegistration]\n" + + "pnfRegConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.impl.DMaaPPNFRegVESMsgConsumer\n" + + "TransportType=HTTPNOAUTH\n" + + "host=onap-dmap:3904\n" + + "topic=unauthenticated.VES_PNFREG_OUTPUT\n" + + "contenttype=application/json\n" + + "group=myG\n" + + "id=C1\n" + + "timeout=20000\n" + + "limit=10000\n" + + "\n" + + "[fault]\n" + + "faultConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPFaultVESMsgConsumer.java\n" + + "TransportType=HTTPNOAUTH\n" + + "host=onap-dmap:3904\n" + + "topic=unauthenticated.SEC_FAULT_OUTPUT\n" + + "contenttype=application/json\n" + + "group=myG\n" + + "id=C1\n" + + "timeout=20000\n" + + "limit=10000\n" + + "fetchPause=10000\n" + + "\n" + + ""; + + private static final String TESTCONFIG_GENERAL_INVALID = "[general]\n" + + "dmaapEnabled=false\n" + + "baseUrl=http://localhost:8181\n" + + "sdnrUser=admin\n" + + "sdnrPasswd=admin\n" + + "\n" + + "[pnfRegistration]\n" + + "pnfRegConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPPNFRegVESMsgConsumer.java\n" + + "TransportType=HTTPNOAUTH\n" + + "host=onap-dmap:3904\n" + + "topic=unauthenticated.VES_PNFREG_OUTPUT\n" + + "contenttype=application/json\n" + + "group=myG\n" + + "id=C1\n" + + "timeout=20000\n" + + "limit=10000\n" + + "\n" + + "[fault]\n" + + "faultConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPFaultVESMsgConsumer.java\n" + + "TransportType=HTTPNOAUTH\n" + + "host=onap-dmap:3904\n" + + "topic=unauthenticated.SEC_FAULT_OUTPUT\n" + + "contenttype=application/json\n" + + "group=myG\n" + + "id=C1\n" + + "timeout=HELLO\n" + + "limit=10000\n" + + "fetchPause=WORLD\n" + + "\n" + + ""; + public GeneralConfig generalConfig; + Map configMap = new HashMap<>(); + StrimziKafkaVESMsgConsumerMain dmaapMain; + + + public void preTest1() { + try { + Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_GENERAL); + ConfigurationFileRepresentation configFileRepresentation = + new ConfigurationFileRepresentation(CONFIGURATIONFILE); + + generalConfig = new GeneralConfig(configFileRepresentation); + PNFRegistrationConfig pnfRegConfig = new PNFRegistrationConfig(configFileRepresentation); + FaultConfig faultConfig = new FaultConfig(configFileRepresentation); + ProvisioningConfig provisioningConfig = new ProvisioningConfig(configFileRepresentation); + + configMap.put("pnfRegistration", pnfRegConfig); + configMap.put("fault", faultConfig); + configMap.put("provisioning", provisioningConfig); + } catch (Exception e) { + System.out.println("Failed in preTest execution " + e.getMessage()); + } + } + + public void preTest2() { + try { + Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_GENERAL_INVALID); + ConfigurationFileRepresentation configFileRepresentation = + new ConfigurationFileRepresentation(CONFIGURATIONFILE); + + generalConfig = new GeneralConfig(configFileRepresentation); + PNFRegistrationConfig pnfRegConfig = new PNFRegistrationConfig(configFileRepresentation); + FaultConfig faultConfig = new FaultConfig(configFileRepresentation); + ProvisioningConfig provisioningConfig = new ProvisioningConfig(configFileRepresentation); + + configMap.put("pnfRegistration", pnfRegConfig); + configMap.put("fault", faultConfig); + configMap.put("provisioning", provisioningConfig); + } catch (Exception e) { + System.out.println("Failed in preTest execution " + e.getMessage()); + } + } + + @Test + public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration() { + preTest1(); + assertNotNull(configMap); +// dmaapMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig); + } + + @Test + public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration1() { + preTest2(); + assertNotNull(configMap); +// dmaapMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig); + } + + @After + public void postTest() { + File file = new File(CONFIGURATIONFILE); + if (file.exists()) { + System.out.println("File exists, Deleting it"); + file.delete(); + } +// List consumers = dmaapMain.getConsumers(); +// for (DMaaPVESMsgConsumer consumer : consumers) { +// // stop all consumers +// consumer.stopConsumer(); +// } + } +} + + -- cgit 1.2.3-korg