diff options
author | Piotr Borelowski <p.borelowski@partner.samsung.com> | 2020-01-15 17:58:27 +0100 |
---|---|---|
committer | Piotr Borelowski <p.borelowski@partner.samsung.com> | 2020-01-30 11:05:55 +0100 |
commit | 74a3c19549a12db2e196a6141f6fc2dcda1c5826 (patch) | |
tree | c868dff00dedc5bdd0b15a87e1382dd4e633bfd4 /adapters/mso-ve-vnfm-adapter/src/test/java/org | |
parent | 4b9193ca1a42a7781ef59a2d724200adcd6439ec (diff) |
Added the communication with AAI
Ve-Vnfm (SOL002) Adapter project
Issue-ID: SO-2574
Signed-off-by: Piotr Borelowski <p.borelowski@partner.samsung.com>
Change-Id: I32a1a560d2787b966f1634b3679368412af19520
Diffstat (limited to 'adapters/mso-ve-vnfm-adapter/src/test/java/org')
3 files changed, 224 insertions, 8 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 c8d2a6bf90..418c2e2201 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 @@ -20,20 +20,59 @@ package org.onap.so.adapters.vevnfm.controller; +import static org.junit.Assert.assertEquals; +import org.junit.Before; import org.junit.Test; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification; +import org.junit.runner.RunWith; +import org.onap.so.adapters.vevnfm.configuration.StartupConfiguration; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import static org.junit.Assert.assertEquals; +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.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.context.WebApplicationContext; +@SpringBootTest +@RunWith(SpringRunner.class) +@ActiveProfiles(StartupConfiguration.TEST_PROFILE) public class NotificationControllerTest { - private final NotificationController controller = new NotificationController(); + private static final String MINIMAL_JSON_CONTENT = "{}"; + private static final int ZERO = 0; + + @Value("${notification.url}") + private String notificationUrl; + + @Autowired + private WebApplicationContext webApplicationContext; + + private MockMvc mvc; + + @Before + public void init() { + mvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); + } @Test - public void testReceiveNotification() { - final VnfLcmOperationOccurrenceNotification notification = new VnfLcmOperationOccurrenceNotification(); - final ResponseEntity response = controller.receiveNotification(notification); - assertEquals(HttpStatus.OK, response.getStatusCode()); + public void testReceiveNotification() throws Exception { + // given + final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(notificationUrl) + .contentType(MediaType.APPLICATION_JSON).content(MINIMAL_JSON_CONTENT); + + // when + final MvcResult mvcResult = mvc.perform(request).andReturn(); + + // then + final MockHttpServletResponse response = mvcResult.getResponse(); + assertEquals(HttpStatus.OK.value(), response.getStatus()); + assertEquals(ZERO, response.getContentLength()); } } 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 new file mode 100644 index 0000000000..8c480d0415 --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/StartupServiceTest.java @@ -0,0 +1,80 @@ +/*- + * ============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.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.adapters.vevnfm.aai.AaiConnection; +import org.onap.so.adapters.vevnfm.exception.VeVnfmException; + +@RunWith(MockitoJUnitRunner.class) +public class StartupServiceTest { + + @Mock + private AaiConnection aaiConnection; + + @Mock + private SubscriberService subscriberService; + + @InjectMocks + private StartupService startupService; + + @Test + public void testSuccess() throws Exception { + // given + final String endpoint = "lh"; + + when(aaiConnection.receiveVnfm()).thenReturn(endpoint); + when(subscriberService.subscribe(endpoint)).thenReturn(true); + + // when + startupService.run(); + + // then + verify(aaiConnection, times(1)).receiveVnfm(); + verify(subscriberService, times(1)).subscribe(endpoint); + } + + @Test(expected = VeVnfmException.class) + public void testFailureAai() throws Exception { + // given + when(aaiConnection.receiveVnfm()).thenReturn(null); + + // when + startupService.run(); + } + + @Test(expected = VeVnfmException.class) + public void testFailureSubscriber() throws Exception { + // given + final String endpoint = "lh"; + + when(aaiConnection.receiveVnfm()).thenReturn(endpoint); + when(subscriberService.subscribe(endpoint)).thenReturn(false); + + // when + startupService.run(); + } +} diff --git a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/subscription/SubscribeSenderTest.java b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/subscription/SubscribeSenderTest.java new file mode 100644 index 0000000000..62a624a983 --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/subscription/SubscribeSenderTest.java @@ -0,0 +1,97 @@ +/*- + * ============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.subscription; + +import static org.junit.Assert.assertTrue; +import static org.springframework.http.HttpHeaders.CONTENT_TYPE; +import static org.springframework.test.web.client.ExpectedCount.once; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.*; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import org.hamcrest.CoreMatchers; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.adapters.vevnfm.configuration.StartupConfiguration; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.client.MockRestServiceServer; +import org.springframework.web.client.RestTemplate; + +@SpringBootTest +@RunWith(SpringRunner.class) +@ActiveProfiles(StartupConfiguration.TEST_PROFILE) +public class SubscribeSenderTest { + + private static final String SLASH = "/"; + private static final String MINIMAL_JSON_CONTENT = "{}"; + + private static final Gson GSON; + + static { + final GsonBuilder builder = new GsonBuilder(); + builder.serializeNulls(); + GSON = builder.create(); + } + + @Value("${vnfm.subscription}") + private String vnfmSubscription; + + @Autowired + private SubscribeSender sender; + + @Autowired + private RestTemplate restTemplate; + + private MockRestServiceServer mockRestServer; + + @Before + public void init() { + mockRestServer = MockRestServiceServer.bindTo(restTemplate).build(); + } + + @Test + public void testSuccess() { + // given + final String endpoint = "lh"; + final LccnSubscriptionRequest request = new LccnSubscriptionRequest(); + + mockRestServer.expect(once(), requestTo(SLASH + endpoint + vnfmSubscription)) + .andExpect(header(CONTENT_TYPE, CoreMatchers.containsString(MediaType.APPLICATION_JSON_VALUE))) + .andExpect(method(HttpMethod.POST)).andExpect(content().json(GSON.toJson(request))) + .andRespond(withStatus(HttpStatus.CREATED).body(MINIMAL_JSON_CONTENT)); + + // when + final boolean done = sender.send(endpoint, request); + + // then + assertTrue(done); + mockRestServer.verify(); + } +} |