diff options
author | Piotr Borelowski <p.borelowski@partner.samsung.com> | 2020-04-29 14:40:27 +0200 |
---|---|---|
committer | Piotr Borelowski <p.borelowski@partner.samsung.com> | 2020-04-29 14:50:28 +0200 |
commit | 589118aacdc22bb5c2a975d857c4f2e62340bf8b (patch) | |
tree | 40826449e534cd4c44c2def74e4ce256fe71c0d5 /adapters/etsi-sol002-adapter/src/test/java/org | |
parent | ac42fe6ee5e461c3053d40f23cc62882b6a59fe5 (diff) |
Rename to SOL002
Change the name of the project from mso-ve-vnfm-adapter
to etsi-sol002-adapter
Issue-ID: SO-2839
Signed-off-by: Piotr Borelowski <p.borelowski@partner.samsung.com>
Change-Id: Iba63d558fede145f2ff0086a75b3dadcd1296d00
Diffstat (limited to 'adapters/etsi-sol002-adapter/src/test/java/org')
6 files changed, 543 insertions, 0 deletions
diff --git a/adapters/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java b/adapters/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java new file mode 100644 index 0000000000..9406b299ea --- /dev/null +++ b/adapters/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java @@ -0,0 +1,81 @@ +/*- + * ============LICENSE_START======================================================= + * SO + * ================================================================================ + * Copyright (C) 2019 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.controller; + +import static org.junit.Assert.assertEquals; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.adapters.vevnfm.configuration.ConfigProperties; +import org.onap.so.adapters.vevnfm.configuration.StartupConfiguration; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpStatus; +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 static final String JSON = "{\"_links\":{\"vnfInstance\":{\"href\":null}}}"; + + private static final int ZERO = 0; + + @Autowired + private ConfigProperties configProperties; + + @Autowired + private WebApplicationContext webApplicationContext; + + private String notification; + private MockMvc mvc; + + @Before + public void init() { + notification = configProperties.getVnfmNotification(); + mvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); + } + + @Test + public void testReceiveNotification() throws Exception { + // given + final MockHttpServletRequestBuilder request = + MockMvcRequestBuilders.post(notification).contentType(MediaType.APPLICATION_JSON).content(JSON); + + // 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/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/provider/AuthorizationHeadersProviderTest.java b/adapters/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/provider/AuthorizationHeadersProviderTest.java new file mode 100644 index 0000000000..f9ae427086 --- /dev/null +++ b/adapters/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/provider/AuthorizationHeadersProviderTest.java @@ -0,0 +1,86 @@ +/*- + * ============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.provider; + +import static org.junit.Assert.*; +import static org.onap.so.configuration.rest.BasicHttpHeadersProvider.AUTHORIZATION_HEADER; +import org.junit.Test; +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(); + + @Test + public void testSuccessValidAuthorizationAndRemoval() { + final HttpHeaders headers = provider.getHttpHeaders(); + final int size = headers.size(); + + provider.addAuthorization(AUTHORIZATION_EXAMPLE); + assertEquals(size + 1, headers.size()); + assertTrue(headers.containsKey(AUTHORIZATION_HEADER)); + + provider.removeAuthorization(); + 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/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSenderTest.java b/adapters/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSenderTest.java new file mode 100644 index 0000000000..5af682dda8 --- /dev/null +++ b/adapters/etsi-sol002-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/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/StartupServiceTest.java b/adapters/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/StartupServiceTest.java new file mode 100644 index 0000000000..78d6ba899d --- /dev/null +++ b/adapters/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/StartupServiceTest.java @@ -0,0 +1,72 @@ +/*- + * ============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.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import java.util.Collections; +import java.util.List; +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.configuration.ConfigProperties; + +@RunWith(MockitoJUnitRunner.class) +public class StartupServiceTest { + + private static final String URL = "rt"; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Mock + private ConfigProperties configProperties; + + @Mock + private AaiConnection aaiConnection; + + @InjectMocks + private StartupService startupService; + + @Test + public void testSuccess() throws Exception { + // given + final EsrSystemInfo info = new EsrSystemInfo(); + info.setServiceUrl(URL); + final List<EsrSystemInfo> infos = Collections.singletonList(info); + + when(aaiConnection.receiveVnfm()).thenReturn(infos); + + // when + final List<EsrSystemInfo> systemInfo = startupService.receiveVnfm(); + + // then + verify(aaiConnection).receiveVnfm(); + assertEquals(infos, systemInfo); + } +} diff --git a/adapters/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/SubscribeSenderTest.java b/adapters/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/SubscribeSenderTest.java new file mode 100644 index 0000000000..e67e19fd8d --- /dev/null +++ b/adapters/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/SubscribeSenderTest.java @@ -0,0 +1,104 @@ +/*- + * ============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.ConfigProperties; +import org.onap.so.adapters.vevnfm.configuration.StartupConfiguration; +import org.onap.so.adapters.vevnfm.exception.VeVnfmException; +import org.onap.so.adapters.etsi.sol003.adapter.lcm.extclients.vnfm.model.LccnSubscriptionRequest; +import org.springframework.beans.factory.annotation.Autowired; +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(); + } + + @Autowired + private ConfigProperties configProperties; + + @Autowired + private SubscribeSender sender; + + @Autowired + private RestTemplate restTemplate; + + private String vnfmSubscription; + private MockRestServiceServer mockRestServer; + + @Before + public void init() { + vnfmSubscription = configProperties.getVnfmSubscription(); + 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/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/SubscriptionSchedulerTest.java b/adapters/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/SubscriptionSchedulerTest.java new file mode 100644 index 0000000000..d3da7c86ec --- /dev/null +++ b/adapters/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/SubscriptionSchedulerTest.java @@ -0,0 +1,69 @@ +/*- + * ============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.assertNull; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import java.util.Collections; +import java.util.List; +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.aai.domain.yang.EsrSystemInfo; + +@RunWith(MockitoJUnitRunner.class) +public class SubscriptionSchedulerTest { + + private static final String URL = "url"; + private static final String ID = "id044"; + + @Mock + private SubscriberService subscriberService; + + @InjectMocks + private SubscriptionScheduler subscriptionScheduler; + + @Test + public void testFullScenario() throws Exception { + // given + final EsrSystemInfo info = new EsrSystemInfo(); + info.setServiceUrl(URL); + final List<EsrSystemInfo> infos = Collections.singletonList(info); + + when(subscriberService.subscribe(eq(info))).thenReturn(ID); + when(subscriberService.checkSubscription(eq(info), eq(ID))).thenReturn(false); + + // when + subscriptionScheduler.setInfos(infos); + subscriptionScheduler.subscribeTask(); + subscriptionScheduler.checkSubscribeTask(); + + // then + verify(subscriberService).subscribe(info); + verify(subscriberService).checkSubscription(info, ID); + + assertNull(subscriptionScheduler.getEsrIds().get(0).getId()); + } +} |