From 4e2d89221395442475eb2d681dfe61a3584d2496 Mon Sep 17 00:00:00 2001 From: Eylon Malin Date: Wed, 4 Dec 2019 10:30:09 +0200 Subject: improve test deployTwoServicesGetServicesFilterByModelId Issue-ID: VID-724 Test validate that only expected jobIds are in service info list + always mute jobs att the end of the test Signed-off-by: Eylon Malin Change-Id: I3cfa35ae5f31cf72dcf8b4ac3e250f9473080693 --- .../vid/api/AsyncInstantiationALaCarteApiTest.java | 57 ++++++++++++++++------ 1 file changed, 41 insertions(+), 16 deletions(-) (limited to 'vid-automation/src/test/java') diff --git a/vid-automation/src/test/java/org/onap/vid/api/AsyncInstantiationALaCarteApiTest.java b/vid-automation/src/test/java/org/onap/vid/api/AsyncInstantiationALaCarteApiTest.java index 78257b398..c32c88525 100644 --- a/vid-automation/src/test/java/org/onap/vid/api/AsyncInstantiationALaCarteApiTest.java +++ b/vid-automation/src/test/java/org/onap/vid/api/AsyncInstantiationALaCarteApiTest.java @@ -10,6 +10,7 @@ import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.matchesPattern; +import static org.hamcrest.Matchers.not; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; import static org.onap.simulator.presetGenerator.presets.BasePresets.BaseMSOPreset.DEFAULT_INSTANCE_ID; import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOBaseCreateInstancePost.DEFAULT_REQUEST_ID; @@ -26,6 +27,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.stream.Stream; import org.onap.simulator.presetGenerator.presets.BasePresets.BaseMSOPreset; import org.onap.simulator.presetGenerator.presets.BasePresets.BasePreset; import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetCloudOwnersByCloudRegionId; @@ -127,22 +129,45 @@ public class AsyncInstantiationALaCarteApiTest extends AsyncInstantiationBase { @Test public void deployTwoServicesGetServicesFilterByModelId() { - final ImmutableMap names = ImmutableMap - .of(SERVICE_NAME, "calazixide85"); - - final List uuids1 = createBulkOfInstances(false, 2, names, CREATE_BULK_OF_ALACARTE_REQUEST); - final List uuids2 = createBulkOfInstances(false, 1, names, DELETE_BULK_OF_ALACARTE_REQUEST); - - String SERVICE_MODEL_UUID = "e3c34d88-a216-4f1d-a782-9af9f9588705"; - ResponseEntity> response = restTemplate.exchange( - getServiceInfoUrl() + "?serviceModelId=" + SERVICE_MODEL_UUID, - HttpMethod.GET, - null, - new ParameterizedTypeReference>() { - }); - assertThat(response.getBody().stream().map(x -> x.serviceModelId).collect(toSet()), - contains(SERVICE_MODEL_UUID)); - + List uuids = new LinkedList<>(); + try { + //given + final ImmutableMap names = ImmutableMap + .of(SERVICE_NAME, "calazixide85"); + + String SERVICE_MODEL_UUID = "e3c34d88-a216-4f1d-a782-9af9f9588705"; + + uuids = Stream.of( + createBulkOfInstances(false, 1, names, CREATE_BULK_OF_ALACARTE_REQUEST).get(0), + createBulkOfInstances(false, 1, names, CREATE_BULK_OF_ALACARTE_REQUEST).get(0), + createBulkOfInstances(false, 1, names, CREATE_BULK_OF_MACRO_REQUEST).get(0) + ).collect(toList()); + + //when + ResponseEntity> response = restTemplate.exchange( + getServiceInfoUrl() + "?serviceModelId=" + SERVICE_MODEL_UUID, + HttpMethod.GET, + null, + new ParameterizedTypeReference>() { + }); + + //then + final List body = response.getBody(); + + //assert that service info list contains only services with desired modelId + assertThat(body.stream().map(x -> x.serviceModelId).collect(toSet()), + contains(SERVICE_MODEL_UUID)); + //assert that service info list contains the 2 first jobs + assertThat(body.stream().map(x -> x.jobId).collect(toList()), + hasItems(uuids.get(0), uuids.get(1))); + //assert that service info list doesn't contains last jobs + assertThat(body.stream().map(x -> x.jobId).collect(toList()), + not(hasItems(uuids.get(2)))); + } + finally { + //clear jobs to not disturb next tests + uuids.forEach(uuid->new AsyncJobsService().muteAsyncJobById(uuid)); + } } -- cgit 1.2.3-korg