aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEylon Malin <eylon.malin@intl.att.com>2019-12-04 10:30:09 +0200
committerEylon Malin <eylon.malin@intl.att.com>2019-12-04 10:30:09 +0200
commit4e2d89221395442475eb2d681dfe61a3584d2496 (patch)
treeb4db87f9deaf2cc8786d35dbf9099e8cf61d6527
parent9e65dc01257d59b78f89077b94cc6393efef1893 (diff)
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 <eylon.malin@intl.att.com> Change-Id: I3cfa35ae5f31cf72dcf8b4ac3e250f9473080693
-rw-r--r--vid-automation/src/main/java/vid/automation/test/services/AsyncJobsService.java12
-rw-r--r--vid-automation/src/test/java/org/onap/vid/api/AsyncInstantiationALaCarteApiTest.java57
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<PresetMSOServiceInstanceGen2WithNames.Keys, String> names = ImmutableMap
- .of(SERVICE_NAME, "calazixide85");
-
- final List<String> uuids1 = createBulkOfInstances(false, 2, names, CREATE_BULK_OF_ALACARTE_REQUEST);
- final List<String> uuids2 = createBulkOfInstances(false, 1, names, DELETE_BULK_OF_ALACARTE_REQUEST);
-
- String SERVICE_MODEL_UUID = "e3c34d88-a216-4f1d-a782-9af9f9588705";
- ResponseEntity<List<ServiceInfo>> response = restTemplate.exchange(
- getServiceInfoUrl() + "?serviceModelId=" + SERVICE_MODEL_UUID,
- HttpMethod.GET,
- null,
- new ParameterizedTypeReference<List<ServiceInfo>>() {
- });
- assertThat(response.getBody().stream().map(x -> x.serviceModelId).collect(toSet()),
- contains(SERVICE_MODEL_UUID));
-
+ List<String> uuids = new LinkedList<>();
+ try {
+ //given
+ final ImmutableMap<PresetMSOServiceInstanceGen2WithNames.Keys, String> 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<List<ServiceInfo>> response = restTemplate.exchange(
+ getServiceInfoUrl() + "?serviceModelId=" + SERVICE_MODEL_UUID,
+ HttpMethod.GET,
+ null,
+ new ParameterizedTypeReference<List<ServiceInfo>>() {
+ });
+
+ //then
+ final List<ServiceInfo> 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));
+ }
}