summaryrefslogtreecommitdiffstats
path: root/adapters/mso-ve-vnfm-adapter/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/mso-ve-vnfm-adapter/src/test')
-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
5 files changed, 135 insertions, 159 deletions
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