From 1e37b701d1a2ab4ed41138fdc097f480dfaf305d Mon Sep 17 00:00:00 2001 From: Piotr Borelowski Date: Fri, 14 Feb 2020 09:15:38 +0100 Subject: Multiplied connection to AAI and subscription to VNFM (if they fail) (+small changes required by OOM) Ve-Vnfm (SOL002) Adapter project Issue-ID: SO-2574 Signed-off-by: Piotr Borelowski Change-Id: I42bb30b4bbf256340123d64d203f461ed336ebc3 --- .../controller/NotificationControllerTest.java | 6 +- .../provider/AuthorizationHeadersProviderTest.java | 39 ++++++++ .../vevnfm/service/StartupServiceTest.java | 52 +++-------- .../vevnfm/service/SubscribeSenderTest.java | 102 +++++++++++++++++++++ .../vevnfm/subscription/SubscribeSenderTest.java | 99 -------------------- 5 files changed, 157 insertions(+), 141 deletions(-) create mode 100644 adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/SubscribeSenderTest.java delete mode 100644 adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/subscription/SubscribeSenderTest.java (limited to 'adapters/mso-ve-vnfm-adapter/src/test/java/org') 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 57638a165a..974e6ec544 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 @@ -53,8 +53,8 @@ public class NotificationControllerTest { private static final String MINIMAL_JSON_CONTENT = "{}"; private static final int ZERO = 0; - @Value("${notification.url}") - private String notificationUrl; + @Value("${vnfm.notification}") + private String notification; @Autowired private WebApplicationContext webApplicationContext; @@ -74,7 +74,7 @@ public class NotificationControllerTest { @Test public void testReceiveNotification() throws Exception { // given - final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(notificationUrl) + final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(notification) .contentType(MediaType.APPLICATION_JSON).content(MINIMAL_JSON_CONTENT); mockRestServer.expect(once(), anything()).andRespond(withSuccess()); diff --git a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/provider/AuthorizationHeadersProviderTest.java b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/provider/AuthorizationHeadersProviderTest.java index 64503ddfc2..f9ae427086 100644 --- a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/provider/AuthorizationHeadersProviderTest.java +++ b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/provider/AuthorizationHeadersProviderTest.java @@ -28,6 +28,8 @@ import org.springframework.http.HttpHeaders; public class AuthorizationHeadersProviderTest { private static final String AUTHORIZATION_EXAMPLE = "authorization"; + private static final String BLANK_EXAMPLE = "\t\n"; + private static final String EMPTY = ""; private final AuthorizationHeadersProvider provider = new AuthorizationHeadersProvider(); @@ -44,4 +46,41 @@ public class AuthorizationHeadersProviderTest { assertEquals(size, headers.size()); assertFalse(headers.containsKey(AUTHORIZATION_HEADER)); } + + @Test + public void testBlankAuthorization() { + final HttpHeaders headers = provider.getHttpHeaders(); + final int size = headers.size(); + + provider.addAuthorization(BLANK_EXAMPLE); + assertEquals(size, headers.size()); + } + + @Test + public void testEmptyAuthorization() { + final HttpHeaders headers = provider.getHttpHeaders(); + final int size = headers.size(); + + provider.addAuthorization(EMPTY); + assertEquals(size, headers.size()); + } + + @Test + public void testNullAuthorization() { + final HttpHeaders headers = provider.getHttpHeaders(); + final int size = headers.size(); + + provider.addAuthorization(null); + assertEquals(size, headers.size()); + } + + @Test + public void testRemoveAuthorization() { + final HttpHeaders headers = provider.getHttpHeaders(); + final int size = headers.size(); + + provider.removeAuthorization(); + provider.removeAuthorization(); + assertEquals(size, headers.size()); + } } 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 0f9c23e261..d1d34a706f 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 @@ -20,7 +20,9 @@ package org.onap.so.adapters.vevnfm.service; -import static org.mockito.Mockito.*; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -30,62 +32,34 @@ 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; @RunWith(MockitoJUnitRunner.class) public class StartupServiceTest { - @Mock - private AaiConnection aaiConnection; + private static final String URL = "rt"; + + @Rule + public ExpectedException thrown = ExpectedException.none(); @Mock - private SubscriberService subscriberService; + private AaiConnection aaiConnection; @InjectMocks private StartupService startupService; - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Test public void testSuccess() throws Exception { // given 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(info); - } + info.setServiceUrl(URL); - @Test - public void testFailureAai() throws Exception { - // given - final EsrSystemInfo info = new EsrSystemInfo(); when(aaiConnection.receiveVnfm()).thenReturn(info); - thrown.expect(VeVnfmException.class); - // when - startupService.run(); - } - - @Test - public void testFailureSubscriber() throws Exception { - // given - final EsrSystemInfo info = new EsrSystemInfo(); - info.setServiceUrl("lh"); - when(aaiConnection.receiveVnfm()).thenReturn(info); - when(subscriberService.subscribe(info)).thenReturn(false); + final EsrSystemInfo systemInfo = startupService.receiveVnfm(); - thrown.expect(VeVnfmException.class); - - // when - startupService.run(); + // then + verify(aaiConnection).receiveVnfm(); + assertEquals(info, systemInfo); } } diff --git a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/SubscribeSenderTest.java b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/SubscribeSenderTest.java new file mode 100644 index 0000000000..b7f1f982a2 --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/SubscribeSenderTest.java @@ -0,0 +1,102 @@ +/*- + * ============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.assertEquals; +import static org.onap.so.adapters.vevnfm.service.SubscribeSender.SLASH; +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.aai.domain.yang.EsrSystemInfo; +import org.onap.so.adapters.vevnfm.configuration.StartupConfiguration; +import org.onap.so.adapters.vevnfm.exception.VeVnfmException; +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 URL = "lh"; + private static final String ID = "1a2s3d4f"; + private static final String JSON = "{\"id\":\"" + ID + "\"}"; + + 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() throws VeVnfmException { + // given + final EsrSystemInfo info = new EsrSystemInfo(); + info.setServiceUrl(URL); + final LccnSubscriptionRequest request = new LccnSubscriptionRequest(); + + 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(JSON).contentType(MediaType.APPLICATION_JSON)); + + // when + final String id = sender.send(info, request); + + // then + mockRestServer.verify(); + assertEquals(ID, id); + } +} 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 deleted file mode 100644 index d1fda0eee6..0000000000 --- a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/subscription/SubscribeSenderTest.java +++ /dev/null @@ -1,99 +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.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.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; -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 EsrSystemInfo info = new EsrSystemInfo(); - info.setServiceUrl("lh"); - final LccnSubscriptionRequest request = new LccnSubscriptionRequest(); - - 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(info, request); - - // then - assertTrue(done); - mockRestServer.verify(); - } -} -- cgit 1.2.3-korg