diff options
Diffstat (limited to 'adapters/mso-ve-vnfm-adapter/src/test')
3 files changed, 40 insertions, 14 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 418c2e2201..57638a165a 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,6 +21,9 @@ package org.onap.so.adapters.vevnfm.controller; import static org.junit.Assert.assertEquals; +import static org.springframework.test.web.client.ExpectedCount.once; +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; @@ -33,11 +36,13 @@ 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 @@ -54,11 +59,16 @@ public class NotificationControllerTest { @Autowired private WebApplicationContext webApplicationContext; + @Autowired + private RestTemplate restTemplate; + private MockMvc mvc; + private MockRestServiceServer mockRestServer; @Before public void init() { mvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); + mockRestServer = MockRestServiceServer.bindTo(restTemplate).build(); } @Test @@ -67,6 +77,8 @@ public class NotificationControllerTest { final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(notificationUrl) .contentType(MediaType.APPLICATION_JSON).content(MINIMAL_JSON_CONTENT); + mockRestServer.expect(once(), anything()).andRespond(withSuccess()); + // when final MvcResult mvcResult = mvc.perform(request).andReturn(); @@ -74,5 +86,6 @@ 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/StartupServiceTest.java b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/StartupServiceTest.java index 8c480d0415..0f9c23e261 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 @@ -21,11 +21,14 @@ package org.onap.so.adapters.vevnfm.service; import static org.mockito.Mockito.*; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import org.onap.aai.domain.yang.EsrSystemInfo; import org.onap.so.adapters.vevnfm.aai.AaiConnection; import org.onap.so.adapters.vevnfm.exception.VeVnfmException; @@ -41,38 +44,46 @@ public class StartupServiceTest { @InjectMocks private StartupService startupService; + @Rule + public ExpectedException thrown = ExpectedException.none(); + @Test public void testSuccess() throws Exception { // given - final String endpoint = "lh"; - - when(aaiConnection.receiveVnfm()).thenReturn(endpoint); - when(subscriberService.subscribe(endpoint)).thenReturn(true); + final EsrSystemInfo info = new EsrSystemInfo(); + info.setServiceUrl("lh"); + when(aaiConnection.receiveVnfm()).thenReturn(info); + when(subscriberService.subscribe(info)).thenReturn(true); // when startupService.run(); // then verify(aaiConnection, times(1)).receiveVnfm(); - verify(subscriberService, times(1)).subscribe(endpoint); + verify(subscriberService, times(1)).subscribe(info); } - @Test(expected = VeVnfmException.class) + @Test public void testFailureAai() throws Exception { // given - when(aaiConnection.receiveVnfm()).thenReturn(null); + final EsrSystemInfo info = new EsrSystemInfo(); + when(aaiConnection.receiveVnfm()).thenReturn(info); + + thrown.expect(VeVnfmException.class); // when startupService.run(); } - @Test(expected = VeVnfmException.class) + @Test public void testFailureSubscriber() throws Exception { // given - final String endpoint = "lh"; + final EsrSystemInfo info = new EsrSystemInfo(); + info.setServiceUrl("lh"); + when(aaiConnection.receiveVnfm()).thenReturn(info); + when(subscriberService.subscribe(info)).thenReturn(false); - when(aaiConnection.receiveVnfm()).thenReturn(endpoint); - when(subscriberService.subscribe(endpoint)).thenReturn(false); + thrown.expect(VeVnfmException.class); // 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 index 62a624a983..d1fda0eee6 100644 --- 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 @@ -31,6 +31,7 @@ import org.hamcrest.CoreMatchers; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.onap.aai.domain.yang.EsrSystemInfo; 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; @@ -79,16 +80,17 @@ public class SubscribeSenderTest { @Test public void testSuccess() { // given - final String endpoint = "lh"; + final EsrSystemInfo info = new EsrSystemInfo(); + info.setServiceUrl("lh"); final LccnSubscriptionRequest request = new LccnSubscriptionRequest(); - mockRestServer.expect(once(), requestTo(SLASH + endpoint + vnfmSubscription)) + mockRestServer.expect(once(), requestTo(SLASH + info.getServiceUrl() + 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); + final boolean done = sender.send(info, request); // then assertTrue(done); |