1 package org.onap.vid.api;
3 import static java.lang.Boolean.FALSE;
4 import static java.lang.Boolean.TRUE;
5 import static java.util.Collections.emptyList;
6 import static java.util.stream.Collectors.joining;
7 import static java.util.stream.Collectors.toMap;
8 import static org.hamcrest.CoreMatchers.hasItem;
9 import static org.hamcrest.MatcherAssert.assertThat;
10 import static org.hamcrest.Matchers.containsInAnyOrder;
11 import static org.hamcrest.Matchers.hasSize;
12 import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames.Keys;
13 import static org.testng.Assert.assertNotNull;
14 import static org.testng.AssertJUnit.assertEquals;
15 import static org.testng.AssertJUnit.assertTrue;
16 import static vid.automation.test.utils.ExtendedHamcrestMatcher.hasItemsFromCollection;
18 import com.google.common.collect.ImmutableList;
19 import com.google.common.collect.ImmutableSet;
20 import com.google.common.util.concurrent.Uninterruptibles;
21 import java.time.Instant;
22 import java.util.List;
25 import java.util.UUID;
26 import java.util.concurrent.TimeUnit;
27 import java.util.concurrent.atomic.AtomicReference;
28 import java.util.function.Predicate;
29 import java.util.stream.Collectors;
30 import java.util.stream.IntStream;
31 import java.util.stream.Stream;
32 import org.apache.commons.lang3.StringUtils;
33 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
34 import org.apache.commons.lang3.builder.ToStringStyle;
35 import org.hamcrest.BaseMatcher;
36 import org.hamcrest.CoreMatchers;
37 import org.hamcrest.Description;
38 import org.hamcrest.MatcherAssert;
39 import org.onap.simulator.presetGenerator.presets.BasePresets.BaseMSOPreset;
40 import org.onap.simulator.presetGenerator.presets.BasePresets.BasePreset;
41 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetCloudOwnersByCloudRegionId;
42 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet;
43 import org.onap.simulator.presetGenerator.presets.ecompportal_att.PresetGetSessionSlotCheckIntervalGet;
44 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOBaseCreateInstancePost;
45 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOBaseDelete;
46 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOCreateServiceInstanceGen2WithNames;
47 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet;
48 import org.onap.vid.model.asyncInstantiation.JobAuditStatus;
49 import org.onap.vid.model.asyncInstantiation.ServiceInfo;
50 import org.onap.vid.model.mso.MsoResponseWrapper2;
51 import org.springframework.core.ParameterizedTypeReference;
52 import org.springframework.http.HttpMethod;
53 import org.springframework.http.HttpStatus;
54 import org.springframework.http.ResponseEntity;
55 import org.springframework.web.client.RestTemplate;
56 import org.testng.Assert;
57 import org.testng.annotations.AfterMethod;
58 import org.testng.annotations.BeforeClass;
59 import org.testng.annotations.DataProvider;
60 import vid.automation.test.infra.Features;
61 import vid.automation.test.infra.Wait;
62 import vid.automation.test.model.JobStatus;
63 import vid.automation.test.model.ServiceAction;
64 import vid.automation.test.services.AsyncJobsService;
65 import vid.automation.test.services.SimulatorApi;
67 public class AsyncInstantiationBase extends BaseMsoApiTest {
69 public static final String CREATE_BULK_OF_ALACARTE_REQUEST_WITH_VNF = "asyncInstantiation/vidRequestCreateALaCarteWithVnf.json";
70 protected static final String CREATE_BULK_OF_MACRO_REQUEST = "asyncInstantiation/vidRequestCreateBulkOfMacro.json";
72 protected static final String MSO_BASE_ERROR =
73 "Received error from SDN-C: java.lang.IllegalArgumentException: All keys must be specified for class org."+
74 "opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.vf.module.assignments.vf."+
75 "module.assignments.vms.VmKey. Missing key is getVmType. Supplied key is VmKey [].";
76 protected static final String MSO_ERROR = MSO_BASE_ERROR + StringUtils.repeat(" and a lot of sentences for long message", 60);
79 protected void muteAndDropNameCounter() {
80 AsyncJobsService asyncJobsService = new AsyncJobsService();
81 asyncJobsService.muteAllAsyncJobs();
82 asyncJobsService.dropAllFromNameCounter();
86 protected void muteAllAsyncJobs() {
87 AsyncJobsService asyncJobsService = new AsyncJobsService();
88 asyncJobsService.muteAllAsyncJobs();
92 public static Object[][] trueAndFalse() {
93 return new Object[][]{{TRUE},{FALSE}};
96 protected String getCreateBulkUri() {
97 return uri.toASCIIString() + "/asyncInstantiation/bulk";
100 protected String getHideServiceUri(String jobId) {
101 return uri.toASCIIString() + "/asyncInstantiation/hide/"+jobId;
104 protected String getServiceInfoUrl() {
105 return uri.toASCIIString() + "/asyncInstantiation";
108 protected String getTemplateInfoUrl(String serviceModelId) {
109 return uri.toASCIIString() + "/instantiationTemplates?serviceModelId=" + serviceModelId;
112 protected String getJobAuditUrl() {
113 return uri.toASCIIString() + "/asyncInstantiation/auditStatus/{JOB_ID}?source={SOURCE}";
116 protected String getMsoJobAuditUrl() {
117 return uri.toASCIIString() + "/asyncInstantiation/auditStatus/{JOB_ID}/mso";
120 protected String getDeleteServiceUrl(String uuid) {
121 return uri.toASCIIString() + "/asyncInstantiation/job/" + uuid;
124 protected String getInstanceAuditInfoUrl() {
125 return uri.toASCIIString() + "/asyncInstantiation/auditStatus/{TYPE}/{INSTANCE_ID}/mso";
128 protected String getRetryJobUrl() {
129 return uri.toASCIIString() + "/asyncInstantiation/retry/{JOB_ID}";
131 protected String getTopologyForRetryUrl() {
132 return uri.toASCIIString() + "/asyncInstantiation/bulkForRetry/{JOB_ID}";
136 protected String getRetryJobWithChangedDataUrl() {
137 return uri.toASCIIString() + "/asyncInstantiation/retryJobWithChangedData/{JOB_ID}";
140 protected boolean getExpectedRetryEnabled(JobStatus jobStatus) {
141 return Features.FLAG_1902_RETRY_JOB.isActive() && (jobStatus==JobStatus.FAILED || jobStatus==JobStatus.COMPLETED_WITH_ERRORS);
144 public List<BasePreset> getPresets(List<PresetMSOBaseDelete> presetOnDeleteList, List<PresetMSOBaseCreateInstancePost> presetOnCreateList, List<PresetMSOOrchestrationRequestGet> presetInProgressList) {
146 final ImmutableList.Builder<BasePreset> basePresetBuilder = new ImmutableList.Builder<>();
148 .add(new PresetGetSessionSlotCheckIntervalGet())
149 .add(new PresetAAIGetSubscribersGet())
150 .addAll(presetOnDeleteList)
151 .addAll(presetOnCreateList)
152 .addAll(presetInProgressList);
153 return basePresetBuilder.build();
156 public List<BasePreset> getDeletePresets(List<PresetMSOBaseDelete> presetOnDeleteList, List<PresetMSOOrchestrationRequestGet> presetInProgressList) {
157 return getPresets(presetOnDeleteList, emptyList(), presetInProgressList);
160 public List<BasePreset> getPresets(List<PresetMSOBaseCreateInstancePost> presetOnCreateList, List<PresetMSOOrchestrationRequestGet> presetInProgressList) {
161 return getPresets(emptyList(), presetOnCreateList, presetInProgressList);
164 public void assertServiceInfoSpecific1(String jobId, JobStatus jobStatus, String serviceInstanceName, String userName) {
165 assertServiceInfoSpecific1(jobId, jobStatus, serviceInstanceName, userName, null, ServiceAction.INSTANTIATE);
168 public void assertServiceInfoSpecific1(String jobId, JobStatus jobStatus, String serviceInstanceName, String userName, String instanceId, ServiceAction action) {
169 assertExpectedStatusAndServiceInfo(jobStatus, jobId, new ServiceInfo(
170 userName, jobStatus, false,
171 "038d99af-0427-42c2-9d15-971b99b9b489", "Lucine Sarika", "zasaki",
172 "de738e5f-3704-4a14-b98f-3bf86ac0c0a0", "voloyakane-senamo",
173 "c85f0e80-0636-44a4-8cb2-4ec00d056e79", "Hedvika Wendelin",
174 "a93f8383-707e-43fa-8191-a6e69a1aab17", null,
175 "TYLER SILVIA", "SILVIA ROBBINS",
176 instanceId, serviceInstanceName,
177 "e3c34d88-a216-4f1d-a782-9af9f9588705", "gayawabawe", "5.1",
178 jobId, null, action, false)
182 public void assertServiceInfoSpecific1(String jobId, JobStatus jobStatus, String serviceInstanceName) {
183 assertServiceInfoSpecific1(jobId, jobStatus, serviceInstanceName, "us16807000");
186 protected void assertAuditStatuses(String jobId, List<JobAuditStatus> expectedVidStatuses, List<JobAuditStatus> expectedMsoStatuses) {
187 assertAuditStatuses(jobId, expectedVidStatuses, expectedMsoStatuses, 15);
190 protected void assertAuditStatuses(String jobId, List<JobAuditStatus> expectedVidStatuses, List<JobAuditStatus> expectedMsoStatuses, long timeoutInSeconds) {
191 assertAndRetryIfNeeded(() -> {
192 final List<JobAuditStatus> auditVidStatuses = getAuditStatuses(jobId, JobAuditStatus.SourceStatus.VID.name());
193 assertThat(auditVidStatuses, hasItemsFromCollection(expectedVidStatuses));
194 if (expectedMsoStatuses!=null) {
195 final List<JobAuditStatus> auditMsoStatuses = getAuditStatuses(jobId, JobAuditStatus.SourceStatus.MSO.name());
196 assertThat(auditMsoStatuses, containsInAnyOrder(expectedMsoStatuses.toArray()));
198 }, timeoutInSeconds);
201 protected void assertAndRetryIfNeeded(Runnable asserter, long timeoutInSeconds) {
202 final Instant expiry = Instant.now().plusSeconds(timeoutInSeconds);
206 break; // we're cool, assertion passed
207 } catch (AssertionError fail) {
208 Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
209 if (Instant.now().isAfter(expiry)) {
212 System.out.println("retrying after: " + fail);
218 protected ImmutableList<JobAuditStatus> vidAuditStatusesCompletedWithErrors(String jobId) {
219 return ImmutableList.of(
220 vidAuditStatus(jobId, "PENDING", false),
221 vidAuditStatus(jobId, "IN_PROGRESS", false),
222 vidAuditStatus(jobId, "COMPLETED_WITH_ERRORS", true)
226 protected ImmutableList<JobAuditStatus> vidAuditStatusesFailed(String jobId) {
227 return ImmutableList.of(
228 vidAuditStatus(jobId, "PENDING", false),
229 vidAuditStatus(jobId, "IN_PROGRESS", false),
230 vidAuditStatus(jobId, "FAILED", true)
234 protected JobAuditStatus vidAuditStatus(String jobId, String jobStatus, boolean isFinal) {
235 return new JobAuditStatus(UUID.fromString(jobId), jobStatus, JobAuditStatus.SourceStatus.VID, null, null, isFinal);
238 public static class JobIdAndStatusMatcher extends BaseMatcher<ServiceInfo> {
239 protected String expectedJobId;
241 public JobIdAndStatusMatcher(String expectedJobId) {
242 this.expectedJobId = expectedJobId;
246 public boolean matches(Object item) {
247 if (!(item instanceof ServiceInfo)) {
250 ServiceInfo serviceInfo = (ServiceInfo) item;
251 return expectedJobId.equals(serviceInfo.jobId);
255 public void describeTo(Description description) {
256 description.appendText("failed to find job with uuid ")
257 .appendValue(expectedJobId);
263 protected Map<Keys,String> generateNames() {
264 return Stream.of(Keys.values()).collect(
265 Collectors.toMap(x->x, x -> UUID.randomUUID().toString().replace("-","")));
268 protected ImmutableList<BasePreset> addPresetsForCreateBulkOfCreateInstances(int bulkSize, Map<Keys, String> names){
269 ImmutableList<BasePreset> msoBulkPresets = generateMsoCreateBulkPresets(bulkSize, names);
270 ImmutableList<BasePreset> presets = new ImmutableList.Builder<BasePreset>()
271 .add(new PresetGetSessionSlotCheckIntervalGet())
272 .add(new PresetAAIGetSubscribersGet())
273 .add(PresetAAIGetCloudOwnersByCloudRegionId.PRESET_MTN3_TO_ATT_SABABA)
274 .addAll(msoBulkPresets)
275 .add(new PresetMSOOrchestrationRequestGet())
281 protected ImmutableList<BasePreset> generateMsoCreateBulkPresets(int bulkSize, Map<Keys, String> names) {
282 return IntStream.rangeClosed(0, bulkSize-1).
283 mapToObj(i-> new PresetMSOCreateServiceInstanceGen2WithNames(names, i))
284 .collect(ImmutableList.toImmutableList());
287 protected ResponseEntity<List<JobAuditStatus>> auditStatusCall(String url) {
288 return restTemplate.exchange(
290 org.springframework.http.HttpMethod.GET,
292 new ParameterizedTypeReference<List<JobAuditStatus>>() {});
296 public static Object[][] auditSources() {
297 return new Object[][]{{JobAuditStatus.SourceStatus.VID},{JobAuditStatus.SourceStatus.MSO}};
302 protected List<String> createBulkAndWaitForBeCompleted(int bulkSize){
303 Map<Keys, String> names = generateNames();
304 ImmutableList<BasePreset> presets = addPresetsForCreateBulkOfCreateInstances(bulkSize, names);
305 final List<String> jobIds = createBulkOfMacroInstances(presets, false, bulkSize, names);
306 Assert.assertEquals(jobIds.size(),bulkSize);
308 waitForJobsToSuccessfullyCompleted(bulkSize, jobIds);
312 public void waitForJobsToSuccessfullyCompleted(int bulkSize, List<String> jobIds) {
313 assertTrue(String.format("Not all services with ids: %s are in state completed after 30 sec",
314 jobIds.stream().collect(joining(","))),
316 Wait.waitFor(y-> serviceListCall().getBody().stream()
317 .filter(si -> jobIds.contains(si.jobId))
318 .filter(si -> si.jobStatus== JobStatus.COMPLETED)
319 .count() == bulkSize,
323 protected List<JobAuditStatus> getJobMsoAuditStatusForAlaCarte(String jobUUID, String requestId, String serviceInstanceId){
324 String url = getMsoJobAuditUrl().replace("{JOB_ID}",jobUUID);
326 if(!StringUtils.isEmpty(requestId)) {
327 url = url + "?requestId=" + requestId;
328 if(!StringUtils.isEmpty(serviceInstanceId)) {
329 url = url + "&serviceInstanceId=" + serviceInstanceId;
332 return callAuditStatus(url);
335 protected List<JobAuditStatus> getAuditStatuses(String jobUUID, String source){
336 String url = getJobAuditUrl().replace("{JOB_ID}",jobUUID).replace("{SOURCE}", source);
337 return callAuditStatus(url);
340 protected List<JobAuditStatus> getAuditStatusesForInstance(String type, String instanceId){
341 String url = getInstanceAuditInfoUrl().replace("{TYPE}",type).replace("{INSTANCE_ID}", instanceId);
342 return callAuditStatus(url);
345 private List<JobAuditStatus> callAuditStatus(String url) {
346 ResponseEntity<List<JobAuditStatus>> statusesResponse = auditStatusCall(url);
347 assertThat(statusesResponse.getStatusCode(), CoreMatchers.equalTo(HttpStatus.OK));
348 return statusesResponse.getBody();
351 protected Map<String, JobStatus> addBulkAllPendingButOneInProgress(){
352 return addBulkAllPendingButOneInProgress(3);
355 protected Map<String, JobStatus> addBulkAllPendingButOneInProgress(int bulkSize){
356 Map<Keys, String> names = generateNames();
357 ImmutableList<BasePreset> msoBulkPresets = generateMsoCreateBulkPresets(bulkSize, names);
358 ImmutableList<BasePreset> presets = new ImmutableList.Builder<BasePreset>()
359 .add(new PresetGetSessionSlotCheckIntervalGet())
360 .add(new PresetAAIGetSubscribersGet())
361 .add(PresetAAIGetCloudOwnersByCloudRegionId.PRESET_MTN3_TO_ATT_SABABA)
362 .addAll(msoBulkPresets)
363 .add(new PresetMSOOrchestrationRequestGet("IN_PROGRESS"))
365 final List<String> jobIds = createBulkOfMacroInstances(presets, false, bulkSize, names);
367 // wait for single IN_PROGRESS, so statuses will stop from changing
368 Wait.waitFor(foo -> serviceListCall().getBody().stream()
369 .filter(si -> jobIds.contains(si.jobId))
370 .anyMatch(si -> si.jobStatus.equals(JobStatus.IN_PROGRESS)),
373 final Map<String, JobStatus> statusMapBefore = serviceListCall().getBody().stream()
374 .filter(si -> jobIds.contains(si.jobId))
375 .collect(toMap(si -> si.jobId, si -> si.jobStatus));
377 assertThat(jobIds, hasSize(bulkSize));
380 return statusMapBefore;
383 protected String deleteOneJobHavingTheStatus(Map<String, JobStatus> jobIdToStatus, JobStatus jobStatus) {
384 final String jobToDelete = jobIdToStatus.entrySet().stream()
385 .filter(entry -> entry.getValue().equals(jobStatus))
386 .map(Map.Entry::getKey)
387 .findFirst().orElseThrow(() -> new AssertionError("no job in " + jobStatus + " state: " + jobIdToStatus));
390 restTemplate.delete(getDeleteServiceUrl(jobToDelete));
396 protected MsoResponseWrapper2 hideService(String jobId) {
397 MsoResponseWrapper2 responseWrapper2 = callMsoForResponseWrapper(org.springframework.http.HttpMethod.POST, getHideServiceUri(jobId), "");
398 return responseWrapper2;
401 protected List<String> createBulkOfInstancesAndAssert(ImmutableList<BasePreset> presets, boolean isPause, int bulkSize, JobStatus finalState, Map<Keys, String> names){
402 List<String> jobIds = createBulkOfMacroInstances(presets, isPause, bulkSize, names);
403 Assert.assertEquals(jobIds.size(), bulkSize);
404 for(String jobId: jobIds) {
405 assertExpectedStatusAndServiceInfo(isPause, finalState, names, jobId);
411 protected void assertExpectedStatusAndServiceInfo(boolean isPause, JobStatus finalState, Map<Keys, String> names, String jobId) {
412 assertExpectedStatusAndServiceInfo(finalState, jobId, new ServiceInfo("us16807000", JobStatus.IN_PROGRESS, isPause, "someID",
413 "someName", "myProject", "NFT1", "NFTJSSSS-NFT1", "greatTenant", "greatTenant", "hvf3", null,
414 "mySubType", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", null, names.get(Keys.SERVICE_NAME),
415 "5c9e863f-2716-467b-8799-4a67f378dcaa", "AIM_TRANSPORT_00004", "1.0", jobId, null, ServiceAction.INSTANTIATE, false));
418 protected void assertExpectedStatusAndServiceInfo(JobStatus finalState, String jobId, ServiceInfo expectedServiceInfo) {
419 assertExpectedStatusAndServiceInfo(finalState, jobId, PATIENCE_LEVEL.FAIL_FAST, expectedServiceInfo);
422 enum PATIENCE_LEVEL { FAIL_FAST, FAIL_SLOW, FAIL_VERY_SLOW }
424 protected void assertExpectedStatusAndServiceInfo(JobStatus finalState, String jobId, PATIENCE_LEVEL patienceLevel, ServiceInfo expectedServiceInfo) {
425 JobInfoChecker<Integer> jobInfoChecker = new JobInfoChecker<>(
426 restTemplate, ImmutableSet.of(JobStatus.PENDING, JobStatus.IN_PROGRESS, finalState), jobId, expectedServiceInfo);
427 boolean result = jobInfoChecker.test(null);
428 assertTrue("service info of jobId: " + jobId + " was in status: " + jobInfoChecker.lastStatus, result);
430 jobInfoChecker.setExpectedJobStatus(ImmutableSet.of(finalState));
431 if (ImmutableList.of(JobStatus.COMPLETED, JobStatus.PAUSE).contains(finalState) && expectedServiceInfo.serviceInstanceId==null) {
432 expectedServiceInfo.serviceInstanceId = BaseMSOPreset.DEFAULT_INSTANCE_ID;
434 result = Wait.waitFor(jobInfoChecker, null, 30, waitIntervalBy(patienceLevel));
435 assertTrue("service info of jobId: " + jobId + " was in status: " + jobInfoChecker.lastStatus, result);
438 private int waitIntervalBy(PATIENCE_LEVEL patienceLevel) {
439 switch (patienceLevel) {
449 protected List<String> createBulkOfMacroInstances(ImmutableList<BasePreset> presets, boolean isPause, int bulkSize, Map<Keys, String> names) {
450 SimulatorApi.registerExpectationFromPresets(presets, SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET);
451 return createBulkOfInstances(isPause, bulkSize, names, CREATE_BULK_OF_MACRO_REQUEST);
454 public List<String> createBulkOfInstances(boolean isPause, int bulkSize, Map<Keys, String> names, String requestDetailsFileName){
456 String requestBody = TestUtils.convertRequest(objectMapper, requestDetailsFileName);
457 requestBody = requestBody.replace("\"IS_PAUSE_VALUE\"", String.valueOf(isPause)).replace("\"BULK_SIZE\"", String.valueOf(bulkSize));
458 for (Map.Entry<Keys, String> e : names.entrySet()) {
459 requestBody = requestBody.replace(e.getKey().name(), e.getValue());
461 MsoResponseWrapper2 responseWrapper2 = callMsoForResponseWrapper(org.springframework.http.HttpMethod.POST, getCreateBulkUri(), requestBody);
462 assertNotNull(responseWrapper2);
463 return (List<String>)responseWrapper2.getEntity();
466 protected List<String> retryJob(String jobId) {
467 ResponseEntity<String> retryBulkPayload = getRetryBulk(jobId);
468 return retryJobWithChangedData(jobId, retryBulkPayload.getBody());
471 protected List<String> retryJobWithChangedData(String jobId, String requestBody) {
472 String retryUri = getRetryJobWithChangedDataUrl();
473 retryUri = retryUri.replace("{JOB_ID}", jobId);
474 MsoResponseWrapper2 responseWrapper2 = callMsoForResponseWrapper(HttpMethod.POST, retryUri, requestBody);
475 assertNotNull(responseWrapper2);
476 return (List<String>)responseWrapper2.getEntity();
479 protected ResponseEntity<String> getRetryBulk(String jobId) {
480 String retryUri = getTopologyForRetryUrl();
481 retryUri = retryUri.replace("{JOB_ID}", jobId);
482 return restTemplateErrorAgnostic.getForEntity(retryUri, String.class);
485 protected Object getResourceAuditInfo(String trackById) {
486 return restTemplate.getForObject(buildUri("/asyncInstantiation/auditStatusForRetry/{trackById}"), Object.class, trackById);
489 public class JobInfoChecker<Integer> implements Predicate<Integer> {
491 protected final RestTemplate restTemplate;
492 protected Set<JobStatus> expectedJobStatus;
493 protected ServiceInfo expectedServiceInfo;
494 protected final String jobId;
495 protected JobStatus lastStatus;
497 public JobInfoChecker(RestTemplate restTemplate, Set<JobStatus> expectedJobStatus, String jobId, ServiceInfo expectedServiceInfo) {
498 this.restTemplate = restTemplate;
499 this.expectedJobStatus = expectedJobStatus;
501 this.expectedServiceInfo = expectedServiceInfo;
504 public void setExpectedJobStatus(Set<JobStatus> expectedJobStatus) {
505 this.expectedJobStatus = expectedJobStatus;
509 public boolean test(Integer integer) {
510 ResponseEntity<List<ServiceInfo>> serviceListResponse = serviceListCall();
511 assertThat(serviceListResponse.getStatusCode(), CoreMatchers.equalTo(HttpStatus.OK));
512 assertThat(serviceListResponse.getBody(), hasItem(new JobIdAndStatusMatcher(jobId)));
513 ServiceInfo serviceInfoFromDB = serviceListResponse.getBody().stream()
514 .filter(serviceInfo -> serviceInfo.jobId.equals(jobId))
515 .findFirst().orElse(null);
516 Assert.assertNotNull(serviceInfoFromDB);
517 Assert.assertEquals(serviceInfoDataReflected(serviceInfoFromDB), serviceInfoDataReflected(expectedServiceInfo));
518 assertTrue("actual service instance doesn't contain template service name:" + expectedServiceInfo.serviceInstanceName,
519 serviceInfoFromDB.serviceInstanceName.contains(expectedServiceInfo.serviceInstanceName));
521 if (expectedServiceInfo.serviceInstanceId != null && ImmutableList.of(JobStatus.COMPLETED, JobStatus.PAUSE, JobStatus.COMPLETED_WITH_ERRORS).contains(serviceInfoFromDB.jobStatus)) {
522 MatcherAssert.assertThat("service instance id is wrong", serviceInfoFromDB.serviceInstanceId, CoreMatchers.is(expectedServiceInfo.serviceInstanceId));
524 if (expectedJobStatus.size()==1) {
525 assertEquals("job status is wrong", getExpectedRetryEnabled((JobStatus)(expectedJobStatus.toArray()[0])), serviceInfoFromDB.isRetryEnabled);
527 lastStatus = serviceInfoFromDB.jobStatus;
528 return expectedJobStatus.contains(serviceInfoFromDB.jobStatus);
532 protected ResponseEntity<List<ServiceInfo>> serviceListCall() {
533 return restTemplate.exchange(
535 org.springframework.http.HttpMethod.GET,
537 new ParameterizedTypeReference<List<ServiceInfo>>() {});
540 //serialize fields except of fields we cannot know ahead of time
541 protected static String serviceInfoDataReflected(ServiceInfo service1) {
542 return new ReflectionToStringBuilder(service1, ToStringStyle.SHORT_PREFIX_STYLE)
543 .setExcludeFieldNames("jobStatus", "templateId", "statusModifiedDate", "createdBulkDate", "serviceInstanceId", "serviceInstanceName", "isRetryEnabled")
547 protected Map<Keys, String> addBulkPendingWithCustomList(List<BasePreset> customPresets){
548 Map<Keys, String> names = generateNames();
549 final int bulkSize = 2 + customPresets.size();
551 List<BasePreset> msoBulkPresets = generateMsoCreateBulkPresets(bulkSize, names);
552 ImmutableList<BasePreset> presets = new ImmutableList.Builder<BasePreset>()
553 .add(new PresetGetSessionSlotCheckIntervalGet())
554 .add(new PresetAAIGetSubscribersGet())
555 .add(PresetAAIGetCloudOwnersByCloudRegionId.PRESET_MTN3_TO_ATT_SABABA, PresetAAIGetCloudOwnersByCloudRegionId.PRESET_MDT1_TO_ATT_NC)
556 .addAll(msoBulkPresets)
557 .addAll(customPresets)
560 List<String> jobIds = createBulkOfMacroInstances(presets, false, bulkSize, names);
561 Assert.assertEquals(jobIds.size(),bulkSize);
566 protected void verifyAuditStatuses(String jobId, List<String> statuses, JobAuditStatus.SourceStatus source) {
567 int statusesSize = statuses.size();
568 AtomicReference<List<JobAuditStatus>> actualAudits = new AtomicReference<>();
569 if (source.equals(JobAuditStatus.SourceStatus.VID)) {
570 actualAudits.set(getAuditStatuses(jobId, JobAuditStatus.SourceStatus.VID.name()));
571 org.junit.Assert.assertEquals("Received number of VID statuses is not as expected", statusesSize, actualAudits.get().size());
573 boolean isStatusedSizeAsExpected = Wait.waitFor(x-> {
574 actualAudits.set(getAuditStatuses(jobId, JobAuditStatus.SourceStatus.MSO.name()));
575 return actualAudits.get().size() == statusesSize;
577 org.junit.Assert.assertTrue("Received number of MSO statuses is not as expected. Expected: " + statusesSize + ". Received: " + actualAudits.get().size(), isStatusedSizeAsExpected);
579 IntStream.range(0, statusesSize).forEach(i-> org.junit.Assert.assertEquals(source + " status #" + i + " is not as expected", statuses.get(i), actualAudits.get().get(i).getJobStatus()));
582 protected void verifyInstanceAuditStatuses(List<JobAuditStatus> expectedStatuses, List<JobAuditStatus> actualStatuses) {
583 final int expectedSize = expectedStatuses.size();
584 assertTrue("Expected statuses size is "+ expectedSize +", actual size is "+actualStatuses.size(), new Integer(expectedSize).equals(actualStatuses.size()));
585 IntStream.range(0, expectedSize).forEach(i-> {
587 final JobAuditStatus expectedStatus = expectedStatuses.get(i);
588 final JobAuditStatus actualStatus = actualStatuses.get(i);
589 org.junit.Assert.assertEquals("MSO status #" + i + " is not as expected", expectedStatus.getJobStatus(), actualStatus.getJobStatus());
590 org.junit.Assert.assertEquals("MSO requestId #" + i + " is not as expected", expectedStatus.getRequestId(), actualStatus.getRequestId());
591 org.junit.Assert.assertEquals("MSO additionalInfo #" + i + " is not as expected", expectedStatus.getAdditionalInfo(), actualStatus.getAdditionalInfo());
592 org.junit.Assert.assertEquals("MSO jobID #" + i + " is not as expected", expectedStatus.getJobId(), actualStatus.getJobId());
593 org.junit.Assert.assertEquals("MSO instanceName #" + i + " is not as expected", expectedStatus.getInstanceName(), actualStatus.getInstanceName());
594 org.junit.Assert.assertEquals("MSO instanceType #" + i + " is not as expected", expectedStatus.getInstanceType(), actualStatus.getInstanceType());