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 --- .../automation/test/services/AsyncJobsService.java | 12 +++-- .../vid/api/AsyncInstantiationALaCarteApiTest.java | 57 ++++++++++++++++------ 2 files changed, 50 insertions(+), 19 deletions(-) diff --git a/vid-automation/src/main/java/vid/automation/test/services/AsyncJobsService.java b/vid-automation/src/main/java/vid/automation/test/services/AsyncJobsService.java index 35849b481..05d6553d3 100644 --- a/vid-automation/src/main/java/vid/automation/test/services/AsyncJobsService.java +++ b/vid-automation/src/main/java/vid/automation/test/services/AsyncJobsService.java @@ -1,16 +1,18 @@ package vid.automation.test.services; import com.google.common.collect.ImmutableList; -import vid.automation.test.utils.DB_CONFIG; - import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; import java.util.List; +import vid.automation.test.utils.DB_CONFIG; public class AsyncJobsService { + private static final String MUTE_JOB_STATEMENT = + "UPDATE `vid_job` SET `TAKEN_BY`='muteAllAsyncJobs', `JOB_STATUS`=CONCAT('MUTED_', `JOB_STATUS`), `AGE`=`AGE`+5 "; + public void dropAllAsyncJobs() { runStatementsInDb(ImmutableList.of( "DELETE FROM `vid_service_info`", @@ -44,7 +46,11 @@ public class AsyncJobsService { public void muteAllAsyncJobs() { - runStatementInDb("UPDATE `vid_job` SET `TAKEN_BY`='muteAllAsyncJobs', `JOB_STATUS`=CONCAT('MUTED_', `JOB_STATUS`), `AGE`=`AGE`+5 WHERE `TAKEN_BY` is NULL or `TAKEN_BY`<>'muteAllAsyncJobs'"); + runStatementInDb(MUTE_JOB_STATEMENT + "WHERE `TAKEN_BY` is NULL or `TAKEN_BY`<>'muteAllAsyncJobs'"); + } + + public void muteAsyncJobById(String uuid) { + runStatementInDb(MUTE_JOB_STATEMENT + String.format("WHERE JOB_ID='%s'",uuid)); } public void dropAllFromNameCounter() { 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