diff options
Diffstat (limited to 'vid-app-common/src/test')
-rw-r--r-- | vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java | 95 | ||||
-rw-r--r-- | vid-app-common/src/test/java/org/onap/vid/services/WorkflowServiceImplTest.java | 34 |
2 files changed, 104 insertions, 25 deletions
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"); } } |