diff options
author | Rafal Wrzesniak <r.wrzesniak@partner.samsung.com> | 2021-09-30 12:08:03 +0200 |
---|---|---|
committer | Rafal Wrzesniak <r.wrzesniak@partner.samsung.com> | 2021-10-15 14:38:06 +0200 |
commit | b9ed86210c28d251c7503b9b0a5b543d957614e8 (patch) | |
tree | beadba763f10c661e51976ce70249260ce29a39e /sdnr/wt/mountpoint-registrar/provider/src/test/java | |
parent | 8f862e52cc36716503c5aea4973031eb4e10d930 (diff) |
Adds handling CM provisioning messages
Adds config, consumer and changes to run it in MountpointRegistrar
Issue-ID: CCSDK-3464
Signed-off-by: Rafal Wrzesniak <r.wrzesniak@partner.samsung.com>
Change-Id: I800db7082dc4a84d73ac9e5dffd90c2f3c46ca82
Diffstat (limited to 'sdnr/wt/mountpoint-registrar/provider/src/test/java')
3 files changed, 181 insertions, 0 deletions
diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPCMVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPCMVESMsgConsumer.java new file mode 100644 index 000000000..0cd7f0228 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPCMVESMsgConsumer.java @@ -0,0 +1,82 @@ +/* + * ============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 static org.junit.Assert.fail; + +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 = 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); + } + + private String readFileToString(File file) throws IOException { + StringBuilder fileContent = new StringBuilder(); + Files.lines(Paths.get(file.toURI())).forEach(fileContent::append); + return fileContent.toString(); + } + + @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/TestDMaaPVESMsgConsumerMain.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPVESMsgConsumerMain.java index 11fb2f3b9..ecfb8d081 100644 --- 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 @@ -109,9 +109,11 @@ public class TestDMaaPVESMsgConsumerMain { 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()); } @@ -126,9 +128,11 @@ public class TestDMaaPVESMsgConsumerMain { 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()); } 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 new file mode 100644 index 000000000..42c204aec --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestProvisioningConfig.java @@ -0,0 +1,95 @@ +/* + * ============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(); + } + } + +} |