diff options
5 files changed, 116 insertions, 34 deletions
diff --git a/vid-app-common/pom.xml b/vid-app-common/pom.xml index 38b06f1f8..8482ae627 100755 --- a/vid-app-common/pom.xml +++ b/vid-app-common/pom.xml @@ -472,6 +472,12 @@ <version>0.9.3</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.jeasy</groupId> + <artifactId>easy-random-core</artifactId> + <version>4.0.0.RC1</version> + <scope>test</scope> + </dependency> <!-- Helpers --> <dependency> diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java index 83757f2fb..142bf73ec 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java @@ -320,8 +320,6 @@ public class AaiServiceImpl implements AaiService { return aaiClient.getPNFData(globalCustomerId, serviceType, modelVersionId, modelInvariantId, cloudRegion, equipVendor, equipModel); } - - @Override public AaiResponse getServices(RoleValidator roleValidator) { AaiResponse<GetServicesAAIRespone> subscriberResponse = aaiClient.getServices(); diff --git a/vid-app-common/src/main/java/org/onap/vid/services/WorkflowServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/WorkflowServiceImpl.java index 097b05e58..cbc79e86f 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/WorkflowServiceImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/WorkflowServiceImpl.java @@ -20,6 +20,7 @@ package org.onap.vid.services; +import java.util.List; import org.onap.vid.model.Workflow; import org.springframework.stereotype.Service; @@ -31,29 +32,27 @@ import java.util.stream.Collectors; @Service public class WorkflowServiceImpl implements WorkflowService { //TODO: Add the list of workflows hard coded or from DB. - private ArrayList<Workflow> workflows = new ArrayList<>(Arrays.asList( + private List<Workflow> workflows = Arrays.asList( new Workflow(0, "Upgrade", new ArrayList<>(Arrays.asList("VNF1", "VNF2", "VNF3", "VNF4"))), new Workflow(1, "Clean", new ArrayList<>(Arrays.asList("VNF1", "VNF2", "VNF3"))), new Workflow(2, "Reinstall", new ArrayList<>(Arrays.asList("VNF1", "VNF2", "VNF4"))), new Workflow(3, "Dump", new ArrayList<>(Arrays.asList("VNF1", "VNF3", "VNF4"))), new Workflow(4, "Flush", new ArrayList<>(Arrays.asList("VNF2", "VNF3", "VNF4"))) - )); + ); @Override public Collection<String> getWorkflowsForVNFs(Collection<String> vnfNames) { - Collection<String> result = workflows.stream() + return workflows.stream() .filter(workflow -> workflow.getVnfNames().containsAll(vnfNames)) - .map(workflow -> workflow.getWorkflowName()) + .map(Workflow::getWorkflowName) .distinct() .collect(Collectors.toList()); - - return result; } @Override public Collection<String> getAllWorkflows() { return workflows.stream() - .map(workflow -> workflow.getWorkflowName()) + .map(Workflow::getWorkflowName) .distinct() .collect(Collectors.toList()); } diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java index 23951aa3d..59cee89b2 100644 --- a/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java @@ -8,9 +8,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. @@ -23,24 +23,36 @@ package org.onap.vid.services; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import javax.ws.rs.core.Response; +import org.jeasy.random.EasyRandom; +import org.jeasy.random.EasyRandomParameters; +import org.jeasy.random.randomizers.misc.BooleanRandomizer; +import org.jeasy.random.randomizers.text.StringRandomizer; import org.junit.Test; import org.onap.vid.aai.AaiClientInterface; import org.onap.vid.aai.AaiGetVnfResponse; import org.onap.vid.aai.AaiOverTLSClientInterface; import org.onap.vid.aai.AaiResponse; import org.onap.vid.aai.AaiResponseTranslator; +import org.onap.vid.aai.model.AaiGetServicesRequestModel.GetServicesAAIRespone; import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse; import org.onap.vid.aai.model.VnfResult; import org.onap.vid.roles.RoleValidator; public class AaiServiceImplTest { + private static final long STATIC_SEED = 5336L; + private EasyRandomParameters parameters = new EasyRandomParameters() + .randomize(String.class, new StringRandomizer(4, 4, STATIC_SEED)) + .randomize(Boolean.class, new BooleanRandomizer(STATIC_SEED)); + private EasyRandom modelGenerator = new EasyRandom(parameters); + private AaiClientInterface aaiClient = mock(AaiClientInterface.class); private AaiOverTLSClientInterface aaiSslClient = mock(AaiOverTLSClientInterface.class); private AaiResponseTranslator aaiResponseTranslator = mock(AaiResponseTranslator.class); @@ -185,4 +197,81 @@ public class AaiServiceImplTest { assertThat(response).isEqualTo(actual); assertThat(response.getT().results).containsOnly(genericVnf, serviceInstance); } -} + + @Test + @SuppressWarnings("unchecked") + public void getServicesShouldMarkAllServicesAsPermitted() { + // given + RoleValidator roleValidator = modelGenerator.nextObject(RoleValidator.class); + + GetServicesAAIRespone inputPayload = modelGenerator.nextObject(GetServicesAAIRespone.class); + assertThat(inputPayload.service.stream().allMatch(service -> service.isPermitted)).isFalse(); + + when(aaiClient.getServices()).thenReturn(new AaiResponse<>(inputPayload, "", 200)); + + // when + AaiResponse<GetServicesAAIRespone> result = aaiService.getServices(roleValidator); + GetServicesAAIRespone outputPayload = result.getT(); + + // then + assertThat(outputPayload.service.stream().allMatch(service -> service.isPermitted)).isTrue(); + } + + @Test + public void shouldGetNodeTemplateInstances() { + // given + String globalCustomerId = "gcid"; + String serviceType = "st"; + String modelVersionId = "mvid"; + String modelInvariantId = "miid"; + String cloudRegion = "cr"; + + // when + aaiService + .getNodeTemplateInstances(globalCustomerId, serviceType, modelVersionId, modelInvariantId, cloudRegion); + + // then + verify(aaiClient) + .getNodeTemplateInstances(globalCustomerId, serviceType, modelVersionId, modelInvariantId, cloudRegion); + } + + @Test + public void shouldGetNetworkCollectionDetails() { + // given + String serviceInstanceId = "siid"; + + // when + aaiService.getNetworkCollectionDetails(serviceInstanceId); + + // then + verify(aaiClient).getNetworkCollectionDetails(serviceInstanceId); + } + + @Test + public void shouldGetInstanceGroupsByCloudRegion() { + // given + String cloudOwner = "co"; + String cloudRegionId = "crid"; + String networkFunction = "nf"; + + // when + aaiService.getInstanceGroupsByCloudRegion(cloudOwner, cloudRegionId, networkFunction); + + // then + verify(aaiClient).getInstanceGroupsByCloudRegion(cloudOwner, cloudRegionId, networkFunction); + } + + @Test + public void getAAIServiceTree() { + // given + String globalCustomerId = "gcid"; + String serviceType = "st"; + String serviceInstanceId = "siid"; + + // when + aaiService.getAAIServiceTree(globalCustomerId, serviceType, serviceInstanceId); + + // then + verify(aaiServiceTree).getServiceInstanceTopology(globalCustomerId, serviceType, serviceInstanceId); + } +}
\ No newline at end of file diff --git a/vid-app-common/src/test/java/org/onap/vid/services/WorkflowServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/WorkflowServiceImplTest.java index a8ded2719..fa53a9a80 100644 --- a/vid-app-common/src/test/java/org/onap/vid/services/WorkflowServiceImplTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/services/WorkflowServiceImplTest.java @@ -3,13 +3,14 @@ * VID * ================================================================================ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 - 2020 Nokia. 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. @@ -20,34 +21,23 @@ package org.onap.vid.services; -import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; +import java.util.Arrays; +import java.util.Collection; import org.junit.Test; public class WorkflowServiceImplTest { - private WorkflowServiceImpl createTestSubject() { - return new WorkflowServiceImpl(); - } - @Test - public void testGetWorkflowsForVNFs() throws Exception { - WorkflowServiceImpl testSubject; - Collection<String> vnfNames = new ArrayList<String>(); - Collection<String> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getWorkflowsForVNFs(vnfNames); + public void testGetWorkflowsForVNFs() { + Collection<String> result = new WorkflowServiceImpl().getWorkflowsForVNFs(Arrays.asList("VNF1", "VNF2")); + assertThat(result).containsExactly("Upgrade", "Clean", "Reinstall"); } @Test - public void testGetAllWorkflows() throws Exception { - WorkflowServiceImpl testSubject; - Collection<String> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getAllWorkflows(); + public void testGetAllWorkflows() { + Collection<String> result = new WorkflowServiceImpl().getAllWorkflows(); + assertThat(result).containsExactly("Upgrade", "Clean", "Reinstall", "Dump", "Flush"); } } |