diff options
Diffstat (limited to 'sdnr/wt/mountpoint-registrar/provider/src/test/java')
20 files changed, 1710 insertions, 0 deletions
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 new file mode 100644 index 000000000..2bc41490d --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/PNFRegistrationConfigTest.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * ============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.*; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.PNFRegistrationConfig; + +import com.google.common.io.Files; + +public class PNFRegistrationConfigTest { + + private static final String TESTCONFIG_CONTENT="[pnfRegistration]\n" + + "pnfRegConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.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" + + "fetchPause=5000\n" + + ""; + + private ConfigurationFileRepresentation cfg; + + @Test + public void test() { + try { + Files.asCharSink(new File("test.properties"), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); + cfg = new ConfigurationFileRepresentation("test.properties"); + PNFRegistrationConfig pnfCfg = new PNFRegistrationConfig(cfg); + assertEquals("pnfRegistration", pnfCfg.getSectionName()); + assertEquals("org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPPNFRegVESMsgConsumer", pnfCfg.getConsumerClass()); + 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()); + + } catch (IOException e) { + // TODO Auto-generated catch block + } + + } + +} 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 new file mode 100644 index 000000000..cdc641f10 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPFaultVESMsgConsumer.java @@ -0,0 +1,172 @@ +/******************************************************************************* + * ============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.*; + +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPFaultVESMsgConsumer; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPPNFRegVESMsgConsumer; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.FaultNotificationClient; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.PNFMountPointClient; + +public class TestDMaaPFaultVESMsgConsumer extends DMaaPFaultVESMsgConsumer { + + 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 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\":94801033822670," + + " \"lastEpochMicrosec\":94801033822670," + + " \"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\"" + + " }" + + " }" + + " }" + + "}"; + + 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\":94801033822670," + + " \"lastEpochMicrosec\":94801033822670," + + " \"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\"" + + " }" + + " }" + + " }" + + "}"; + @Test + public void test() { + DMaaPFaultVESMsgConsumer faultMsgConsumer = new TestDMaaPFaultVESMsgConsumer(); + 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()); + } + } + + @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 new file mode 100644 index 000000000..54439150c --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPPNFRegVESMsgConsumer.java @@ -0,0 +1,279 @@ +/******************************************************************************* + * ============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 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 { + + 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 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\": \"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" + + ""; + + @Test + public void processMsgTest() { + + DMaaPPNFRegVESMsgConsumer pnfRegMsgConsumer = new TestDMaaPPNFRegVESMsgConsumer(); + 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()); + } + } + + @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(); + 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 new file mode 100644 index 000000000..956477379 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPVESMsgConsumerMain.java @@ -0,0 +1,166 @@ +/******************************************************************************* + * ============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.*; + +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.Before; +import org.junit.Test; +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.mountpointregistrar.impl.DMaaPVESMsgConsumer; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPVESMsgConsumerMain; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.FaultConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.GeneralConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.PNFRegistrationConfig; + +import com.google.common.io.Files; + +public class TestDMaaPVESMsgConsumerMain { + + private static final String CONFIGURATIONFILE = "test.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.DummyPNFRegVESMsgConsumer\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.test.impl.DummyFaultVESMsgConsumer\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.test.impl.DummyPNFRegVESMsgConsumer\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.test.impl.DummyFaultVESMsgConsumer\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<String, Configuration> configMap = new HashMap<String, Configuration>(); + DMaaPVESMsgConsumerMain dmaapMain; + +// @Before + 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); + + configMap.put("pnfRegistration", pnfRegConfig); + configMap.put("fault", faultConfig); + } 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); + + configMap.put("pnfRegistration", pnfRegConfig); + configMap.put("fault", faultConfig); + } catch (Exception e) { + System.out.println("Failed in preTest execution "+e.getMessage()); + } + } + + @Test + public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration() { + preTest1(); + assertNotNull(configMap); + dmaapMain = new DMaaPVESMsgConsumerMain(configMap); + } + + @Test + public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration1() { + preTest2(); + assertNotNull(configMap); + dmaapMain = new DMaaPVESMsgConsumerMain(configMap); + } + + @After + public void postTest() { + List<DMaaPVESMsgConsumer> consumers = DMaaPVESMsgConsumerMain.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 new file mode 100644 index 000000000..cbdb24a03 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestFaultConfig.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; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.FaultConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.PNFRegistrationConfig; + +import com.google.common.io.Files; + +public class TestFaultConfig { + + private static final String TESTCONFIG_CONTENT="[fault]\n" + + "faultConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPFaultVESMsgConsumer\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=5000\n" + + "\n" + + ""; + + private ConfigurationFileRepresentation cfg; + + @Test + public void test() { + try { + Files.asCharSink(new File("test.properties"), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); + cfg = new ConfigurationFileRepresentation("test.properties"); + FaultConfig faultCfg = new FaultConfig(cfg); + assertEquals("fault", faultCfg.getSectionName()); + assertEquals("org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPFaultVESMsgConsumer", faultCfg.getConsumerClass()); + 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()); + + } catch (IOException e) { + // TODO Auto-generated catch block + } + } + +} 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 new file mode 100644 index 000000000..68bcb5ee4 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestFaultNotificationClient.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * ============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.*; + +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"); + assertEquals(true, testClient.sendFaultNotification("TEST_50001", "1", "2019-11-20T09:25:19.948Z", "SEDNKSAHQ01M01nSky01", "lossOfSignal", "Critical")); + assertEquals(true, testClient.sendFaultNotification("TEST_50001", "1", "2019-11-20T09:25:19.948Z", "SEDNKSAHQ01M01nSky01", "lossOfSignal", "Critical")); + } + + @Override + protected @Nonnull BaseHTTPResponse sendRequest(String uri, String method, String body, Map<String, String> 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 new file mode 100644 index 000000000..4eb5ba17b --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestGeneralConfig.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * ============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.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.GeneralConfig; + +import com.google.common.io.Files; + +public class TestGeneralConfig { + + private static final String TESTCONFIG_CONTENT="[general]\n" + + "dmaapEnabled=false\n" + + "baseUrl=http://localhost:8181\n" + + "sdnrUser=admin\n" + + "sdnrPasswd=admin\n" + + ""; + + private ConfigurationFileRepresentation globalCfg; + + @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); + assertEquals(false, cfg.getEnabled()); + assertEquals("http://localhost:8181", GeneralConfig.getBaseUrl()); + assertEquals("admin", GeneralConfig.getSDNRUser()); + assertEquals("admin", GeneralConfig.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(); + } + + } +} 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 new file mode 100644 index 000000000..5c9fbe35d --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestMapping.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * ============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 com.fasterxml.jackson.core.JsonProcessingException; +import java.util.Optional; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.yangtools.YangToolsMapper; +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; + +public class TestMapping { + + private final YangToolsMapper mapper = new YangToolsMapper(); + + + private static Optional<SeverityType> getSeverity(String faultSeverity) { + return SeverityType.forName(faultSeverity); // <-- mapping provided by generated classes. Manual mapping beneficial. + } + + private String updateFaultPayload(String faultNodeId, String faultCounter, String faultOccurrenceTime, String faultObjectId, + String faultReason, String faultSeverity) throws JsonProcessingException { + + PushFaultNotificationInputBuilder faultNotificationBuilder = new PushFaultNotificationInputBuilder(); + faultNotificationBuilder.setNodeId(faultNodeId); + faultNotificationBuilder.setCounter(Integer.valueOf(faultCounter)); + faultNotificationBuilder.setTimestamp(new DateAndTime(faultOccurrenceTime)); + faultNotificationBuilder.setObjectId(faultObjectId); + faultNotificationBuilder.setProblem(faultReason); + Optional<SeverityType> oSeverity = getSeverity(faultSeverity); //TODO getSeverity + if (oSeverity.isPresent()) { + faultNotificationBuilder.setSeverity(oSeverity.get()); + } else { + // Do something to handle the problem + } + return mapper.writeValueAsString(faultNotificationBuilder); + } + + + @Test + public void test() throws JsonProcessingException { + DateAndTime dt = new DateAndTime("2017-03-01T09:15:00.0Z"); + + String result = updateFaultPayload("f1","34",dt.getValue(),"fefef","reason","Critical"); + + System.out.println("Res: "+result); + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestMountpointRegistrarImpl.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestMountpointRegistrarImpl.java new file mode 100644 index 000000000..014a96f03 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestMountpointRegistrarImpl.java @@ -0,0 +1,147 @@ +/******************************************************************************* + * ============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.assertNotNull; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MountpointRegistrarImpl; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.mock.odlapi.ClusterSingletonServiceProviderMock; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.mock.odlapi.DataBrokerNetconfMock; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.mock.odlapi.MountPointServiceMock; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.mock.odlapi.NotificationPublishServiceMock; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.mock.odlapi.RpcProviderRegistryMock; +import org.opendaylight.controller.md.sal.binding.api.MountPointService; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@SuppressWarnings("deprecation") +public class TestMountpointRegistrarImpl { + + private static Path KARAF_ETC = Paths.get("etc"); + private static MountpointRegistrarImpl mountpointRegistrar; + private static DataBrokerNetconfMock dataBrokerNetconf; + + private static final Logger LOG = LoggerFactory.getLogger(TestMountpointRegistrarImpl.class); + + + + @Before + public void before() throws InterruptedException, IOException { + + System.out.println("Logger: " + LOG.getClass().getName() + " " + LOG.getName()); + // Call System property to get the classpath value + Path etc = KARAF_ETC; + delete(etc); + + System.out.println("Create empty:" + etc.toString()); + Files.createDirectories(etc); + + // Create mocks + dataBrokerNetconf = new DataBrokerNetconfMock(); + ClusterSingletonServiceProvider clusterSingletonService = new ClusterSingletonServiceProviderMock(); + MountPointService mountPointService = new MountPointServiceMock(null); + NotificationPublishService notificationPublishService = new NotificationPublishServiceMock(); + RpcProviderRegistry rpcProviderRegistry = new RpcProviderRegistryMock(); + + // start using blueprint interface + try { + mountpointRegistrar = new MountpointRegistrarImpl(); + + mountpointRegistrar.setDataBroker(dataBrokerNetconf); + mountpointRegistrar.setMountPointService(mountPointService); + mountpointRegistrar.setNotificationPublishService(notificationPublishService); + mountpointRegistrar.setRpcProviderRegistry(rpcProviderRegistry); + mountpointRegistrar.setClusterSingletonService(clusterSingletonService); + mountpointRegistrar.init(); + } catch (Exception e) { + StringWriter sw = new StringWriter(); + e.printStackTrace(new PrintWriter(sw)); + fail("Not initialized" +sw.toString()); + } + System.out.println("Initialization status: " + mountpointRegistrar.isInitializationOk()); + System.out.println("Initialization done"); + } + + @After + public void after() throws InterruptedException, IOException { + + System.out.println("Start shutdown"); + // close using blueprint interface + try { + mountpointRegistrar.close(); + } catch (Exception e) { + System.out.println(e); + } + delete(KARAF_ETC); + + } + + @Test + public void test1() { + System.out.println("Test1: slave mountpoint"); + assertNotNull(mountpointRegistrar); + System.out.println("Initialization status: " + mountpointRegistrar.isInitializationOk()); + System.out.println("Test2: Done"); + } + + // ********************* Private + + @SuppressWarnings("unused") + private static void sleep(int millis) { + try { + Thread.sleep(millis); + } catch (InterruptedException e) { + LOG.warn(e.getMessage()); + Thread.interrupted(); + } + } + + private static void delete(Path etc) throws IOException { + if (Files.exists(etc)) { + System.out.println("Found and remove:" + etc.toString()); + delete(etc.toFile()); + } + } + + private static void delete(File f) throws IOException { + if (f.isDirectory()) { + for (File c : f.listFiles()) { + delete(c); + } + } + if (!f.delete()) { + throw new FileNotFoundException("Failed to delete file: " + f); + } + } +} 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 new file mode 100644 index 000000000..ca61d9c1c --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestPNFMountPointClient.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * ============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.*; + +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"); + assertEquals(true, testClient.pnfMountPointCreate("TEST_50001", "127.0.0.1", "TLS", "key_id", "admin", "admin", "17380")); + + assertEquals(true, testClient.pnfMountPointCreate("TEST_50001", "127.0.0.1", "SSH", "key_id", "admin", "admin", "17380")); + } + + @Override + protected @Nonnull BaseHTTPResponse sendRequest(String uri, String method, String body, Map<String, String> headers) + throws IOException { + System.out.println("In overridden sendRequest in TestPNFMountPointClient"); + return new BaseHTTPResponse(200, body); + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/impl/DummyFaultVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/impl/DummyFaultVESMsgConsumer.java new file mode 100644 index 000000000..a5662c986 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/impl/DummyFaultVESMsgConsumer.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * ============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.impl; + +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPVESMsgConsumerImpl; + +public class DummyFaultVESMsgConsumer extends DMaaPVESMsgConsumerImpl { + + @Override + public void processMsg(String msg) throws Exception { + System.out.println("Message received is - "+msg); + + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/impl/DummyPNFRegVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/impl/DummyPNFRegVESMsgConsumer.java new file mode 100644 index 000000000..368bbde11 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/impl/DummyPNFRegVESMsgConsumer.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * ============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.impl; + +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPVESMsgConsumerImpl; + +public class DummyPNFRegVESMsgConsumer extends DMaaPVESMsgConsumerImpl { + + + @Override + public void processMsg(String msg) throws Exception { + System.out.println("Message received is - "+msg); + + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/ClusterSingletonServiceProviderMock.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/ClusterSingletonServiceProviderMock.java new file mode 100644 index 000000000..d76b9db93 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/ClusterSingletonServiceProviderMock.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * ============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.mock.odlapi; + +import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService; +import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider; +import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration; + +public class ClusterSingletonServiceProviderMock implements ClusterSingletonServiceProvider { + + @Override + public void close() throws Exception { + + } + + @Override + public ClusterSingletonServiceRegistration registerClusterSingletonService(ClusterSingletonService service) { + return null; + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/DataBrokerMountpointMock.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/DataBrokerMountpointMock.java new file mode 100644 index 000000000..a2e115d59 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/DataBrokerMountpointMock.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.mock.odlapi; + +import org.opendaylight.controller.md.sal.binding.api.BindingService; +import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; +import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; +import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; +import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.DataObject; + +/** + * @author herbert + * + */ +@SuppressWarnings("deprecation") +public class DataBrokerMountpointMock implements DataBroker, BindingService { + + ReadOnlyTransaction readOnlyTransaction; + + public void setReadOnlyTransaction(ReadOnlyTransaction readOnlyTransaction) { + this.readOnlyTransaction = readOnlyTransaction; + } + + @Override + public <T extends DataObject, L extends DataTreeChangeListener<T>> ListenerRegistration<L> registerDataTreeChangeListener( + DataTreeIdentifier<T> arg0, L arg1) { + return null; + } + + @Override + public BindingTransactionChain createTransactionChain(TransactionChainListener listener) { + return null; + } + + @Override + public ReadOnlyTransaction newReadOnlyTransaction() { + return readOnlyTransaction; + } + + @Override + public ReadWriteTransaction newReadWriteTransaction() { + return null; + } + + @Override + public WriteTransaction newWriteOnlyTransaction() { + return null; + } + + + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/DataBrokerNetconfMock.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/DataBrokerNetconfMock.java new file mode 100644 index 000000000..e504ef166 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/DataBrokerNetconfMock.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.mock.odlapi; + +import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; +import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; +import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; +import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.DataObject; + +/** + * @author herbert + * + */ +@SuppressWarnings("deprecation") +public class DataBrokerNetconfMock implements DataBroker { + + + ReadOnlyTransaction readOnlyTransaction; + + public void setReadOnlyTransaction(ReadOnlyTransaction readOnlyTransaction) { + this.readOnlyTransaction = readOnlyTransaction; + } + + @Override + public <T extends DataObject, L extends DataTreeChangeListener<T>> ListenerRegistration<L> registerDataTreeChangeListener( + DataTreeIdentifier<T> arg0, L arg1) { + return null; + } + + @Override + public BindingTransactionChain createTransactionChain(TransactionChainListener listener) { + return null; + } + + @Override + public ReadOnlyTransaction newReadOnlyTransaction() { + return readOnlyTransaction; + } + + @Override + public ReadWriteTransaction newReadWriteTransaction() { + return null; + } + + @Override + public WriteTransaction newWriteOnlyTransaction() { + return null; + } + + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/MountPointMock.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/MountPointMock.java new file mode 100644 index 000000000..1a7cc50a5 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/MountPointMock.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * ONAP : ccsdk feature sdnr wt sdnr-wt-devicemanager-provider + * ================================================================================ + * 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.mock.odlapi; + +import com.google.common.base.Optional; +import org.opendaylight.controller.md.sal.binding.api.BindingService; +import org.opendaylight.controller.md.sal.binding.api.MountPoint; +import org.opendaylight.controller.md.sal.binding.api.NotificationService; +import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.network.topology.topology.topology.types.TopologyNetconf; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * @author herbert + * + */ +@SuppressWarnings("deprecation") +public class MountPointMock implements MountPoint { + + private boolean databrokerAbsent = true; + private final DataBrokerMountpointMock dataBroker = new DataBrokerMountpointMock(); + private final RpcConsumerRegistryMock rpcConsumerRegistry = new RpcConsumerRegistryMock(); + private NotificationService setReadOnlyTransaction; + + private static final InstanceIdentifier<Topology> NETCONF_TOPO_IID = + InstanceIdentifier.create(NetworkTopology.class).child(Topology.class, + new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName()))); + + @Override + public InstanceIdentifier<?> getIdentifier() { + return NETCONF_TOPO_IID; + } + + @SuppressWarnings("unchecked") + @Override + public <T extends BindingService> Optional<T> getService(Class<T> service) { + + System.out.println("Requested mountpoint service: "+service.getSimpleName()+" databrokerAbsent state: "+databrokerAbsent); + + Optional<?> res; + if (service.isInstance(dataBroker)) { + System.out.println("Delivering databroker"); + res = databrokerAbsent ? Optional.absent() : Optional.of(dataBroker); + } else if (service.isInstance(rpcConsumerRegistry)) { + System.out.println("Delivering RpcConsumerRegistryMock"); + res = Optional.of(rpcConsumerRegistry); + } else if (service.isInstance(setReadOnlyTransaction)) { + System.out.println("Delivering notificationService"); + res = Optional.of(setReadOnlyTransaction); + } else { + System.out.println("Delivering no service"); + res = Optional.absent(); + } + return (Optional<T>)res; + } + + public void setDatabrokerAbsent( boolean state) { + this.databrokerAbsent = state; + } + + public <T extends NotificationService&ReadOnlyTransaction>void setReadOnlyTransaction(T readOnlyTransaction) { + this.setReadOnlyTransaction = readOnlyTransaction; + dataBroker.setReadOnlyTransaction(readOnlyTransaction); + } + + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/MountPointServiceMock.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/MountPointServiceMock.java new file mode 100644 index 000000000..433324737 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/MountPointServiceMock.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * ============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.mock.odlapi; + +import com.google.common.base.Optional; +import org.opendaylight.controller.md.sal.binding.api.MountPoint; +import org.opendaylight.controller.md.sal.binding.api.MountPointService; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * @author herbert + * + */ +@SuppressWarnings("deprecation") +public class MountPointServiceMock implements MountPointService { + + private final MountPointMock mountpoint; + + public MountPointServiceMock(MountPointMock mountpoint) { + this.mountpoint = mountpoint; + } + + @Override + public Optional<MountPoint> getMountPoint(InstanceIdentifier<?> mountPoint) { + + Optional<MountPoint> optional = Optional.of(mountpoint); + return optional; + } + + @Override + public <T extends MountPointListener> ListenerRegistration<T> registerListener(InstanceIdentifier<?> path, + T listener) { + return null; + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/NotificationPublishServiceMock.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/NotificationPublishServiceMock.java new file mode 100644 index 000000000..cf4ab0e9b --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/NotificationPublishServiceMock.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * ============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.mock.odlapi; + +import com.google.common.util.concurrent.ListenableFuture; +import java.util.concurrent.TimeUnit; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.yangtools.yang.binding.Notification; + +/** + * @author herbert + * + */ +@SuppressWarnings("deprecation") +public class NotificationPublishServiceMock implements NotificationPublishService { + + @Override + public ListenableFuture<?> offerNotification(Notification notification) { + return null; + } + + @Override + public ListenableFuture<?> offerNotification(Notification notification, int timeout, TimeUnit unit) + throws InterruptedException { + return null; + } + + @Override + public void putNotification(Notification notification) throws InterruptedException { + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/RpcConsumerRegistryMock.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/RpcConsumerRegistryMock.java new file mode 100644 index 000000000..a33012b8b --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/RpcConsumerRegistryMock.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * ONAP : ccsdk feature sdnr wt sdnr-wt-devicemanager-provider + * ================================================================================ + * 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.mock.odlapi; + +import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry; +import org.opendaylight.yangtools.yang.binding.RpcService; + +/** + * @author herbert + * + */ +@SuppressWarnings("deprecation") +public class RpcConsumerRegistryMock implements RpcConsumerRegistry { + + @Override + public <T extends RpcService> T getRpcService(Class<T> serviceInterface) { + return null; + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/RpcProviderRegistryMock.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/RpcProviderRegistryMock.java new file mode 100644 index 000000000..7d556df98 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/mock/odlapi/RpcProviderRegistryMock.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * ============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.mock.odlapi; + +import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration; +import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.controller.sal.binding.api.rpc.RpcContextIdentifier; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.RpcService; + +@SuppressWarnings("deprecation") +public class RpcProviderRegistryMock implements RpcProviderRegistry { + + @Override + public <T extends RpcService> T getRpcService(Class<T> serviceInterface) { + return null; + } + + @Override + public <L extends RouteChangeListener<RpcContextIdentifier, InstanceIdentifier<?>>> ListenerRegistration<L> registerRouteChangeListener( + L listener) { + return null; + } + + + @Override + public <T extends RpcService> RoutedRpcRegistration<T> addRoutedRpcImplementation(Class<T> serviceInterface, + T implementation) throws IllegalStateException { + return null; + } + + @Override + public <T extends RpcService> RpcRegistration<T> addRpcImplementation(Class<T> serviceInterface, T implementation) + throws IllegalStateException { + System.out.println("Register class "+serviceInterface); + return null; + } + +} |