summaryrefslogtreecommitdiffstats
path: root/adapters
diff options
context:
space:
mode:
authorPiotr Borelowski <p.borelowski@partner.samsung.com>2020-04-16 13:26:59 +0200
committerPiotr Borelowski <p.borelowski@partner.samsung.com>2020-04-28 17:44:00 +0200
commit603b6362951f4cdfaca66053948524b78daa0477 (patch)
tree41038e074eea09d4147df44fa7b245d0e5bb365c /adapters
parentaefb6fd6b91be3aa44b5e8183fa1c9e471853c29 (diff)
AAI id mapping in SOL002 Adapter
SOL002 (Ve-Vnfm) Adapter project - mapping between vnfInstanceId and AAI Id to the DMaaP message Issue-ID: SO-2574 Signed-off-by: Piotr Borelowski <p.borelowski@partner.samsung.com> Change-Id: Ic20ff45a49b26c141aa834d55589f482f961e70b
Diffstat (limited to 'adapters')
-rw-r--r--adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/aai/AaiConnection.java49
-rw-r--r--adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/controller/NotificationController.java29
-rw-r--r--adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/event/DmaapEvent.java4
-rw-r--r--adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSender.java75
-rw-r--r--adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java6
-rw-r--r--adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/VnfAaiChecker.java51
-rw-r--r--adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java19
-rw-r--r--adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSenderTest.java131
-rw-r--r--adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/StartupServiceTest.java1
-rw-r--r--adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/VnfAaiCheckerTest.java87
-rw-r--r--adapters/mso-ve-vnfm-adapter/src/test/resources/application.yaml56
11 files changed, 254 insertions, 254 deletions
diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/aai/AaiConnection.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/aai/AaiConnection.java
index fd20a0f78e..70e4e1d88b 100644
--- a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/aai/AaiConnection.java
+++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/aai/AaiConnection.java
@@ -25,11 +25,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import org.apache.logging.log4j.util.Strings;
-import org.onap.aai.domain.yang.EsrSystemInfo;
-import org.onap.aai.domain.yang.EsrSystemInfoList;
-import org.onap.aai.domain.yang.EsrVnfm;
-import org.onap.aai.domain.yang.EsrVnfmList;
-import org.onap.aai.domain.yang.v18.GenericVnf;
+import org.onap.aai.domain.yang.*;
import org.onap.so.adapters.vevnfm.exception.VeVnfmException;
import org.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.aai.AAIResourcesClient;
@@ -45,14 +41,25 @@ public class AaiConnection {
private static final Logger logger = LoggerFactory.getLogger(AaiConnection.class);
+ private static final String SELFLINK = "selflink";
private static final int FIRST_INDEX = 0;
+ private AAIResourcesClient resourcesClient = null;
+
private static void isValid(final List<EsrSystemInfo> infos) throws VeVnfmException {
if (infos == null || infos.isEmpty() || Strings.isBlank(infos.get(FIRST_INDEX).getServiceUrl())) {
throw new VeVnfmException("No 'url' field in VNFM info");
}
}
+ private AAIResourcesClient getResourcesClient() {
+ if (resourcesClient == null) {
+ resourcesClient = new AAIResourcesClient();
+ }
+
+ return resourcesClient;
+ }
+
public List<EsrSystemInfo> receiveVnfm() throws VeVnfmException {
List<EsrSystemInfo> infos;
@@ -68,9 +75,8 @@ public class AaiConnection {
}
private List<EsrSystemInfo> receiveVnfmInternal() {
- final AAIResourcesClient resourcesClient = new AAIResourcesClient();
final AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.VNFM_LIST);
- final Optional<EsrVnfmList> response = resourcesClient.get(EsrVnfmList.class, resourceUri);
+ final Optional<EsrVnfmList> response = getResourcesClient().get(EsrVnfmList.class, resourceUri);
if (response.isPresent()) {
final EsrVnfmList esrVnfmList = response.get();
@@ -81,7 +87,7 @@ public class AaiConnection {
for (final EsrVnfm vnfm : esrVnfm) {
final String vnfmId = vnfm.getVnfmId();
- infos.addAll(receiveVnfmServiceUrl(resourcesClient, vnfmId));
+ infos.addAll(receiveVnfmServiceUrl(vnfmId));
}
return infos;
@@ -90,8 +96,8 @@ public class AaiConnection {
return null;
}
- private List<EsrSystemInfo> receiveVnfmServiceUrl(final AAIResourcesClient resourcesClient, final String vnfmId) {
- final Optional<EsrVnfm> response = resourcesClient.get(EsrVnfm.class,
+ private List<EsrSystemInfo> receiveVnfmServiceUrl(final String vnfmId) {
+ final Optional<EsrVnfm> response = getResourcesClient().get(EsrVnfm.class,
AAIUriFactory.createResourceUri(AAIObjectType.VNFM, vnfmId).depth(Depth.ONE));
if (response.isPresent()) {
@@ -107,17 +113,24 @@ public class AaiConnection {
return Collections.emptyList();
}
- public boolean checkGenericVnfId(final String vnfId) {
- final AAIResourcesClient resourcesClient = new AAIResourcesClient();
- final AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId);
- final Optional<GenericVnf> response = resourcesClient.get(GenericVnf.class, resourceUri);
+ public String receiveGenericVnfId(final String href) {
+ final AAIResourceUri resourceUri =
+ AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNFS).queryParam(SELFLINK, href);
+ final Optional<GenericVnfs> response = getResourcesClient().get(GenericVnfs.class, resourceUri);
if (response.isPresent()) {
- final GenericVnf vnf = response.get();
- logger.info("The AAI replied with: {}", vnf);
- return vnfId.equals(vnf.getVnfId());
+ final GenericVnfs vnfs = response.get();
+ logger.info("The AAI replied with: {}", vnfs);
+ final List<GenericVnf> genericVnfList = vnfs.getGenericVnf();
+ final int size = genericVnfList.size();
+
+ if (size == 1) {
+ return genericVnfList.get(FIRST_INDEX).getVnfId();
+ } else if (size > 1) {
+ logger.warn("more generic vnfs available");
+ }
}
- return false;
+ return null;
}
}
diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/controller/NotificationController.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/controller/NotificationController.java
index 1560b3be4d..36bc23d1b5 100644
--- a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/controller/NotificationController.java
+++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/controller/NotificationController.java
@@ -20,14 +20,10 @@
package org.onap.so.adapters.vevnfm.controller;
-import org.onap.so.adapters.vevnfm.configuration.ConfigProperties;
-import org.onap.so.adapters.vevnfm.constant.NotificationVnfFilterType;
-import org.onap.so.adapters.vevnfm.service.DmaapService;
-import org.onap.so.adapters.vevnfm.service.VnfAaiChecker;
import org.onap.so.adapters.etsi.sol003.adapter.lcm.lcn.model.VnfLcmOperationOccurrenceNotification;
+import org.onap.so.adapters.vevnfm.service.DmaapConditionalSender;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@@ -38,29 +34,20 @@ public class NotificationController {
private static final Logger logger = LoggerFactory.getLogger(NotificationController.class);
- private final NotificationVnfFilterType notificationVnfFilterType;
- private final VnfAaiChecker vnfAaiChecker;
- private final DmaapService dmaapService;
+ private final DmaapConditionalSender dmaapConditionalSender;
- @Autowired
- public NotificationController(final ConfigProperties configProperties, final VnfAaiChecker vnfAaiChecker,
- final DmaapService dmaapService) {
- this.notificationVnfFilterType = configProperties.getNotificationVnfFilterType();
- this.vnfAaiChecker = vnfAaiChecker;
- this.dmaapService = dmaapService;
+ public NotificationController(final DmaapConditionalSender dmaapConditionalSender) {
+ this.dmaapConditionalSender = dmaapConditionalSender;
}
@PostMapping("${vnfm.notification}")
public ResponseEntity receiveNotification(@RequestBody final VnfLcmOperationOccurrenceNotification notification) {
logger.info("Notification received {}", notification);
- final String vnfInstanceId = notification.getVnfInstanceId();
-
- if (vnfAaiChecker.vnfCheck(notificationVnfFilterType, vnfInstanceId)) {
- logger.info("The info with the VNF id '{}' is sent to DMaaP", vnfInstanceId);
- dmaapService.send(notification);
- } else {
- logger.info("This VNF id '{}' is not supported", vnfInstanceId);
+ try {
+ dmaapConditionalSender.send(notification);
+ } catch (NullPointerException e) {
+ logger.warn("NullPointerException caught while sending to DMaaP", e);
}
return ResponseEntity.ok().build();
diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/event/DmaapEvent.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/event/DmaapEvent.java
index 8ef3f24d2f..a3ff2dcd6d 100644
--- a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/event/DmaapEvent.java
+++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/event/DmaapEvent.java
@@ -47,7 +47,7 @@ public class DmaapEvent {
private final VnfLcmOperationOccurrenceNotification etsiLcmEvent;
public DmaapEvent(final String closedLoopControlName, final String version,
- final VnfLcmOperationOccurrenceNotification etsiLcmEvent) {
+ final VnfLcmOperationOccurrenceNotification etsiLcmEvent, final String genericId) {
this.closedLoopControlName = closedLoopControlName;
this.closedLoopAlarmStart = Instant.now().getLong(INSTANT_SECONDS);
this.closedLoopEventClient = MSERVICE;
@@ -55,7 +55,7 @@ public class DmaapEvent {
this.requestId = UUID.randomUUID().toString();
this.targetType = VNF;
this.target = VNFID;
- this.aaiEvent = new AaiEvent(false, etsiLcmEvent.getId());
+ this.aaiEvent = (genericId == null) ? null : new AaiEvent(false, genericId);
this.from = ETSI;
this.version = version;
this.etsiLcmEvent = etsiLcmEvent;
diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSender.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSender.java
new file mode 100644
index 0000000000..b96bffa58f
--- /dev/null
+++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSender.java
@@ -0,0 +1,75 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SO
+ * ================================================================================
+ * Copyright (C) 2020 Samsung. 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.so.adapters.vevnfm.service;
+
+import org.apache.logging.log4j.util.Strings;
+import org.onap.so.adapters.etsi.sol003.adapter.lcm.lcn.model.VnfLcmOperationOccurrenceNotification;
+import org.onap.so.adapters.vevnfm.aai.AaiConnection;
+import org.onap.so.adapters.vevnfm.configuration.ConfigProperties;
+import org.onap.so.adapters.vevnfm.constant.NotificationVnfFilterType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+@Service
+public class DmaapConditionalSender {
+
+ private static final Logger logger = LoggerFactory.getLogger(DmaapConditionalSender.class);
+
+ private final NotificationVnfFilterType notificationVnfFilterType;
+ private final AaiConnection aaiConnection;
+ private final DmaapService dmaapService;
+
+ public DmaapConditionalSender(final ConfigProperties configProperties, final AaiConnection aaiConnection,
+ final DmaapService dmaapService) {
+ this.notificationVnfFilterType = configProperties.getNotificationVnfFilterType();
+ this.aaiConnection = aaiConnection;
+ this.dmaapService = dmaapService;
+ }
+
+ public void send(final VnfLcmOperationOccurrenceNotification notification) {
+ final String href = notification.getLinks().getVnfInstance().getHref();
+ boolean logSent = false;
+
+ switch (notificationVnfFilterType) {
+ case ALL:
+ dmaapService.send(notification, aaiConnection.receiveGenericVnfId(href));
+ logSent = true;
+ break;
+ case AAI_CHECKED:
+ final String genericId = aaiConnection.receiveGenericVnfId(href);
+ if (Strings.isNotBlank(genericId)) {
+ dmaapService.send(notification, genericId);
+ logSent = true;
+ }
+ break;
+ case NONE:
+ break;
+ default:
+ throw new IllegalArgumentException(
+ "The value of VnfNotificationFilterType is not supported: " + notificationVnfFilterType);
+ }
+
+ final String vnfInstanceId = notification.getVnfInstanceId();
+ final String not = logSent ? "" : "not ";
+ logger.info("The info with the VNF id '{}' is " + not + "sent to DMaaP", vnfInstanceId);
+ }
+}
diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java
index c13811d9d0..278f9dee95 100644
--- a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java
+++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java
@@ -20,9 +20,9 @@
package org.onap.so.adapters.vevnfm.service;
+import org.onap.so.adapters.etsi.sol003.adapter.lcm.lcn.model.VnfLcmOperationOccurrenceNotification;
import org.onap.so.adapters.vevnfm.configuration.ConfigProperties;
import org.onap.so.adapters.vevnfm.event.DmaapEvent;
-import org.onap.so.adapters.etsi.sol003.adapter.lcm.lcn.model.VnfLcmOperationOccurrenceNotification;
import org.onap.so.rest.service.HttpRestServiceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,9 +51,9 @@ public class DmaapService {
this.restProvider = restProvider;
}
- public void send(final VnfLcmOperationOccurrenceNotification notification) {
+ public void send(final VnfLcmOperationOccurrenceNotification notification, final String genericId) {
try {
- final DmaapEvent event = new DmaapEvent(closedLoopControlName, version, notification);
+ final DmaapEvent event = new DmaapEvent(closedLoopControlName, version, notification, genericId);
final ResponseEntity<String> response = restProvider.postHttpRequest(event, getUrl(), String.class);
final HttpStatus statusCode = response.getStatusCode();
final String body = response.getBody();
diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/VnfAaiChecker.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/VnfAaiChecker.java
deleted file mode 100644
index 1442fa2862..0000000000
--- a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/VnfAaiChecker.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SO
- * ================================================================================
- * Copyright (C) 2020 Samsung. 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.so.adapters.vevnfm.service;
-
-import org.onap.so.adapters.vevnfm.aai.AaiConnection;
-import org.onap.so.adapters.vevnfm.constant.NotificationVnfFilterType;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-@Service
-public class VnfAaiChecker {
-
- private final AaiConnection aaiConnection;
-
- @Autowired
- public VnfAaiChecker(final AaiConnection aaiConnection) {
- this.aaiConnection = aaiConnection;
- }
-
- public boolean vnfCheck(final NotificationVnfFilterType filterType, final String vnfId) {
- switch (filterType) {
- case ALL:
- return true;
- case AAI_CHECKED:
- return aaiConnection.checkGenericVnfId(vnfId);
- case NONE:
- return false;
- default:
- throw new IllegalArgumentException(
- "The value of VnfNotificationFilterType is not supported: " + filterType);
- }
- }
-}
diff --git a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java
index 27def126ef..9406b299ea 100644
--- a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java
+++ b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java
@@ -21,8 +21,6 @@
package org.onap.so.adapters.vevnfm.controller;
import static org.junit.Assert.assertEquals;
-import static org.springframework.test.web.client.match.MockRestRequestMatchers.anything;
-import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -35,13 +33,11 @@ import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
-import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
-import org.springframework.web.client.RestTemplate;
import org.springframework.web.context.WebApplicationContext;
@SpringBootTest
@@ -49,7 +45,8 @@ import org.springframework.web.context.WebApplicationContext;
@ActiveProfiles(StartupConfiguration.TEST_PROFILE)
public class NotificationControllerTest {
- private static final String MINIMAL_JSON_CONTENT = "{}";
+ private static final String JSON = "{\"_links\":{\"vnfInstance\":{\"href\":null}}}";
+
private static final int ZERO = 0;
@Autowired
@@ -58,27 +55,20 @@ public class NotificationControllerTest {
@Autowired
private WebApplicationContext webApplicationContext;
- @Autowired
- private RestTemplate restTemplate;
-
private String notification;
private MockMvc mvc;
- private MockRestServiceServer mockRestServer;
@Before
public void init() {
notification = configProperties.getVnfmNotification();
mvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
- mockRestServer = MockRestServiceServer.bindTo(restTemplate).build();
}
@Test
public void testReceiveNotification() throws Exception {
// given
- final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(notification)
- .contentType(MediaType.APPLICATION_JSON).content(MINIMAL_JSON_CONTENT);
-
- mockRestServer.expect(anything()).andRespond(withSuccess());
+ final MockHttpServletRequestBuilder request =
+ MockMvcRequestBuilders.post(notification).contentType(MediaType.APPLICATION_JSON).content(JSON);
// when
final MvcResult mvcResult = mvc.perform(request).andReturn();
@@ -87,6 +77,5 @@ public class NotificationControllerTest {
final MockHttpServletResponse response = mvcResult.getResponse();
assertEquals(HttpStatus.OK.value(), response.getStatus());
assertEquals(ZERO, response.getContentLength());
- mockRestServer.verify();
}
}
diff --git a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSenderTest.java b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSenderTest.java
new file mode 100644
index 0000000000..5af682dda8
--- /dev/null
+++ b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSenderTest.java
@@ -0,0 +1,131 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SO
+ * ================================================================================
+ * Copyright (C) 2020 Samsung. 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.so.adapters.vevnfm.service;
+
+import static org.mockito.Mockito.*;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.adapters.etsi.sol003.adapter.lcm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationLinks;
+import org.onap.so.adapters.etsi.sol003.adapter.lcm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance;
+import org.onap.so.adapters.etsi.sol003.adapter.lcm.lcn.model.VnfLcmOperationOccurrenceNotification;
+import org.onap.so.adapters.vevnfm.aai.AaiConnection;
+import org.onap.so.adapters.vevnfm.configuration.ConfigProperties;
+import org.onap.so.adapters.vevnfm.constant.NotificationVnfFilterType;
+
+@RunWith(MockitoJUnitRunner.class)
+public class DmaapConditionalSenderTest {
+
+ private static final String GENERIC_ID = "gener77";
+ private static final String INSTANCE_ID = "insta44";
+ private static final String HREF = "/href";
+
+ @Mock
+ private ConfigProperties configProperties;
+
+ @Mock
+ private AaiConnection aaiConnection;
+
+ @Mock
+ private DmaapService dmaapService;
+
+ private static VnfLcmOperationOccurrenceNotification createNotification() {
+ final VnfLcmOperationOccurrenceNotification notification = new VnfLcmOperationOccurrenceNotification();
+ final LcnVnfLcmOperationOccurrenceNotificationLinks links = new LcnVnfLcmOperationOccurrenceNotificationLinks();
+ final LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance vnfInstance =
+ new LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance();
+
+ notification.setVnfInstanceId(INSTANCE_ID);
+ notification.setLinks(links);
+ links.setVnfInstance(vnfInstance);
+ vnfInstance.setHref(HREF);
+
+ return notification;
+ }
+
+ @Test
+ public void testSendNone() {
+ // given
+ when(configProperties.getNotificationVnfFilterType()).thenReturn(NotificationVnfFilterType.NONE);
+
+ final DmaapConditionalSender sender = new DmaapConditionalSender(configProperties, aaiConnection, dmaapService);
+ final VnfLcmOperationOccurrenceNotification notification = createNotification();
+
+ // when
+ sender.send(notification);
+
+ // then
+ verify(aaiConnection, never()).receiveGenericVnfId(any());
+ verify(dmaapService, never()).send(any(), any());
+ }
+
+ @Test
+ public void testSendAll() {
+ // given
+ when(configProperties.getNotificationVnfFilterType()).thenReturn(NotificationVnfFilterType.ALL);
+ when(aaiConnection.receiveGenericVnfId(eq(HREF))).thenReturn(GENERIC_ID);
+
+ final DmaapConditionalSender sender = new DmaapConditionalSender(configProperties, aaiConnection, dmaapService);
+ final VnfLcmOperationOccurrenceNotification notification = createNotification();
+
+ // when
+ sender.send(notification);
+
+ // then
+ verify(aaiConnection).receiveGenericVnfId(eq(HREF));
+ verify(dmaapService).send(eq(notification), eq(GENERIC_ID));
+ }
+
+ @Test
+ public void testSendAaiCheckedPresent() {
+ // given
+ when(configProperties.getNotificationVnfFilterType()).thenReturn(NotificationVnfFilterType.AAI_CHECKED);
+ when(aaiConnection.receiveGenericVnfId(eq(HREF))).thenReturn(GENERIC_ID);
+
+ final DmaapConditionalSender sender = new DmaapConditionalSender(configProperties, aaiConnection, dmaapService);
+ final VnfLcmOperationOccurrenceNotification notification = createNotification();
+
+ // when
+ sender.send(notification);
+
+ // then
+ verify(aaiConnection).receiveGenericVnfId(eq(HREF));
+ verify(dmaapService).send(eq(notification), eq(GENERIC_ID));
+ }
+
+ @Test
+ public void testSendAaiCheckedAbsent() {
+ // given
+ when(configProperties.getNotificationVnfFilterType()).thenReturn(NotificationVnfFilterType.AAI_CHECKED);
+ when(aaiConnection.receiveGenericVnfId(eq(HREF))).thenReturn(null);
+
+ final DmaapConditionalSender sender = new DmaapConditionalSender(configProperties, aaiConnection, dmaapService);
+ final VnfLcmOperationOccurrenceNotification notification = createNotification();
+
+ // when
+ sender.send(notification);
+
+ // then
+ verify(aaiConnection).receiveGenericVnfId(eq(HREF));
+ verify(dmaapService, never()).send(any(), any());
+ }
+}
diff --git a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/StartupServiceTest.java b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/StartupServiceTest.java
index 5d5ffa6555..78d6ba899d 100644
--- a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/StartupServiceTest.java
+++ b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/StartupServiceTest.java
@@ -40,7 +40,6 @@ import org.onap.so.adapters.vevnfm.configuration.ConfigProperties;
public class StartupServiceTest {
private static final String URL = "rt";
- private static final String ENDPOINT = "localhost";
@Rule
public ExpectedException thrown = ExpectedException.none();
diff --git a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/VnfAaiCheckerTest.java b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/VnfAaiCheckerTest.java
deleted file mode 100644
index da5992ee42..0000000000
--- a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/VnfAaiCheckerTest.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SO
- * ================================================================================
- * Copyright (C) 2020 Samsung. 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.so.adapters.vevnfm.service;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.when;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.so.adapters.vevnfm.aai.AaiConnection;
-import org.onap.so.adapters.vevnfm.constant.NotificationVnfFilterType;
-
-@RunWith(MockitoJUnitRunner.class)
-public class VnfAaiCheckerTest {
-
- private static final String VNF_ID = "t5h78w";
-
- @Mock
- private AaiConnection aaiConnection;
-
- @InjectMocks
- private VnfAaiChecker checker;
-
- @Test
- public void testAll() {
- // when
- final boolean response = checker.vnfCheck(NotificationVnfFilterType.ALL, VNF_ID);
-
- // then
- assertTrue(response);
- }
-
- @Test
- public void testAaiCheckedPresent() {
- // given
- when(aaiConnection.checkGenericVnfId(eq(VNF_ID))).thenReturn(true);
-
- // when
- final boolean response = checker.vnfCheck(NotificationVnfFilterType.AAI_CHECKED, VNF_ID);
-
- // then
- assertTrue(response);
- }
-
- @Test
- public void testAaiCheckedAbsent() {
- // given
- when(aaiConnection.checkGenericVnfId(eq(VNF_ID))).thenReturn(false);
-
- // when
- final boolean response = checker.vnfCheck(NotificationVnfFilterType.AAI_CHECKED, VNF_ID);
-
- // then
- assertFalse(response);
- }
-
- @Test
- public void testNone() {
- // when
- final boolean response = checker.vnfCheck(NotificationVnfFilterType.NONE, VNF_ID);
-
- // then
- assertFalse(response);
- }
-}
diff --git a/adapters/mso-ve-vnfm-adapter/src/test/resources/application.yaml b/adapters/mso-ve-vnfm-adapter/src/test/resources/application.yaml
deleted file mode 100644
index 2c7f67e459..0000000000
--- a/adapters/mso-ve-vnfm-adapter/src/test/resources/application.yaml
+++ /dev/null
@@ -1,56 +0,0 @@
-#
-# Copyright © 2019, 2020 Samsung.
-# 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.
-
-server:
- port: 9098
-
-vevnfmadapter:
- vnf-filter-json: '{notificationTypes:[VnfLcmOperationOccurrenceNotification],operationStates:[COMPLETED]}'
- endpoint: http://so-ve-vnfm-adapter.onap:9098
-
-mso:
- key: 07a7159d3bf51a0e53be7a8f89699be7
-
-aai:
- endpoint: https://aai.onap:30233
- auth: 75C4483F9C05E2C33A8602635FA532397EC44AB667A2B64DED4FEE08DD932F2E3C1FEE
-
-vnfm:
- default-endpoint: https://so-vnfm-simulator.onap:9093
- subscription: /vnflcm/v1/subscriptions
- notification: /lcm/v1/vnf/instances/notifications
-
-notification:
- vnf-filter-type: ALL
-
-dmaap:
- endpoint: http://message-router.onap:30227
- topic: /events/unauthenticated.DCAE_CL_OUTPUT
- closed-loop:
- control:
- name: ClosedLoopControlName
- version: 1.0.2
-
-spring:
- security:
- usercredentials:
- - username: admin
- openpass: a4b3c2d1
- password: '$2a$10$vU.mWyNTsikAxXIA5c269ewCpAbYTiyMS0m1N.kn4F2CSGEnrKN7K'
- role: USER
- http:
- converters:
- preferred-json-mapper: gson