diff options
author | highstreetherbert <herbert.eiselt@highstreet-technologies.com> | 2020-07-15 19:23:07 +0200 |
---|---|---|
committer | highstreetherbert <herbert.eiselt@highstreet-technologies.com> | 2020-07-16 13:06:25 +0200 |
commit | 3d93b15a297c0c661100c665aa5379bf4fedff7d (patch) | |
tree | 7f3d0b20ac34d85ca98936c4998f40ddf2de322e /sdnr/wt/mountpoint-registrar/provider/src/test | |
parent | 002ad417b90882524276d1b9cfe377c6f6293a4c (diff) |
SDN-R Sodium compliant mountpoint-registrar
Adapted tests
Issue-ID: CCSDK-2568
Signed-off-by: highstreetherbert <herbert.eiselt@highstreet-technologies.com>
Change-Id: Iab79976a60a77f84bdaa1f191b58333a9b114149
Signed-off-by: highstreetherbert <herbert.eiselt@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/mountpoint-registrar/provider/src/test')
8 files changed, 139 insertions, 122 deletions
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 new file mode 100644 index 000000000..3413e9766 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/GeneralConfigForTest.java @@ -0,0 +1,66 @@ +/* + * ============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 index 9c41da9ea..80e037da6 100644 --- 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 @@ -50,12 +50,13 @@ public class PNFRegistrationConfigTest { + ""; // @formatter:on private ConfigurationFileRepresentation cfg; + private static final String configFile = "test.properties"; @Test public void test() { try { - Files.asCharSink(new File("test.properties"), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); - cfg = new ConfigurationFileRepresentation("test.properties"); + 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("org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPPNFRegVESMsgConsumer", @@ -76,14 +77,14 @@ public class PNFRegistrationConfigTest { assertEquals("25000", pnfCfg.getClientConnectTimeout()); } catch (IOException e) { - // TODO Auto-generated catch block + e.printStackTrace(); } } @After public void cleanUp() { - File file = new File("test.properties"); + 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/TestDMaaPFaultVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPFaultVESMsgConsumer.java index 8929612ad..0d9f107a8 100644 --- 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 @@ -18,15 +18,18 @@ 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; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.FaultNotificationClient; -public class TestDMaaPFaultVESMsgConsumer extends 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 = "" @@ -112,9 +115,21 @@ public class TestDMaaPFaultVESMsgConsumer extends DMaaPFaultVESMsgConsumer { + "}"; // @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() { - DMaaPFaultVESMsgConsumer faultMsgConsumer = new TestDMaaPFaultVESMsgConsumer(); + public void test() throws IOException { + DMaaPFaultVESMsgConsumer faultMsgConsumer = new DMaaPFaultVESMsgConsumer(cfgTest.getCfg()); try { faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "CRITICAL")); @@ -130,42 +145,4 @@ public class TestDMaaPFaultVESMsgConsumer extends DMaaPFaultVESMsgConsumer { } } - @Override - public FaultNotificationClient getFaultNotificationClient(String baseUrl) { - return new TestFaultNotificationClient(); - } - - @Override - public String getSDNRUser() { - return DEFAULT_SDNRUSER; - } - - @Override - public String getSDNRPasswd() { - return DEFAULT_SDNRPASSWD; - } - - @Override - public String getBaseUrl() { - return DEFAULT_SDNRBASEURL; - } - - @Test - public void Test1() { - TestGeneralConfig cfgTest = new TestGeneralConfig(); - cfgTest.test(); - DMaaPFaultVESMsgConsumer faultConsumer = new DMaaPFaultVESMsgConsumer(); - System.out.println(faultConsumer.getBaseUrl()); - System.out.println(faultConsumer.getSDNRUser()); - System.out.println(faultConsumer.getSDNRPasswd()); - } - - /* - * @Test public void Test2() { TestGeneralConfig cfgTest = new - * TestGeneralConfig(); cfgTest.test1(); //cfgTest.test(); - * DMaaPFaultVESMsgConsumer faultConsumer = new DMaaPFaultVESMsgConsumer(); - * System.out.println(faultConsumer.getBaseUrl()); - * System.out.println(faultConsumer.getSDNRUser()); - * System.out.println(faultConsumer.getSDNRPasswd()); } - */ } 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 index 169f734e8..fb38879a5 100644 --- 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 @@ -18,19 +18,22 @@ 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; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.PNFMountPointClient; -public class TestDMaaPPNFRegVESMsgConsumer extends 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" + + " \"event\": {\n" + " \"commonEventHeader\": {\n" + " \"domain\": \"pnfRegistration\",\n" + " \"eventId\": \"NSHMRIACQ01M01123401_1234 BestInClass\",\n" @@ -82,7 +85,6 @@ public class TestDMaaPPNFRegVESMsgConsumer extends DMaaPPNFRegVESMsgConsumer { + " }\n" + "}\n" + ""; - private static final String pnfRegMsg_SSH = "{\n" + " \"event\": {\n" + " \"commonEventHeader\": {\n" @@ -136,7 +138,6 @@ public class TestDMaaPPNFRegVESMsgConsumer extends DMaaPPNFRegVESMsgConsumer { + " }\n" + "}\n" + ""; - private static final String pnfRegMsg_OTHER = "{\n" + " \"event\": {\n" + " \"commonEventHeader\": {\n" @@ -231,10 +232,22 @@ public class TestDMaaPPNFRegVESMsgConsumer extends DMaaPPNFRegVESMsgConsumer { + ""; // @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 TestDMaaPPNFRegVESMsgConsumer(); + DMaaPPNFRegVESMsgConsumer pnfRegMsgConsumer = new DMaaPPNFRegVESMsgConsumer(cfgTest.getCfg()); try { pnfRegMsgConsumer.processMsg(pnfRegMsg); pnfRegMsgConsumer.processMsg(pnfRegMsg_SSH); @@ -246,31 +259,9 @@ public class TestDMaaPPNFRegVESMsgConsumer extends DMaaPPNFRegVESMsgConsumer { } } - @Override - public PNFMountPointClient getPNFMountPointClient(String baseUrl) { - return new TestPNFMountPointClient(); - } - - @Override - public String getSDNRUser() { - return DEFAULT_SDNRUSER; - } - - @Override - public String getSDNRPasswd() { - return DEFAULT_SDNRPASSWD; - } - - @Override - public String getBaseUrl() { - return DEFAULT_SDNRBASEURL; - } - @Test public void Test1() { - TestGeneralConfig cfgTest = new TestGeneralConfig(); - cfgTest.test(); - DMaaPPNFRegVESMsgConsumer pnfConsumer = new DMaaPPNFRegVESMsgConsumer(); + 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 index 1f1cfa33f..032850afb 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 @@ -37,7 +37,7 @@ import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.PNFRegistrationC public class TestDMaaPVESMsgConsumerMain { - private static final String CONFIGURATIONFILE = "test.properties"; + private static final String CONFIGURATIONFILE = "test1.properties"; // @formatter:off private static final String TESTCONFIG_GENERAL = "[general]\n" + "dmaapEnabled=false\n" @@ -100,8 +100,8 @@ public class TestDMaaPVESMsgConsumerMain { + "fetchPause=WORLD\n" + "\n" + ""; - public GeneralConfig generalConfig; // @formatter:on + public GeneralConfig generalConfig; Map<String, Configuration> configMap = new HashMap<String, Configuration>(); DMaaPVESMsgConsumerMain dmaapMain; @@ -144,24 +144,24 @@ public class TestDMaaPVESMsgConsumerMain { public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration() { preTest1(); assertNotNull(configMap); - dmaapMain = new DMaaPVESMsgConsumerMain(configMap); + dmaapMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig); } @Test public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration1() { preTest2(); assertNotNull(configMap); - dmaapMain = new DMaaPVESMsgConsumerMain(configMap); + dmaapMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig); } @After public void postTest() { - File file = new File("test.properties"); + File file = new File(CONFIGURATIONFILE); if (file.exists()) { System.out.println("File exists, Deleting it"); file.delete(); } - List<DMaaPVESMsgConsumer> consumers = DMaaPVESMsgConsumerMain.getConsumers(); + List<DMaaPVESMsgConsumer> 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 index c847fbb9f..3caa864d5 100644 --- 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 @@ -52,12 +52,12 @@ public class TestFaultConfig { // @formatter:on private ConfigurationFileRepresentation cfg; - + private static final String CONFIGURATIONFILE = "test2.properties"; @Test public void test() { try { - Files.asCharSink(new File("test.properties"), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); - cfg = new ConfigurationFileRepresentation("test.properties"); + 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("org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPFaultVESMsgConsumer", @@ -78,13 +78,13 @@ public class TestFaultConfig { assertEquals("25000", faultCfg.getClientConnectTimeout()); } catch (IOException e) { - // TODO Auto-generated catch block + e.printStackTrace(); } } @After public void cleanUp() { - File file = new File("test.properties"); + 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/TestGeneralConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestGeneralConfig.java index c07ee480b..f73f3a5bf 100644 --- 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 @@ -19,52 +19,36 @@ 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.Before; import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.GeneralConfig; public class TestGeneralConfig { - // @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 static final String CONFIGURATIONFILE = "test1.properties"; - private ConfigurationFileRepresentation globalCfg; + private GeneralConfigForTest config; + + @Before + public void before() throws IOException { + config = new GeneralConfigForTest(CONFIGURATIONFILE); + } @Test - public void test() { - try { - Files.asCharSink(new File("test.properties"), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); - globalCfg = new ConfigurationFileRepresentation("test.properties"); - GeneralConfig cfg = new GeneralConfig(globalCfg); + public void test() throws IOException { + GeneralConfig cfg = config.getCfg(); + assertEquals(false, cfg.getEnabled()); - assertEquals("http://localhost:8181", GeneralConfig.getBaseUrl()); - assertEquals("admin", GeneralConfig.getSDNRUser()); - assertEquals("admin", GeneralConfig.getSDNRPasswd()); + assertEquals("http://localhost:8181", cfg.getBaseUrl()); + assertEquals("admin", cfg.getSDNRUser()); + assertEquals("admin", cfg.getSDNRPasswd()); assertEquals("general", cfg.getSectionName()); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } } @After public void cleanUp() { - File file = new File("test.properties"); - if (file.exists()) { - System.out.println("File exists, Deleting it"); - file.delete(); - } - + config.close(); } } diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestMapping.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestMapping.java index 7753c0975..883746067 100644 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestMapping.java +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestMapping.java @@ -17,16 +17,14 @@ */ package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import java.util.Optional; - import org.junit.Test; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SeverityType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushFaultNotificationInputBuilder; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; - public class TestMapping { private final ObjectMapper mapper = new ObjectMapper(); @@ -45,7 +43,7 @@ public class TestMapping { faultNotificationBuilder.setTimestamp(new DateAndTime(faultOccurrenceTime)); faultNotificationBuilder.setObjectId(faultObjectId); faultNotificationBuilder.setProblem(faultReason); - Optional<SeverityType> oSeverity = getSeverity(faultSeverity); //TODO getSeverity + Optional<SeverityType> oSeverity = getSeverity(faultSeverity); if (oSeverity.isPresent()) { faultNotificationBuilder.setSeverity(oSeverity.get()); } else { |