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 getJobAuditUrl() {
109 return uri.toASCIIString() + "/asyncInstantiation/auditStatus/{JOB_ID}?source={SOURCE}";
112 protected String getMsoJobAuditUrl() {
113 return uri.toASCIIString() + "/asyncInstantiation/auditStatus/{JOB_ID}/mso";
116 protected String getDeleteServiceUrl(String uuid) {
117 return uri.toASCIIString() + "/asyncInstantiation/job/" + uuid;
120 protected String getInstanceAuditInfoUrl() {
121 return uri.toASCIIString() + "/asyncInstantiation/auditStatus/{TYPE}/{INSTANCE_ID}/mso";
124 protected String getRetryJobUrl() {
125 return uri.toASCIIString() + "/asyncInstantiation/retry/{JOB_ID}";
127 protected String getTopologyForRetryUrl() {
128 return uri.toASCIIString() + "/asyncInstantiation/bulkForRetry/{JOB_ID}";
132 protected String getRetryJobWithChangedDataUrl() {
133 return uri.toASCIIString() + "/asyncInstantiation/retryJobWithChangedData/{JOB_ID}";
136 protected boolean getExpectedRetryEnabled(JobStatus jobStatus) {
137 return Features.FLAG_1902_RETRY_JOB.isActive() && (jobStatus==JobStatus.FAILED || jobStatus==JobStatus.COMPLETED_WITH_ERRORS);
140 public List<BasePreset> getPresets(List<PresetMSOBaseDelete> presetOnDeleteList, List<PresetMSOBaseCreateInstancePost> presetOnCreateList, List<PresetMSOOrchestrationRequestGet> presetInProgressList) {
142 final ImmutableList.Builder<BasePreset> basePresetBuilder = new ImmutableList.Builder<>();
144 .add(new PresetGetSessionSlotCheckIntervalGet())
145 .add(new PresetAAIGetSubscribersGet())
146 .addAll(presetOnDeleteList)
147 .addAll(presetOnCreateList)
148 .addAll(presetInProgressList);
149 return basePresetBuilder.build();
152 public List<BasePreset> getDeletePresets(List<PresetMSOBaseDelete> presetOnDeleteList, List<PresetMSOOrchestrationRequestGet> presetInProgressList) {
153 return getPresets(presetOnDeleteList, emptyList(), presetInProgressList);
156 public List<BasePreset> getPresets(List<PresetMSOBaseCreateInstancePost> presetOnCreateList, List<PresetMSOOrchestrationRequestGet> presetInProgressList) {
157 return getPresets(emptyList(), presetOnCreateList, presetInProgressList);
160 public void assertServiceInfoSpecific1(String jobId, JobStatus jobStatus, String serviceInstanceName, String userName) {
161 assertServiceInfoSpecific1(jobId, jobStatus, serviceInstanceName, userName, null, ServiceAction.INSTANTIATE);
164 public void assertServiceInfoSpecific1(String jobId, JobStatus jobStatus, String serviceInstanceName, String userName, String instanceId, ServiceAction action) {
165 assertExpectedStatusAndServiceInfo(jobStatus, jobId, new ServiceInfo(
166 userName, jobStatus, false,
167 "038d99af-0427-42c2-9d15-971b99b9b489", "Lucine Sarika", "zasaki",
168 "de738e5f-3704-4a14-b98f-3bf86ac0c0a0", "voloyakane-senamo",
169 "c85f0e80-0636-44a4-8cb2-4ec00d056e79", "Hedvika Wendelin",
170 "a93f8383-707e-43fa-8191-a6e69a1aab17", null,
171 "TYLER SILVIA", "SILVIA ROBBINS",
172 instanceId, serviceInstanceName,
173 "e3c34d88-a216-4f1d-a782-9af9f9588705", "gayawabawe", "5.1",
174 jobId, null, action, false)
178 public void assertServiceInfoSpecific1(String jobId, JobStatus jobStatus, String serviceInstanceName) {
179 assertServiceInfoSpecific1(jobId, jobStatus, serviceInstanceName, "us16807000");
182 protected void assertAuditStatuses(String jobId, List<JobAuditStatus> expectedVidStatuses, List<JobAuditStatus> expectedMsoStatuses) {
183 assertAuditStatuses(jobId, expectedVidStatuses, expectedMsoStatuses, 15);
186 protected void assertAuditStatuses(String jobId, List<JobAuditStatus> expectedVidStatuses, List<JobAuditStatus> expectedMsoStatuses, long timeoutInSeconds) {
187 assertAndRetryIfNeeded(() -> {
188 final List<JobAuditStatus> auditVidStatuses = getAuditStatuses(jobId, JobAuditStatus.SourceStatus.VID.name());
189 assertThat(auditVidStatuses, hasItemsFromCollection(expectedVidStatuses));
190 if (expectedMsoStatuses!=null) {
191 final List<JobAuditStatus> auditMsoStatuses = getAuditStatuses(jobId, JobAuditStatus.SourceStatus.MSO.name());
192 assertThat(auditMsoStatuses, containsInAnyOrder(expectedMsoStatuses.toArray()));
194 }, timeoutInSeconds);
197 protected void assertAndRetryIfNeeded(Runnable asserter, long timeoutInSeconds) {
198 final Instant expiry = Instant.now().plusSeconds(timeoutInSeconds);
202 break; // we're cool, assertion passed
203 } catch (AssertionError fail) {
204 Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
205 if (Instant.now().isAfter(expiry)) {
208 System.out.println("retrying after: " + fail);
214 protected ImmutableList<JobAuditStatus> vidAuditStatusesCompletedWithErrors(String jobId) {
215 return ImmutableList.of(
216 vidAuditStatus(jobId, "PENDING", false),
217 vidAuditStatus(jobId, "IN_PROGRESS", false),
218 vidAuditStatus(jobId, "COMPLETED_WITH_ERRORS", true)
222 protected ImmutableList<JobAuditStatus> vidAuditStatusesFailed(String jobId) {
223 return ImmutableList.of(
224 vidAuditStatus(jobId, "PENDING", false),
225 vidAuditStatus(jobId, "IN_PROGRESS", false),
226 vidAuditStatus(jobId, "FAILED", true)
230 protected JobAuditStatus vidAuditStatus(String jobId, String jobStatus, boolean isFinal) {
231 return new JobAuditStatus(UUID.fromString(jobId), jobStatus, JobAuditStatus.SourceStatus.VID, null, null, isFinal);
234 public static class JobIdAndStatusMatcher extends BaseMatcher<ServiceInfo> {
235 protected String expectedJobId;
237 public JobIdAndStatusMatcher(String expectedJobId) {
238 this.expectedJobId = expectedJobId;
242 public boolean matches(Object item) {
243 if (!(item instanceof ServiceInfo)) {
246 ServiceInfo serviceInfo = (ServiceInfo) item;
247 return expectedJobId.equals(serviceInfo.jobId);
251 public void describeTo(Description description) {
252 description.appendText("failed to find job with uuid ")
253 .appendValue(expectedJobId);
259 protected Map<Keys,String> generateNames() {
260 return Stream.of(Keys.values()).collect(
261 Collectors.toMap(x->x, x -> UUID.randomUUID().toString().replace("-","")));
264 protected ImmutableList<BasePreset> addPresetsForCreateBulkOfCreateInstances(int bulkSize, Map<Keys, String> names){
265 ImmutableList<BasePreset> msoBulkPresets = generateMsoCreateBulkPresets(bulkSize, names);
266 ImmutableList<BasePreset> presets = new ImmutableList.Builder<BasePreset>()
267 .add(new PresetGetSessionSlotCheckIntervalGet())
268 .add(new PresetAAIGetSubscribersGet())
269 .add(PresetAAIGetCloudOwnersByCloudRegionId.PRESET_MTN3_TO_ATT_SABABA)
270 .addAll(msoBulkPresets)
271 .add(new PresetMSOOrchestrationRequestGet())
277 protected ImmutableList<BasePreset> generateMsoCreateBulkPresets(int bulkSize, Map<Keys, String> names) {
278 return IntStream.rangeClosed(0, bulkSize-1).
279 mapToObj(i-> new PresetMSOCreateServiceInstanceGen2WithNames(names, i))
280 .collect(ImmutableList.toImmutableList());
283 protected ResponseEntity<List<JobAuditStatus>> auditStatusCall(String url) {
284 return restTemplate.exchange(
286 org.springframework.http.HttpMethod.GET,
288 new ParameterizedTypeReference<List<JobAuditStatus>>() {});
292 public static Object[][] auditSources() {
293 return new Object[][]{{JobAuditStatus.SourceStatus.VID},{JobAuditStatus.SourceStatus.MSO}};
298 protected List<String> createBulkAndWaitForBeCompleted(int bulkSize){
299 Map<Keys, String> names = generateNames();
300 ImmutableList<BasePreset> presets = addPresetsForCreateBulkOfCreateInstances(bulkSize, names);
301 final List<String> jobIds = createBulkOfMacroInstances(presets, false, bulkSize, names);
302 Assert.assertEquals(jobIds.size(),bulkSize);
304 assertTrue(String.format("Not all services with ids: %s are in state completed after 30 sec",
305 jobIds.stream().collect(joining(","))),
307 Wait.waitFor(y-> serviceListCall().getBody().stream()
308 .filter(si -> jobIds.contains(si.jobId))
309 .filter(si -> si.jobStatus==JobStatus.COMPLETED)
310 .count() == bulkSize,
315 protected List<JobAuditStatus> getJobMsoAuditStatusForAlaCarte(String jobUUID, String requestId, String serviceInstanceId){
316 String url = getMsoJobAuditUrl().replace("{JOB_ID}",jobUUID);
318 if(!StringUtils.isEmpty(requestId)) {
319 url = url + "?requestId=" + requestId;
320 if(!StringUtils.isEmpty(serviceInstanceId)) {
321 url = url + "&serviceInstanceId=" + serviceInstanceId;
324 return callAuditStatus(url);
327 protected List<JobAuditStatus> getAuditStatuses(String jobUUID, String source){
328 String url = getJobAuditUrl().replace("{JOB_ID}",jobUUID).replace("{SOURCE}", source);
329 return callAuditStatus(url);
332 protected List<JobAuditStatus> getAuditStatusesForInstance(String type, String instanceId){
333 String url = getInstanceAuditInfoUrl().replace("{TYPE}",type).replace("{INSTANCE_ID}", instanceId);
334 return callAuditStatus(url);
337 private List<JobAuditStatus> callAuditStatus(String url) {
338 ResponseEntity<List<JobAuditStatus>> statusesResponse = auditStatusCall(url);
339 assertThat(statusesResponse.getStatusCode(), CoreMatchers.equalTo(HttpStatus.OK));
340 return statusesResponse.getBody();
343 protected Map<String, JobStatus> addBulkAllPendingButOneInProgress(){
344 return addBulkAllPendingButOneInProgress(3);
347 protected Map<String, JobStatus> addBulkAllPendingButOneInProgress(int bulkSize){
348 Map<Keys, String> names = generateNames();
349 ImmutableList<BasePreset> msoBulkPresets = generateMsoCreateBulkPresets(bulkSize, names);
350 ImmutableList<BasePreset> presets = new ImmutableList.Builder<BasePreset>()
351 .add(new PresetGetSessionSlotCheckIntervalGet())
352 .add(new PresetAAIGetSubscribersGet())
353 .add(PresetAAIGetCloudOwnersByCloudRegionId.PRESET_MTN3_TO_ATT_SABABA)
354 .addAll(msoBulkPresets)
355 .add(new PresetMSOOrchestrationRequestGet("IN_PROGRESS"))
357 final List<String> jobIds = createBulkOfMacroInstances(presets, false, bulkSize, names);
359 // wait for single IN_PROGRESS, so statuses will stop from changing
360 Wait.waitFor(foo -> serviceListCall().getBody().stream()
361 .filter(si -> jobIds.contains(si.jobId))
362 .anyMatch(si -> si.jobStatus.equals(JobStatus.IN_PROGRESS)),
365 final Map<String, JobStatus> statusMapBefore = serviceListCall().getBody().stream()
366 .filter(si -> jobIds.contains(si.jobId))
367 .collect(toMap(si -> si.jobId, si -> si.jobStatus));
369 assertThat(jobIds, hasSize(bulkSize));
372 return statusMapBefore;
375 protected String deleteOneJobHavingTheStatus(Map<String, JobStatus> jobIdToStatus, JobStatus jobStatus) {
376 final String jobToDelete = jobIdToStatus.entrySet().stream()
377 .filter(entry -> entry.getValue().equals(jobStatus))
378 .map(Map.Entry::getKey)
379 .findFirst().orElseThrow(() -> new AssertionError("no job in " + jobStatus + " state: " + jobIdToStatus));
382 restTemplate.delete(getDeleteServiceUrl(jobToDelete));
388 protected MsoResponseWrapper2 hideService(String jobId) {
389 MsoResponseWrapper2 responseWrapper2 = callMsoForResponseWrapper(org.springframework.http.HttpMethod.POST, getHideServiceUri(jobId), "");
390 return responseWrapper2;
393 protected List<String> createBulkOfInstancesAndAssert(ImmutableList<BasePreset> presets, boolean isPause, int bulkSize, JobStatus finalState, Map<Keys, String> names){
394 List<String> jobIds = createBulkOfMacroInstances(presets, isPause, bulkSize, names);
395 Assert.assertEquals(jobIds.size(), bulkSize);
396 for(String jobId: jobIds) {
397 assertExpectedStatusAndServiceInfo(isPause, finalState, names, jobId);
403 protected void assertExpectedStatusAndServiceInfo(boolean isPause, JobStatus finalState, Map<Keys, String> names, String jobId) {
404 assertExpectedStatusAndServiceInfo(finalState, jobId, new ServiceInfo("us16807000", JobStatus.IN_PROGRESS, isPause, "someID",
405 "someName", "myProject", "NFT1", "NFTJSSSS-NFT1", "greatTenant", "greatTenant", "hvf3", null,
406 "mySubType", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", null, names.get(Keys.SERVICE_NAME),
407 "5c9e863f-2716-467b-8799-4a67f378dcaa", "AIM_TRANSPORT_00004", "1.0", jobId, null, ServiceAction.INSTANTIATE, false));
410 protected void assertExpectedStatusAndServiceInfo(JobStatus finalState, String jobId, ServiceInfo expectedServiceInfo) {
411 assertExpectedStatusAndServiceInfo(finalState, jobId, PATIENCE_LEVEL.FAIL_FAST, expectedServiceInfo);
414 enum PATIENCE_LEVEL { FAIL_FAST, FAIL_SLOW, FAIL_VERY_SLOW }
416 protected void assertExpectedStatusAndServiceInfo(JobStatus finalState, String jobId, PATIENCE_LEVEL patienceLevel, ServiceInfo expectedServiceInfo) {
417 JobInfoChecker<Integer> jobInfoChecker = new JobInfoChecker<>(
418 restTemplate, ImmutableSet.of(JobStatus.PENDING, JobStatus.IN_PROGRESS, finalState), jobId, expectedServiceInfo);
419 boolean result = jobInfoChecker.test(null);
420 assertTrue("service info of jobId: " + jobId + " was in status: " + jobInfoChecker.lastStatus, result);
422 jobInfoChecker.setExpectedJobStatus(ImmutableSet.of(finalState));
423 if (ImmutableList.of(JobStatus.COMPLETED, JobStatus.PAUSE).contains(finalState) && expectedServiceInfo.serviceInstanceId==null) {
424 expectedServiceInfo.serviceInstanceId = BaseMSOPreset.DEFAULT_INSTANCE_ID;
426 result = Wait.waitFor(jobInfoChecker, null, 30, waitIntervalBy(patienceLevel));
427 assertTrue("service info of jobId: " + jobId + " was in status: " + jobInfoChecker.lastStatus, result);
430 private int waitIntervalBy(PATIENCE_LEVEL patienceLevel) {
431 switch (patienceLevel) {
441 protected List<String> createBulkOfMacroInstances(ImmutableList<BasePreset> presets, boolean isPause, int bulkSize, Map<Keys, String> names) {
442 SimulatorApi.registerExpectationFromPresets(presets, SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET);
443 return createBulkOfInstances(isPause, bulkSize, names, CREATE_BULK_OF_MACRO_REQUEST);
446 public List<String> createBulkOfInstances(boolean isPause, int bulkSize, Map<Keys, String> names, String requestDetailsFileName){
448 String requestBody = TestUtils.convertRequest(objectMapper, requestDetailsFileName);
449 requestBody = requestBody.replace("\"IS_PAUSE_VALUE\"", String.valueOf(isPause)).replace("\"BULK_SIZE\"", String.valueOf(bulkSize));
450 for (Map.Entry<Keys, String> e : names.entrySet()) {
451 requestBody = requestBody.replace(e.getKey().name(), e.getValue());
453 MsoResponseWrapper2 responseWrapper2 = callMsoForResponseWrapper(org.springframework.http.HttpMethod.POST, getCreateBulkUri(), requestBody);
454 assertNotNull(responseWrapper2);
455 return (List<String>)responseWrapper2.getEntity();
458 protected List<String> retryJob(String jobId) {
459 ResponseEntity<String> retryBulkPayload = getRetryBulk(jobId);
460 return retryJobWithChangedData(jobId, retryBulkPayload.getBody());
463 protected List<String> retryJobWithChangedData(String jobId, String requestBody) {
464 String retryUri = getRetryJobWithChangedDataUrl();
465 retryUri = retryUri.replace("{JOB_ID}", jobId);
466 MsoResponseWrapper2 responseWrapper2 = callMsoForResponseWrapper(HttpMethod.POST, retryUri, requestBody);
467 assertNotNull(responseWrapper2);
468 return (List<String>)responseWrapper2.getEntity();
471 protected ResponseEntity<String> getRetryBulk(String jobId) {
472 String retryUri = getTopologyForRetryUrl();
473 retryUri = retryUri.replace("{JOB_ID}", jobId);
474 return restTemplateErrorAgnostic.getForEntity(retryUri, String.class);
477 protected Object getResourceAuditInfo(String trackById) {
478 return restTemplate.getForObject(buildUri("/asyncInstantiation/auditStatusForRetry/{trackById}"), Object.class, trackById);
481 public class JobInfoChecker<Integer> implements Predicate<Integer> {
483 protected final RestTemplate restTemplate;
484 protected Set<JobStatus> expectedJobStatus;
485 protected ServiceInfo expectedServiceInfo;
486 protected final String jobId;
487 protected JobStatus lastStatus;
489 public JobInfoChecker(RestTemplate restTemplate, Set<JobStatus> expectedJobStatus, String jobId, ServiceInfo expectedServiceInfo) {
490 this.restTemplate = restTemplate;
491 this.expectedJobStatus = expectedJobStatus;
493 this.expectedServiceInfo = expectedServiceInfo;
496 public void setExpectedJobStatus(Set<JobStatus> expectedJobStatus) {
497 this.expectedJobStatus = expectedJobStatus;
501 public boolean test(Integer integer) {
502 ResponseEntity<List<ServiceInfo>> serviceListResponse = serviceListCall();
503 assertThat(serviceListResponse.getStatusCode(), CoreMatchers.equalTo(HttpStatus.OK));
504 assertThat(serviceListResponse.getBody(), hasItem(new JobIdAndStatusMatcher(jobId)));
505 ServiceInfo serviceInfoFromDB = serviceListResponse.getBody().stream()
506 .filter(serviceInfo -> serviceInfo.jobId.equals(jobId))
507 .findFirst().orElse(null);
508 Assert.assertNotNull(serviceInfoFromDB);
509 Assert.assertEquals(serviceInfoDataReflected(serviceInfoFromDB), serviceInfoDataReflected(expectedServiceInfo));
510 assertTrue("actual service instance doesn't contain template service name:" + expectedServiceInfo.serviceInstanceName,
511 serviceInfoFromDB.serviceInstanceName.contains(expectedServiceInfo.serviceInstanceName));
513 if (expectedServiceInfo.serviceInstanceId != null && ImmutableList.of(JobStatus.COMPLETED, JobStatus.PAUSE, JobStatus.COMPLETED_WITH_ERRORS).contains(serviceInfoFromDB.jobStatus)) {
514 MatcherAssert.assertThat("service instance id is wrong", serviceInfoFromDB.serviceInstanceId, CoreMatchers.is(expectedServiceInfo.serviceInstanceId));
516 if (expectedJobStatus.size()==1) {
517 assertEquals("job status is wrong", getExpectedRetryEnabled((JobStatus)(expectedJobStatus.toArray()[0])), serviceInfoFromDB.isRetryEnabled);
519 lastStatus = serviceInfoFromDB.jobStatus;
520 return expectedJobStatus.contains(serviceInfoFromDB.jobStatus);
524 protected ResponseEntity<List<ServiceInfo>> serviceListCall() {
525 return restTemplate.exchange(
527 org.springframework.http.HttpMethod.GET,
529 new ParameterizedTypeReference<List<ServiceInfo>>() {});
532 //serialize fields except of fields we cannot know ahead of time
533 protected static String serviceInfoDataReflected(ServiceInfo service1) {
534 return new ReflectionToStringBuilder(service1, ToStringStyle.SHORT_PREFIX_STYLE)
535 .setExcludeFieldNames("jobStatus", "templateId", "statusModifiedDate", "createdBulkDate", "serviceInstanceId", "serviceInstanceName", "isRetryEnabled")
539 protected void addBulkPendingWithCustomList(List<BasePreset> customPresets){
540 Map<Keys, String> names = generateNames();
541 final int bulkSize = 2 + customPresets.size();
543 List<BasePreset> msoBulkPresets = generateMsoCreateBulkPresets(bulkSize, names);
544 ImmutableList<BasePreset> presets = new ImmutableList.Builder<BasePreset>()
545 .add(new PresetGetSessionSlotCheckIntervalGet())
546 .add(new PresetAAIGetSubscribersGet())
547 .addAll(msoBulkPresets)
548 .addAll(customPresets)
551 List<String> jobIds = createBulkOfMacroInstances(presets, false, bulkSize, names);
552 Assert.assertEquals(jobIds.size(),bulkSize);
555 protected void verifyAuditStatuses(String jobId, List<String> statuses, JobAuditStatus.SourceStatus source) {
556 int statusesSize = statuses.size();
557 AtomicReference<List<JobAuditStatus>> actualAudits = new AtomicReference<>();
558 if (source.equals(JobAuditStatus.SourceStatus.VID)) {
559 actualAudits.set(getAuditStatuses(jobId, JobAuditStatus.SourceStatus.VID.name()));
560 org.junit.Assert.assertEquals("Received number of VID statuses is not as expected", statusesSize, actualAudits.get().size());
562 boolean isStatusedSizeAsExpected = Wait.waitFor(x-> {
563 actualAudits.set(getAuditStatuses(jobId, JobAuditStatus.SourceStatus.MSO.name()));
564 return actualAudits.get().size() == statusesSize;
566 org.junit.Assert.assertTrue("Received number of MSO statuses is not as expected. Expected: " + statusesSize + ". Received: " + actualAudits.get().size(), isStatusedSizeAsExpected);
568 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()));
571 protected void verifyInstanceAuditStatuses(List<JobAuditStatus> expectedStatuses, List<JobAuditStatus> actualStatuses) {
572 final int expectedSize = expectedStatuses.size();
573 assertTrue("Expected statuses size is "+ expectedSize +", actual size is "+actualStatuses.size(), new Integer(expectedSize).equals(actualStatuses.size()));
574 IntStream.range(0, expectedSize).forEach(i-> {
576 final JobAuditStatus expectedStatus = expectedStatuses.get(i);
577 final JobAuditStatus actualStatus = actualStatuses.get(i);
578 org.junit.Assert.assertEquals("MSO status #" + i + " is not as expected", expectedStatus.getJobStatus(), actualStatus.getJobStatus());
579 org.junit.Assert.assertEquals("MSO requestId #" + i + " is not as expected", expectedStatus.getRequestId(), actualStatus.getRequestId());
580 org.junit.Assert.assertEquals("MSO additionalInfo #" + i + " is not as expected", expectedStatus.getAdditionalInfo(), actualStatus.getAdditionalInfo());
581 org.junit.Assert.assertEquals("MSO jobID #" + i + " is not as expected", expectedStatus.getJobId(), actualStatus.getJobId());
582 org.junit.Assert.assertEquals("MSO instanceName #" + i + " is not as expected", expectedStatus.getInstanceName(), actualStatus.getInstanceName());
583 org.junit.Assert.assertEquals("MSO instanceType #" + i + " is not as expected", expectedStatus.getInstanceType(), actualStatus.getInstanceType());