diff options
author | KAPIL SINGAL <ks220y@att.com> | 2020-07-16 14:12:12 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-07-16 14:12:12 +0000 |
commit | 96aeff5a753e008add7a879198ba3229f4b6016b (patch) | |
tree | e1ecdc8066260b918605f3fcd82cc22ec1cf93b8 /sdnr/wt/mountpoint-registrar/provider/src | |
parent | 7dbe38ba0522b346a0fcd9851e797f0fd71ecd5e (diff) | |
parent | 3d93b15a297c0c661100c665aa5379bf4fedff7d (diff) |
Merge "SDN-R Sodium compliant mountpoint-registrar"
Diffstat (limited to 'sdnr/wt/mountpoint-registrar/provider/src')
13 files changed, 197 insertions, 186 deletions
diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPFaultVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPFaultVESMsgConsumer.java index 4e6cc996d..b0227da6f 100644 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPFaultVESMsgConsumer.java +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPFaultVESMsgConsumer.java @@ -18,15 +18,12 @@ package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; - import java.io.IOException; - import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SeverityType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class DMaaPFaultVESMsgConsumer extends DMaaPVESMsgConsumerImpl { @@ -36,6 +33,12 @@ public class DMaaPFaultVESMsgConsumer extends DMaaPVESMsgConsumerImpl { private static final String DEFAULT_SDNRUSER = "admin"; private static final String DEFAULT_SDNRPASSWD = "admin"; + private final GeneralConfig generalConfig; + + public DMaaPFaultVESMsgConsumer(GeneralConfig generalConfig) { + this.generalConfig = generalConfig; + } + @Override public void processMsg(String msg) throws Exception { String faultNodeId; @@ -89,15 +92,15 @@ public class DMaaPFaultVESMsgConsumer extends DMaaPVESMsgConsumerImpl { } public String getBaseUrl() { - return GeneralConfig.getBaseUrl(); + return generalConfig.getBaseUrl(); } public String getSDNRUser() { - return GeneralConfig.getSDNRUser() != null ? GeneralConfig.getSDNRUser() : DEFAULT_SDNRUSER; + return generalConfig.getSDNRUser() != null ? generalConfig.getSDNRUser() : DEFAULT_SDNRUSER; } public String getSDNRPasswd() { - return GeneralConfig.getSDNRPasswd() != null ? GeneralConfig.getSDNRPasswd() : DEFAULT_SDNRPASSWD; + return generalConfig.getSDNRPasswd() != null ? generalConfig.getSDNRPasswd() : DEFAULT_SDNRPASSWD; } public FaultNotificationClient getFaultNotificationClient(String baseUrl) { diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPPNFRegVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPPNFRegVESMsgConsumer.java index ed9f583a5..c412a7a91 100644 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPPNFRegVESMsgConsumer.java +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPPNFRegVESMsgConsumer.java @@ -18,14 +18,12 @@ package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - public class DMaaPPNFRegVESMsgConsumer extends DMaaPVESMsgConsumerImpl { private static final Logger LOG = LoggerFactory.getLogger(DMaaPPNFRegVESMsgConsumer.class); @@ -36,6 +34,12 @@ public class DMaaPPNFRegVESMsgConsumer extends DMaaPVESMsgConsumerImpl { private static final String DEFAULT_SDNRUSER = "admin"; private static final String DEFAULT_SDNRPASSWD = "admin"; + private final GeneralConfig generalConfig; + + public DMaaPPNFRegVESMsgConsumer(GeneralConfig generalConfig) { + this.generalConfig = generalConfig; + } + @Override public void processMsg(String msg) { LOG.debug("Message from DMaaP topic is - {} ", msg); @@ -105,15 +109,15 @@ public class DMaaPPNFRegVESMsgConsumer extends DMaaPVESMsgConsumerImpl { } public String getBaseUrl() { - return GeneralConfig.getBaseUrl(); + return generalConfig.getBaseUrl(); } public String getSDNRUser() { - return GeneralConfig.getSDNRUser() != null ? GeneralConfig.getSDNRUser() : DEFAULT_SDNRUSER; + return generalConfig.getSDNRUser() != null ? generalConfig.getSDNRUser() : DEFAULT_SDNRUSER; } public String getSDNRPasswd() { - return GeneralConfig.getSDNRPasswd() != null ? GeneralConfig.getSDNRPasswd() : DEFAULT_SDNRPASSWD; + return generalConfig.getSDNRPasswd() != null ? generalConfig.getSDNRPasswd() : DEFAULT_SDNRPASSWD; } public PNFMountPointClient getPNFMountPointClient(String baseUrl) { diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgConsumerMain.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgConsumerMain.java index 7b851aa5c..97dd79577 100644 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgConsumerMain.java +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgConsumerMain.java @@ -22,7 +22,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Properties; - import org.onap.ccsdk.features.sdnr.wt.common.configuration.Configuration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,14 +29,18 @@ import org.slf4j.LoggerFactory; public class DMaaPVESMsgConsumerMain implements Runnable { private static final Logger LOG = LoggerFactory.getLogger(DMaaPVESMsgConsumerMain.class); - + private static final String pnfRegClass = + "org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPPNFRegVESMsgConsumer"; + private static final String faultClass = + "org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPFaultVESMsgConsumer"; boolean threadsRunning = false; - static List<DMaaPVESMsgConsumer> consumers = new LinkedList<>(); - public GeneralConfig config; + List<DMaaPVESMsgConsumer> consumers = new LinkedList<>(); public PNFRegistrationConfig pnfRegistrationConfig; public FaultConfig faultConfig; + public GeneralConfig generalConfig; - public DMaaPVESMsgConsumerMain(Map<String, Configuration> configMap) { + public DMaaPVESMsgConsumerMain(Map<String, Configuration> configMap, GeneralConfig generalConfig) { + this.generalConfig = generalConfig; configMap.forEach((k, v) -> initialize(k, v)); } @@ -77,6 +80,7 @@ public class DMaaPVESMsgConsumerMain implements Runnable { pnfRegistrationConfig.getClientReadTimeout()); consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_CLIENT_CONNECTTIMEOUT, pnfRegistrationConfig.getClientConnectTimeout()); + threadsRunning = createConsumer("pnfRegistration", consumerProperties); } else if (domain.equalsIgnoreCase("fault")) { this.faultConfig = (FaultConfig) domainConfig; consumerClass = faultConfig.getConsumerClass(); @@ -97,16 +101,11 @@ public class DMaaPVESMsgConsumerMain implements Runnable { faultConfig.getClientReadTimeout()); consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_CLIENT_CONNECTTIMEOUT, faultConfig.getClientConnectTimeout()); + threadsRunning = createConsumer("fault", consumerProperties); } - - if (consumerClass != null) { - LOG.info("Calling createConsumer : {}", consumerClass); - threadsRunning = createConsumer(consumerClass, consumerProperties); - } - } - private static boolean updateThreadState(List<DMaaPVESMsgConsumer> consumers) { + private boolean updateThreadState(List<DMaaPVESMsgConsumer> consumers) { boolean threadsRunning = false; for (DMaaPVESMsgConsumer consumer : consumers) { if (consumer.isRunning()) { @@ -116,35 +115,21 @@ public class DMaaPVESMsgConsumerMain implements Runnable { return threadsRunning; } - static boolean createConsumer(String consumerClassName, Properties properties) { - Class<?> consumerClass = null; + public boolean createConsumer(String consumerType, Properties properties) { + DMaaPVESMsgConsumerImpl consumer = null; - try { - consumerClass = Class.forName(consumerClassName); - } catch (Exception e) { - LOG.error("Could not find DMaap VES Message consumer class {}", consumerClassName, e); - } + if (consumerType.equalsIgnoreCase("pnfRegistration")) + consumer = new DMaaPPNFRegVESMsgConsumer(generalConfig); + else if (consumerType.equalsIgnoreCase("fault")) + consumer = new DMaaPFaultVESMsgConsumer(generalConfig); - if (consumerClass != null) { - LOG.debug("Calling handleConsumerClass"); - handleConsumerClass(consumerClass, consumerClassName, properties, consumers); - } + handleConsumer(consumer, properties, consumers); return !consumers.isEmpty(); } - private static boolean handleConsumerClass(Class<?> consumerClass, String consumerClassName, Properties properties, + private boolean handleConsumer(DMaaPVESMsgConsumer consumer, Properties properties, List<DMaaPVESMsgConsumer> consumers) { - DMaaPVESMsgConsumer consumer = null; - - try { - consumer = (DMaaPVESMsgConsumer) consumerClass.newInstance(); - LOG.debug("Successfully created an instance of consumerClass : {}", consumerClassName); - } catch (Exception e) { - LOG.error("Could not create consumer from class {}", consumerClassName, e); - } - if (consumer != null) { - LOG.info("Initializing consumer {}({})", consumerClassName, properties); consumer.init(properties); if (consumer.isReady()) { @@ -152,15 +137,16 @@ public class DMaaPVESMsgConsumerMain implements Runnable { consumerThread.start(); consumers.add(consumer); - LOG.info("Started consumer thread ({} : {})", consumerClassName, properties); + LOG.info("Started consumer thread ({} : {})", consumer.getClass().getSimpleName(), properties); return true; } else { - LOG.debug("Consumer {} is not ready", consumerClassName); + LOG.debug("Consumer {} is not ready", consumer.getClass().getSimpleName()); } } return false; } + @Override public void run() { while (threadsRunning) { threadsRunning = updateThreadState(consumers); @@ -178,7 +164,7 @@ public class DMaaPVESMsgConsumerMain implements Runnable { LOG.info("No listener threads running - exiting"); } - public static List<DMaaPVESMsgConsumer> getConsumers() { + public List<DMaaPVESMsgConsumer> getConsumers() { return consumers; } diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/GeneralConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/GeneralConfig.java index e8269ccda..f0d4323c4 100644 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/GeneralConfig.java +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/GeneralConfig.java @@ -44,11 +44,11 @@ public class GeneralConfig implements Configuration { private static final String DEFAULT_VALUE_BASEURL = "http://localhost:8181"; - private static ConfigurationFileRepresentation configuration; + private ConfigurationFileRepresentation configuration; public GeneralConfig(ConfigurationFileRepresentation configuration) { - GeneralConfig.configuration = configuration; - GeneralConfig.configuration.addSection(SECTION_MARKER); + this.configuration = configuration; + configuration.addSection(SECTION_MARKER); defaults(); } @@ -57,15 +57,15 @@ public class GeneralConfig implements Configuration { return enabled; } - public static String getBaseUrl() { + public String getBaseUrl() { return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_BASEURL); } - public static String getSDNRUser() { + public String getSDNRUser() { return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_USER); } - public static String getSDNRPasswd() { + public String getSDNRPasswd() { return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_USERPASSWD); } diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/MountpointRegistrarImpl.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/MountpointRegistrarImpl.java index 12a992216..94b15a54c 100644 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/MountpointRegistrarImpl.java +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/MountpointRegistrarImpl.java @@ -21,11 +21,9 @@ package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl; import java.util.HashMap; import java.util.List; import java.util.Map; - import org.onap.ccsdk.features.sdnr.wt.common.configuration.Configuration; import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; import org.onap.ccsdk.features.sdnr.wt.common.configuration.filechange.IConfigChangedListener; -import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,6 +38,7 @@ public class MountpointRegistrarImpl implements AutoCloseable, IConfigChangedLis private GeneralConfig generalConfig; private boolean dmaapEnabled = false; private Map<String, Configuration> configMap = new HashMap<>(); + private DMaaPVESMsgConsumerMain dmaapConsumerMain = null; // Blueprint 1 public MountpointRegistrarImpl() { @@ -63,7 +62,8 @@ public class MountpointRegistrarImpl implements AutoCloseable, IConfigChangedLis dmaapEnabled = generalConfig.getEnabled(); if (dmaapEnabled) { // start dmaap consumer thread only if dmaapEnabled=true LOG.info("DMaaP seems to be enabled, starting consumer(s)"); - dmaapVESMsgConsumerMain = new Thread(new DMaaPVESMsgConsumerMain(configMap)); + dmaapConsumerMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig); + dmaapVESMsgConsumerMain = new Thread(dmaapConsumerMain); dmaapVESMsgConsumerMain.start(); } else { LOG.info("DMaaP seems to be disabled, not starting any consumer(s)"); @@ -72,7 +72,7 @@ public class MountpointRegistrarImpl implements AutoCloseable, IConfigChangedLis /** * Reflect status for Unit Tests - * + * * @return Text with status */ public String isInitializationOk() { @@ -85,11 +85,12 @@ public class MountpointRegistrarImpl implements AutoCloseable, IConfigChangedLis boolean dmaapEnabledNewVal = generalConfig.getEnabled(); if (!dmaapEnabled && dmaapEnabledNewVal) { // Dmaap disabled earlier (or during bundle startup) but enabled later, start Consumer(s) LOG.info("DMaaP is enabled, starting consumer(s)"); - dmaapVESMsgConsumerMain = new Thread(new DMaaPVESMsgConsumerMain(configMap)); + dmaapConsumerMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig); + dmaapVESMsgConsumerMain = new Thread(dmaapConsumerMain); dmaapVESMsgConsumerMain.start(); } else if (dmaapEnabled && !dmaapEnabledNewVal) { // Dmaap enabled earlier (or during bundle startup) but disabled later, stop consumer(s) LOG.info("DMaaP is disabled, stopping consumer(s)"); - List<DMaaPVESMsgConsumer> consumers = DMaaPVESMsgConsumerMain.getConsumers(); + List<DMaaPVESMsgConsumer> consumers = dmaapConsumerMain.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/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 { |