diff options
Diffstat (limited to 'vid-app-common/src/test/java/org/onap/vid/controller')
7 files changed, 92 insertions, 34 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java index a60aa7ea6..2377c8055 100644 --- a/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java @@ -21,8 +21,14 @@ package org.onap.vid.controller; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.booleanThat; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; @@ -34,13 +40,16 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Multimap; +import java.io.IOException; import java.util.Map; import java.util.UUID; +import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import org.mockito.junit.MockitoJUnitRunner; import org.onap.vid.aai.AaiResponse; import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigData; @@ -53,14 +62,18 @@ import org.onap.vid.aai.model.PortDetailsTranslator.PortDetails; import org.onap.vid.aai.model.PortDetailsTranslator.PortDetailsError; import org.onap.vid.aai.model.PortDetailsTranslator.PortDetailsOk; import org.onap.vid.aai.util.AAIRestInterface; +import org.onap.vid.properties.Features; +import org.onap.vid.roles.Role; import org.onap.vid.model.VersionByInvariantIdsRequest; import org.onap.vid.roles.RoleProvider; +import org.onap.vid.roles.RoleValidator; import org.onap.vid.services.AaiService; import org.onap.vid.utils.SystemPropertiesWrapper; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.togglz.core.manager.FeatureManager; @RunWith(MockitoJUnitRunner.class) public class AaiControllerTest { @@ -76,12 +89,16 @@ public class AaiControllerTest { private RoleProvider roleProvider; @Mock private SystemPropertiesWrapper systemPropertiesWrapper; + + @Mock + private FeatureManager featureManager; + private MockMvc mockMvc; private AaiController aaiController; @Before public void setUp() { - aaiController = new AaiController(aaiService, aaiRestInterface, roleProvider, systemPropertiesWrapper); + aaiController = new AaiController(aaiService, aaiRestInterface, roleProvider, systemPropertiesWrapper, featureManager); mockMvc = MockMvcBuilders.standaloneSetup(aaiController).build(); } @@ -248,5 +265,42 @@ public class AaiControllerTest { .andExpect(status().isOk()) .andExpect(content().string(expectedResponse)); } + + @Test + public void getSubscriberDetailsOmitServiceInstances_reduceDepthEnabledAndOmitQueryParam() throws IOException { + getSubscriberDetailsOmitServiceInstances("some subscriber id", + true, true, true); + } + + @Test + public void getSubscriberDetailsOmitServiceInstances_reduceDepthDisabledAndOmitQueryParam() throws IOException { + getSubscriberDetailsOmitServiceInstances("another-subscriber-id-123", + false, true, false); + } + + @Test + public void getSubscriberDetailsOmitServiceInstances_reduceDepthDisabled() throws IOException { + getSubscriberDetailsOmitServiceInstances("123-456-789-123-345-567-6", + false, false, false); + } + + @Test + public void getSubscriberDetailsOmitServiceInstances_reduceDepthEnabled() throws IOException { + getSubscriberDetailsOmitServiceInstances("0000000000000000000000000", + true, false, false); + } + + private void getSubscriberDetailsOmitServiceInstances(String subscriberId, boolean isFlag1906AaiSubDetailsReduceDepthEnabled, + boolean omitServiceInstancesQueryParam, boolean omitServiceInstancesExpectedGetSubscriberDataParam) throws IOException { + when(featureManager.isActive(Features.FLAG_1906_AAI_SUB_DETAILS_REDUCE_DEPTH)).thenReturn(isFlag1906AaiSubDetailsReduceDepthEnabled); + HttpServletRequest request = mock(HttpServletRequest.class); + when(roleProvider.getUserRoles(request)).thenReturn(ImmutableList.of(mock(Role.class), mock(Role.class))); + AaiResponse subscriberData = mock(AaiResponse.class); + when(subscriberData.getT()).thenReturn(null); + when(subscriberData.getHttpCode()).thenReturn(200); + when(aaiService.getSubscriberData(any(), any(), anyBoolean())).thenReturn(subscriberData); + aaiController.getSubscriberDetails(request, subscriberId, omitServiceInstancesQueryParam); + verify(aaiService).getSubscriberData(argThat(subscriberId::equals), any(RoleValidator.class), booleanThat(b -> omitServiceInstancesExpectedGetSubscriberDataParam == b)); + } } diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/AaiServiceInstanceStandardQueryControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/AaiServiceInstanceStandardQueryControllerTest.java index 2a8db9650..b036b4794 100644 --- a/vid-app-common/src/test/java/org/onap/vid/controller/AaiServiceInstanceStandardQueryControllerTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/controller/AaiServiceInstanceStandardQueryControllerTest.java @@ -7,9 +7,9 @@ * 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. @@ -20,18 +20,20 @@ package org.onap.vid.controller; -import org.mockito.Answers; +import com.google.common.collect.ImmutableList; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.onap.vid.aai.util.ServiceInstanceStandardQuery; import org.onap.vid.asdc.AsdcCatalogException; import org.onap.vid.model.Service; import org.onap.vid.model.ServiceModel; import org.onap.vid.model.VidNotions; import org.onap.vid.model.VidNotions.ModelCategory; +import org.onap.vid.model.aaiTree.AAITreeNode; import org.onap.vid.properties.Features; +import org.onap.vid.services.AAIServiceTree; import org.onap.vid.services.VidService; +import org.springframework.http.HttpMethod; import org.springframework.mock.web.MockHttpServletRequest; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; @@ -56,8 +58,9 @@ public class AaiServiceInstanceStandardQueryControllerTest { @Mock private VidService sdcService; - @Mock(answer = Answers.RETURNS_MOCKS) - private ServiceInstanceStandardQuery serviceInstanceStandardQuery; + @Mock + private AAIServiceTree aaiServiceTree; + //Don't use initMocks with @BeforeMethod //because AaiServiceInstanceStandardQueryController contains final members that can not be injected twice @@ -69,7 +72,7 @@ public class AaiServiceInstanceStandardQueryControllerTest { @AfterMethod public void resetMocks() { - reset(sdcService, featureManager, serviceInstanceStandardQuery); + reset(sdcService, featureManager); } @Test @@ -80,13 +83,14 @@ public class AaiServiceInstanceStandardQueryControllerTest { // - assert that AAI was accessed when(featureManager.isActive(Features.FLAG_PRESENT_PROVIDER_NETWORKS_ASSOCIATIONS)).thenReturn(true); + when(aaiServiceTree.buildAAITree(any(), any(), any(HttpMethod.class), any(), anyBoolean())).thenReturn(ImmutableList.of(mock(AAITreeNode.class))); final UUID randomModelUuid = UUID.randomUUID(); mockServiceModel(ModelCategory.IS_5G_PROVIDER_NETWORK_MODEL, randomModelUuid); doGetNetworksToVlansByServiceInstance(randomModelUuid); - verify(serviceInstanceStandardQuery).fetchServiceInstance(any(), any(), any()); + verify(aaiServiceTree).buildAAITree(any(), any(), any(HttpMethod.class), any(), anyBoolean()); } @Test @@ -103,7 +107,7 @@ public class AaiServiceInstanceStandardQueryControllerTest { mockServiceModel(ModelCategory.OTHER, randomModelUuid); assertThat(doGetNetworksToVlansByServiceInstance(randomModelUuid).serviceNetworks, hasSize(0)); - verifyZeroInteractions(serviceInstanceStandardQuery); + verifyZeroInteractions(aaiServiceTree); } @Test @@ -123,7 +127,7 @@ public class AaiServiceInstanceStandardQueryControllerTest { Service mockedService = mock(Service.class); when(mockedModel.getService()).thenReturn(mockedService); when(mockedService.getVidNotions()).thenReturn( - new VidNotions(instantiationUI, modelCategory, VidNotions.InstantiationUI.LEGACY) + new VidNotions(instantiationUI, modelCategory, VidNotions.InstantiationUI.LEGACY, VidNotions.InstantiationType.ALaCarte) ); when(sdcService.getService(randomModelUuid.toString())).thenReturn(mockedModel); @@ -137,4 +141,4 @@ public class AaiServiceInstanceStandardQueryControllerTest { "my service type", "my instance id"); } -} +}
\ No newline at end of file diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/LocalWebConfig.java b/vid-app-common/src/test/java/org/onap/vid/controller/LocalWebConfig.java index 7e50c8959..701f1c62a 100644 --- a/vid-app-common/src/test/java/org/onap/vid/controller/LocalWebConfig.java +++ b/vid-app-common/src/test/java/org/onap/vid/controller/LocalWebConfig.java @@ -44,6 +44,7 @@ import org.togglz.core.manager.FeatureManager; import javax.servlet.ServletContext; import java.io.File; +import java.util.concurrent.ExecutorService; @Configuration public class LocalWebConfig { @@ -66,8 +67,8 @@ public class LocalWebConfig { @Bean public AaiService getAaiService(AaiClientInterface aaiClient, AaiOverTLSClientInterface aaiOverTLSClient, - AaiResponseTranslator aaiResponseTranslator, AAITreeNodeBuilder aaiTreeNode, AAIServiceTree aaiServiceTree) { - return new AaiServiceImpl(aaiClient, aaiOverTLSClient, aaiResponseTranslator, aaiTreeNode, aaiServiceTree); + AaiResponseTranslator aaiResponseTranslator, AAITreeNodeBuilder aaiTreeNode, AAIServiceTree aaiServiceTree, ExecutorService executorService) { + return new AaiServiceImpl(aaiClient, aaiOverTLSClient, aaiResponseTranslator, aaiTreeNode, aaiServiceTree, executorService); } @Bean diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerNewTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerNewTest.java index a5222dd04..43edeebe9 100644 --- a/vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerNewTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerNewTest.java @@ -20,24 +20,24 @@ package org.onap.vid.controller; +import static org.mockito.Mockito.mock; + +import javax.servlet.http.HttpServletRequest; import org.junit.Test; import org.onap.vid.mso.MsoBusinessLogicImpl; import org.onap.vid.mso.MsoInterface; +import org.onap.vid.mso.rest.MsoRestClientNew; import org.onap.vid.mso.rest.RequestDetails; import org.onap.vid.mso.rest.RequestDetailsWrapper; import org.onap.vid.services.CloudOwnerServiceImpl; import org.springframework.http.ResponseEntity; -import org.togglz.core.manager.FeatureManager; - -import javax.servlet.http.HttpServletRequest; - -import static org.mockito.Mockito.mock; public class MsoControllerNewTest { private MsoController createTestSubject() { try { - return new MsoController(new MsoBusinessLogicImpl(mock(MsoInterface.class),mock(FeatureManager.class)), new CloudOwnerServiceImpl(null, null)); + return new MsoController(new MsoBusinessLogicImpl(mock(MsoInterface.class)), mock(MsoRestClientNew.class), + new CloudOwnerServiceImpl(null, null)); } catch (Exception e) { return null; } diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerTest.java index 02ab287be..a1b45590c 100644 --- a/vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerTest.java @@ -46,6 +46,7 @@ import org.junit.Before; import org.junit.Test; import org.onap.vid.mso.MsoBusinessLogic; import org.onap.vid.mso.MsoResponseWrapper; +import org.onap.vid.mso.rest.MsoRestClientNew; import org.onap.vid.mso.rest.Request; import org.onap.vid.mso.rest.RequestDetails; import org.onap.vid.mso.rest.Task; @@ -66,12 +67,14 @@ public class MsoControllerTest { private MockMvc mockMvc; private MsoBusinessLogic msoBusinessLogic; private CloudOwnerService cloudService; + private MsoRestClientNew msoRestClient; @Before public void setUp() { msoBusinessLogic = mock(MsoBusinessLogic.class); cloudService = mock(CloudOwnerService.class); - MsoController msoController = new MsoController(msoBusinessLogic, cloudService); + msoRestClient = mock(MsoRestClientNew.class); + MsoController msoController = new MsoController(msoBusinessLogic, msoRestClient, cloudService); mockMvc = MockMvcBuilders.standaloneSetup(msoController).build(); } diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/ToscaParserMockHelper.java b/vid-app-common/src/test/java/org/onap/vid/controller/ToscaParserMockHelper.java index 2eedee9d7..9e77e99e3 100644 --- a/vid-app-common/src/test/java/org/onap/vid/controller/ToscaParserMockHelper.java +++ b/vid-app-common/src/test/java/org/onap/vid/controller/ToscaParserMockHelper.java @@ -22,25 +22,21 @@ package org.onap.vid.controller; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.module.kotlin.KotlinModule; -import org.apache.commons.io.IOUtils; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; -import org.onap.vid.model.NewServiceModel; - import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import org.apache.commons.io.IOUtils; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; +import org.onap.vid.model.ServiceModel; -/** - * Created by moriya1 on 04/07/2017. - */ public class ToscaParserMockHelper { private static final Logger logger = LogManager.getLogger(ToscaParserMockHelper.class); private static final ObjectMapper om = new ObjectMapper(); private final String uuid; private final String filePath; - private final NewServiceModel newServiceModel; + private final ServiceModel serviceModel; public ToscaParserMockHelper(String uuid, String filePath) throws IOException { this.uuid = uuid; @@ -50,7 +46,7 @@ public class ToscaParserMockHelper { logger.info(jsonFile); String expectedJsonAsString = IOUtils.toString(jsonFile, StandardCharsets.UTF_8.name()); om.registerModule(new KotlinModule()); - this.newServiceModel = om.readValue(expectedJsonAsString, NewServiceModel.class); + this.serviceModel = om.readValue(expectedJsonAsString, ServiceModel.class); } public String getUuid() { @@ -61,7 +57,7 @@ public class ToscaParserMockHelper { return filePath; } - public NewServiceModel getNewServiceModel() { - return newServiceModel; + public ServiceModel getServiceModel() { + return serviceModel; } } diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/VidControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/VidControllerTest.java index 39d3cddc7..484f4a034 100644 --- a/vid-app-common/src/test/java/org/onap/vid/controller/VidControllerTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/controller/VidControllerTest.java @@ -178,7 +178,7 @@ public class VidControllerTest { private ServiceModel createServiceModel(int i) { ServiceModel model = new ServiceModel(); - model.setCollectionResource(ImmutableMap.of("resKey" + i, new CR())); + model.setCollectionResources(ImmutableMap.of("resKey" + i, new CR())); model.setNetworks(ImmutableMap.of("network" + i, new Network())); model.setPnfs(ImmutableMap.of("pnf" + i, new Node())); model.setServiceProxies(ImmutableMap.of("servProxy" + i, new ServiceProxy())); |