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 java.util.List;
23 import java.util.UUID;
24 import java.util.concurrent.atomic.AtomicReference;
25 import java.util.function.Predicate;
26 import java.util.stream.Collectors;
27 import java.util.stream.IntStream;
28 import java.util.stream.Stream;
29 import org.apache.commons.lang3.StringUtils;
30 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
31 import org.apache.commons.lang3.builder.ToStringStyle;
32 import org.hamcrest.BaseMatcher;
33 import org.hamcrest.CoreMatchers;
34 import org.hamcrest.Description;
35 import org.hamcrest.MatcherAssert;
36 import org.onap.simulator.presetGenerator.presets.BasePresets.BaseMSOPreset;
37 import org.onap.simulator.presetGenerator.presets.BasePresets.BasePreset;
38 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetCloudOwnersByCloudRegionId;
39 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet;
40 import org.onap.simulator.presetGenerator.presets.ecompportal_att.PresetGetSessionSlotCheckIntervalGet;
41 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOBaseCreateInstancePost;
42 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOBaseDelete;
43 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOCreateServiceInstanceGen2WithNames;
44 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet;
45 import org.onap.vid.model.asyncInstantiation.JobAuditStatus;
46 import org.onap.vid.model.asyncInstantiation.ServiceInfo;
47 import org.onap.vid.model.mso.MsoResponseWrapper2;
48 import org.springframework.core.ParameterizedTypeReference;
49 import org.springframework.http.HttpMethod;
50 import org.springframework.http.HttpStatus;
51 import org.springframework.http.ResponseEntity;
52 import org.springframework.web.client.RestTemplate;
53 import org.testng.Assert;
54 import org.testng.annotations.AfterMethod;
55 import org.testng.annotations.BeforeClass;
56 import org.testng.annotations.DataProvider;
57 import vid.automation.test.infra.Features;
58 import vid.automation.test.infra.Wait;
59 import vid.automation.test.model.JobStatus;
60 import vid.automation.test.model.ServiceAction;
61 import vid.automation.test.services.AsyncJobsService;
62 import vid.automation.test.services.SimulatorApi;
64 public class AsyncInstantiationBase extends BaseMsoApiTest {
66 public static final String CREATE_BULK_OF_ALACARTE_REQUEST_WITH_VNF = "asyncInstantiation/vidRequestCreateALaCarteWithVnf.json";
67 protected static final String CREATE_BULK_OF_MACRO_REQUEST = "asyncInstantiation/vidRequestCreateBulkOfMacro.json";
69 protected static final String MSO_BASE_ERROR =
70 "Received error from SDN-C: java.lang.IllegalArgumentException: All keys must be specified for class org."+
71 "opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.vf.module.assignments.vf."+
72 "module.assignments.vms.VmKey. Missing key is getVmType. Supplied key is VmKey [].";
73 protected static final String MSO_ERROR = MSO_BASE_ERROR + StringUtils.repeat(" and a lot of sentences for long message", 60);
76 protected void muteAndDropNameCounter() {
77 AsyncJobsService asyncJobsService = new AsyncJobsService();
78 asyncJobsService.muteAllAsyncJobs();
79 asyncJobsService.dropAllFromNameCounter();
83 protected void muteAllAsyncJobs() {
84 AsyncJobsService asyncJobsService = new AsyncJobsService();
85 asyncJobsService.muteAllAsyncJobs();
89 public static Object[][] trueAndFalse() {
90 return new Object[][]{{TRUE},{FALSE}};
93 protected String getCreateBulkUri() {
94 return uri.toASCIIString() + "/asyncInstantiation/bulk";
97 protected String getHideServiceUri(String jobId) {
98 return uri.toASCIIString() + "/asyncInstantiation/hide/"+jobId;
101 protected String getServiceInfoUrl() {
102 return uri.toASCIIString() + "/asyncInstantiation";
105 protected String getTemplateInfoUrl(String serviceModelId) {
106 return uri.toASCIIString() + "/instantiationTemplates?serviceModelId=" + serviceModelId;
109 protected String getJobAuditUrl() {
110 return uri.toASCIIString() + "/asyncInstantiation/auditStatus/{JOB_ID}?source={SOURCE}";
113 protected String getMsoJobAuditUrl() {
114 return uri.toASCIIString() + "/asyncInstantiation/auditStatus/{JOB_ID}/mso";
117 protected String getDeleteServiceUrl(String uuid) {
118 return uri.toASCIIString() + "/asyncInstantiation/job/" + uuid;
121 protected String getInstanceAuditInfoUrl() {
122 return uri.toASCIIString() + "/asyncInstantiation/auditStatus/{TYPE}/{INSTANCE_ID}/mso";
125 protected String getRetryJobUrl() {
126 return uri.toASCIIString() + "/asyncInstantiation/retry/{JOB_ID}";
128 protected String getTopologyForRetryUrl() {
129 return uri.toASCIIString() + "/asyncInstantiation/bulkForRetry/{JOB_ID}";
133 protected String getRetryJobWithChangedDataUrl() {
134 return uri.toASCIIString() + "/asyncInstantiation/retryJobWithChangedData/{JOB_ID}";
137 protected boolean getExpectedRetryEnabled(JobStatus jobStatus) {
138 return Features.FLAG_1902_RETRY_JOB.isActive() && (jobStatus==JobStatus.FAILED || jobStatus==JobStatus.COMPLETED_WITH_ERRORS
139 || jobStatus==JobStatus.FAILED_AND_PAUSED);
142 public List<BasePreset> getPresets(List<PresetMSOBaseDelete> presetOnDeleteList, List<PresetMSOBaseCreateInstancePost> presetOnCreateList, List<PresetMSOOrchestrationRequestGet> presetInProgressList) {
144 final ImmutableList.Builder<BasePreset> basePresetBuilder = new ImmutableList.Builder<>();
146 .add(new PresetGetSessionSlotCheckIntervalGet())
147 .add(new PresetAAIGetSubscribersGet())
148 .addAll(presetOnDeleteList)
149 .addAll(presetOnCreateList)
150 .addAll(presetInProgressList);
151 return basePresetBuilder.build();
154 public List<BasePreset> getDeletePresets(List<PresetMSOBaseDelete> presetOnDeleteList, List<PresetMSOOrchestrationRequestGet> presetInProgressList) {
155 return getPresets(presetOnDeleteList, emptyList(), presetInProgressList);
158 public List<BasePreset> getPresets(List<PresetMSOBaseCreateInstancePost> presetOnCreateList, List<PresetMSOOrchestrationRequestGet> presetInProgressList) {
159 return getPresets(emptyList(), presetOnCreateList, presetInProgressList);
162 public void assertServiceInfoSpecific1(String jobId, JobStatus jobStatus, String serviceInstanceName, String userName) {
163 assertServiceInfoSpecific1(jobId, jobStatus, serviceInstanceName, userName, null, ServiceAction.INSTANTIATE);
166 public void assertServiceInfoSpecific1(String jobId, JobStatus jobStatus, String serviceInstanceName, String userName, String instanceId, ServiceAction action) {
167 assertExpectedStatusAndServiceInfo(jobStatus, jobId, new ServiceInfo(
168 userName, jobStatus, false,
169 "038d99af-0427-42c2-9d15-971b99b9b489", "Lucine Sarika", "zasaki",
170 "de738e5f-3704-4a14-b98f-3bf86ac0c0a0", "voloyakane-senamo",
171 "c85f0e80-0636-44a4-8cb2-4ec00d056e79", "Hedvika Wendelin",
172 "a93f8383-707e-43fa-8191-a6e69a1aab17", null,
173 "TYLER SILVIA", "SILVIA ROBBINS",
174 instanceId, serviceInstanceName,
175 "e3c34d88-a216-4f1d-a782-9af9f9588705", "gayawabawe", "5.1",
176 jobId, null, action, false)
180 public void assertServiceInfoSpecific1(String jobId, JobStatus jobStatus, String serviceInstanceName) {
181 assertServiceInfoSpecific1(jobId, jobStatus, serviceInstanceName, "us16807000");
184 protected void assertAuditStatuses(String jobId, List<JobAuditStatus> expectedVidStatuses, List<JobAuditStatus> expectedMsoStatuses) {
185 assertAuditStatuses(jobId, expectedVidStatuses, expectedMsoStatuses, 15);
188 protected void assertAuditStatuses(String jobId, List<JobAuditStatus> expectedVidStatuses, List<JobAuditStatus> expectedMsoStatuses, long timeoutInSeconds) {
189 assertAndRetryIfNeeded(() -> {
190 final List<JobAuditStatus> auditVidStatuses = getAuditStatuses(jobId, JobAuditStatus.SourceStatus.VID.name());
191 assertThat(auditVidStatuses, hasItemsFromCollection(expectedVidStatuses));
192 if (expectedMsoStatuses!=null) {
193 final List<JobAuditStatus> auditMsoStatuses = getAuditStatuses(jobId, JobAuditStatus.SourceStatus.MSO.name());
194 assertThat(auditMsoStatuses, containsInAnyOrder(expectedMsoStatuses.toArray()));
196 }, timeoutInSeconds);
199 protected void assertAndRetryIfNeeded(Runnable asserter, long timeoutInSeconds) {
200 TestUtils.assertAndRetryIfNeeded(timeoutInSeconds, asserter);
203 protected ImmutableList<JobAuditStatus> vidAuditStatusesCompletedWithErrors(String jobId) {
204 return ImmutableList.of(
205 vidAuditStatus(jobId, "PENDING", false),
206 vidAuditStatus(jobId, "IN_PROGRESS", false),
207 vidAuditStatus(jobId, "COMPLETED_WITH_ERROR", true)
211 protected ImmutableList<JobAuditStatus> vidAuditStatusesFailed(String jobId) {
212 return ImmutableList.of(
213 vidAuditStatus(jobId, "PENDING", false),
214 vidAuditStatus(jobId, "IN_PROGRESS", false),
215 vidAuditStatus(jobId, "FAILED", true)
218 protected ImmutableList<JobAuditStatus> vidAuditStatusesFailedAndPaused(String jobId) {
219 return ImmutableList.of(
220 vidAuditStatus(jobId, "PENDING", false),
221 vidAuditStatus(jobId, "IN_PROGRESS", false),
222 vidAuditStatus(jobId, "FAILED_AND_PAUSED", true)
225 protected JobAuditStatus vidAuditStatus(String jobId, String jobStatus, boolean isFinal) {
226 return new JobAuditStatus(UUID.fromString(jobId), jobStatus, JobAuditStatus.SourceStatus.VID, null, null, isFinal);
229 public static class JobIdAndStatusMatcher extends BaseMatcher<ServiceInfo> {
230 protected String expectedJobId;
232 public JobIdAndStatusMatcher(String expectedJobId) {
233 this.expectedJobId = expectedJobId;
237 public boolean matches(Object item) {
238 if (!(item instanceof ServiceInfo)) {
241 ServiceInfo serviceInfo = (ServiceInfo) item;
242 return expectedJobId.equals(serviceInfo.jobId);
246 public void describeTo(Description description) {
247 description.appendText("failed to find job with uuid ")
248 .appendValue(expectedJobId);
254 protected Map<Keys,String> generateNames() {
255 return Stream.of(Keys.values()).collect(
256 Collectors.toMap(x->x, x -> UUID.randomUUID().toString().replace("-","")));
259 protected ImmutableList<BasePreset> addPresetsForCreateBulkOfCreateInstances(int bulkSize, Map<Keys, String> names){
260 ImmutableList<BasePreset> msoBulkPresets = generateMsoCreateBulkPresets(bulkSize, names);
261 ImmutableList<BasePreset> presets = new ImmutableList.Builder<BasePreset>()
262 .add(new PresetGetSessionSlotCheckIntervalGet())
263 .add(new PresetAAIGetSubscribersGet())
264 .add(PresetAAIGetCloudOwnersByCloudRegionId.PRESET_MTN3_TO_ATT_SABABA)
265 .addAll(msoBulkPresets)
266 .add(new PresetMSOOrchestrationRequestGet())
272 protected ImmutableList<BasePreset> generateMsoCreateBulkPresets(int bulkSize, Map<Keys, String> names) {
273 return IntStream.rangeClosed(0, bulkSize-1).
274 mapToObj(i-> new PresetMSOCreateServiceInstanceGen2WithNames(names, i))
275 .collect(ImmutableList.toImmutableList());
278 protected ResponseEntity<List<JobAuditStatus>> auditStatusCall(String url) {
279 return restTemplate.exchange(
281 org.springframework.http.HttpMethod.GET,
283 new ParameterizedTypeReference<List<JobAuditStatus>>() {});
287 public static Object[][] auditSources() {
288 return new Object[][]{{JobAuditStatus.SourceStatus.VID},{JobAuditStatus.SourceStatus.MSO}};
293 protected List<String> createBulkAndWaitForBeCompleted(int bulkSize){
294 Map<Keys, String> names = generateNames();
295 ImmutableList<BasePreset> presets = addPresetsForCreateBulkOfCreateInstances(bulkSize, names);
296 final List<String> jobIds = createBulkOfMacroInstances(presets, false, bulkSize, names);
297 Assert.assertEquals(jobIds.size(),bulkSize);
299 waitForJobsToSuccessfullyCompleted(bulkSize, jobIds);
303 public void waitForJobsToSuccessfullyCompleted(int bulkSize, List<String> jobIds) {
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,
314 protected List<JobAuditStatus> getJobMsoAuditStatusForAlaCarte(String jobUUID, String requestId, String serviceInstanceId){
315 String url = getMsoJobAuditUrl().replace("{JOB_ID}",jobUUID);
317 if(!StringUtils.isEmpty(requestId)) {
318 url = url + "?requestId=" + requestId;
319 if(!StringUtils.isEmpty(serviceInstanceId)) {
320 url = url + "&serviceInstanceId=" + serviceInstanceId;
323 return callAuditStatus(url);
326 protected List<JobAuditStatus> getAuditStatuses(String jobUUID, String source){
327 String url = getJobAuditUrl().replace("{JOB_ID}",jobUUID).replace("{SOURCE}", source);
328 return callAuditStatus(url);
331 protected List<JobAuditStatus> getAuditStatusesForInstance(String type, String instanceId){
332 String url = getInstanceAuditInfoUrl().replace("{TYPE}",type).replace("{INSTANCE_ID}", instanceId);
333 return callAuditStatus(url);
336 private List<JobAuditStatus> callAuditStatus(String url) {
337 ResponseEntity<List<JobAuditStatus>> statusesResponse = auditStatusCall(url);
338 assertThat(statusesResponse.getStatusCode(), CoreMatchers.equalTo(HttpStatus.OK));
339 return statusesResponse.getBody();
342 protected Map<String, JobStatus> addBulkAllPendingButOneInProgress(){
343 return addBulkAllPendingButOneInProgress(3);
346 protected Map<String, JobStatus> addBulkAllPendingButOneInProgress(int bulkSize){
347 Map<Keys, String> names = generateNames();
348 ImmutableList<BasePreset> msoBulkPresets = generateMsoCreateBulkPresets(bulkSize, names);
349 ImmutableList<BasePreset> presets = new ImmutableList.Builder<BasePreset>()
350 .add(new PresetGetSessionSlotCheckIntervalGet())
351 .add(new PresetAAIGetSubscribersGet())
352 .add(PresetAAIGetCloudOwnersByCloudRegionId.PRESET_MTN3_TO_ATT_SABABA)
353 .addAll(msoBulkPresets)
354 .add(new PresetMSOOrchestrationRequestGet("IN_PROGRESS"))
356 final List<String> jobIds = createBulkOfMacroInstances(presets, false, bulkSize, names);
358 // wait for single IN_PROGRESS, so statuses will stop from changing
359 Wait.waitFor(foo -> serviceListCall().getBody().stream()
360 .filter(si -> jobIds.contains(si.jobId))
361 .anyMatch(si -> si.jobStatus.equals(JobStatus.IN_PROGRESS)),
364 final Map<String, JobStatus> statusMapBefore = serviceListCall().getBody().stream()
365 .filter(si -> jobIds.contains(si.jobId))
366 .collect(toMap(si -> si.jobId, si -> si.jobStatus));
368 assertThat(jobIds, hasSize(bulkSize));
371 return statusMapBefore;
374 protected String deleteOneJobHavingTheStatus(Map<String, JobStatus> jobIdToStatus, JobStatus jobStatus) {
375 final String jobToDelete = jobIdToStatus.entrySet().stream()
376 .filter(entry -> entry.getValue().equals(jobStatus))
377 .map(Map.Entry::getKey)
378 .findFirst().orElseThrow(() -> new AssertionError("no job in " + jobStatus + " state: " + jobIdToStatus));
381 restTemplate.delete(getDeleteServiceUrl(jobToDelete));
387 protected MsoResponseWrapper2 hideService(String jobId) {
388 MsoResponseWrapper2 responseWrapper2 = callMsoForResponseWrapper(org.springframework.http.HttpMethod.POST, getHideServiceUri(jobId), "");
389 return responseWrapper2;
392 protected List<String> createBulkOfInstancesAndAssert(ImmutableList<BasePreset> presets, boolean isPause, int bulkSize, JobStatus finalState, Map<Keys, String> names){
393 List<String> jobIds = createBulkOfMacroInstances(presets, isPause, bulkSize, names);
394 Assert.assertEquals(jobIds.size(), bulkSize);
395 for(String jobId: jobIds) {
396 assertExpectedStatusAndServiceInfo(isPause, finalState, names, jobId);
402 protected void assertExpectedStatusAndServiceInfo(boolean isPause, JobStatus finalState, Map<Keys, String> names, String jobId) {
403 assertExpectedStatusAndServiceInfo(finalState, jobId, new ServiceInfo("us16807000", JobStatus.IN_PROGRESS, isPause, "someID",
404 "someName", "myProject", "NFT1", "NFTJSSSS-NFT1", "greatTenant", "greatTenant", "hvf3", null,
405 "mySubType", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", null, names.get(Keys.SERVICE_NAME),
406 "5c9e863f-2716-467b-8799-4a67f378dcaa", "AIM_TRANSPORT_00004", "1.0", jobId, null, ServiceAction.INSTANTIATE, false));
409 protected void assertExpectedStatusAndServiceInfo(JobStatus finalState, String jobId, ServiceInfo expectedServiceInfo) {
410 assertExpectedStatusAndServiceInfo(finalState, jobId, PATIENCE_LEVEL.FAIL_FAST, expectedServiceInfo);
413 enum PATIENCE_LEVEL { FAIL_FAST, FAIL_SLOW, FAIL_VERY_SLOW }
415 protected void assertExpectedStatusAndServiceInfo(JobStatus finalState, String jobId, PATIENCE_LEVEL patienceLevel, ServiceInfo expectedServiceInfo) {
416 JobInfoChecker<Integer> jobInfoChecker = new JobInfoChecker<>(
417 restTemplate, ImmutableSet.of(JobStatus.PENDING, JobStatus.IN_PROGRESS, finalState), jobId, expectedServiceInfo);
418 boolean result = jobInfoChecker.test(null);
419 assertTrue("service info of jobId: " + jobId + " was in status: " + jobInfoChecker.lastStatus, result);
421 jobInfoChecker.setExpectedJobStatus(ImmutableSet.of(finalState));
422 if (ImmutableList.of(JobStatus.COMPLETED, JobStatus.PAUSE).contains(finalState) && expectedServiceInfo.serviceInstanceId==null) {
423 expectedServiceInfo.serviceInstanceId = BaseMSOPreset.DEFAULT_INSTANCE_ID;
425 result = Wait.waitFor(jobInfoChecker, null, 30, waitIntervalBy(patienceLevel));
426 assertTrue("service info of jobId: " + jobId + " was in status: " + jobInfoChecker.lastStatus, result);
429 private int waitIntervalBy(PATIENCE_LEVEL patienceLevel) {
430 switch (patienceLevel) {
440 protected List<String> createBulkOfMacroInstances(ImmutableList<BasePreset> presets, boolean isPause, int bulkSize, Map<Keys, String> names) {
441 SimulatorApi.registerExpectationFromPresets(presets, SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET);
442 return createBulkOfInstances(isPause, bulkSize, names, CREATE_BULK_OF_MACRO_REQUEST);
445 public List<String> createBulkOfInstances(boolean isPause, int bulkSize, Map<Keys, String> names, String requestDetailsFileName){
447 String requestBody = TestUtils.convertRequest(objectMapper, requestDetailsFileName);
448 requestBody = requestBody.replace("\"IS_PAUSE_VALUE\"", String.valueOf(isPause)).replace("\"BULK_SIZE\"", String.valueOf(bulkSize));
449 for (Map.Entry<Keys, String> e : names.entrySet()) {
450 requestBody = requestBody.replace(e.getKey().name(), e.getValue());
452 MsoResponseWrapper2 responseWrapper2 = callMsoForResponseWrapper(org.springframework.http.HttpMethod.POST, getCreateBulkUri(), requestBody);
453 assertNotNull(responseWrapper2);
454 return (List<String>)responseWrapper2.getEntity();
457 protected List<String> retryJob(String jobId) {
458 ResponseEntity<String> retryBulkPayload = getRetryBulk(jobId);
459 return retryJobWithChangedData(jobId, retryBulkPayload.getBody());
462 protected List<String> retryJobWithChangedData(String jobId, String requestBody) {
463 String retryUri = getRetryJobWithChangedDataUrl();
464 retryUri = retryUri.replace("{JOB_ID}", jobId);
465 MsoResponseWrapper2 responseWrapper2 = callMsoForResponseWrapper(HttpMethod.POST, retryUri, requestBody);
466 assertNotNull(responseWrapper2);
467 return (List<String>)responseWrapper2.getEntity();
470 protected ResponseEntity<String> getRetryBulk(String jobId) {
471 String retryUri = getTopologyForRetryUrl();
472 retryUri = retryUri.replace("{JOB_ID}", jobId);
473 return restTemplateErrorAgnostic.getForEntity(retryUri, String.class);
476 protected Object getResourceAuditInfo(String trackById) {
477 return restTemplate.getForObject(buildUri("/asyncInstantiation/auditStatusForRetry/{trackById}"), Object.class, trackById);
480 public class JobInfoChecker<Integer> implements Predicate<Integer> {
482 protected final RestTemplate restTemplate;
483 protected Set<JobStatus> expectedJobStatus;
484 protected ServiceInfo expectedServiceInfo;
485 protected final String jobId;
486 protected JobStatus lastStatus;
488 public JobInfoChecker(RestTemplate restTemplate, Set<JobStatus> expectedJobStatus, String jobId, ServiceInfo expectedServiceInfo) {
489 this.restTemplate = restTemplate;
490 this.expectedJobStatus = expectedJobStatus;
492 this.expectedServiceInfo = expectedServiceInfo;
495 public void setExpectedJobStatus(Set<JobStatus> expectedJobStatus) {
496 this.expectedJobStatus = expectedJobStatus;
500 public boolean test(Integer integer) {
501 ResponseEntity<List<ServiceInfo>> serviceListResponse = serviceListCall();
502 assertThat(serviceListResponse.getStatusCode(), CoreMatchers.equalTo(HttpStatus.OK));
503 assertThat(serviceListResponse.getBody(), hasItem(new JobIdAndStatusMatcher(jobId)));
504 ServiceInfo serviceInfoFromDB = serviceListResponse.getBody().stream()
505 .filter(serviceInfo -> serviceInfo.jobId.equals(jobId))
506 .findFirst().orElse(null);
507 Assert.assertNotNull(serviceInfoFromDB);
508 Assert.assertEquals(serviceInfoDataReflected(serviceInfoFromDB), serviceInfoDataReflected(expectedServiceInfo));
509 assertTrue("actual service instance doesn't contain template service name:" + expectedServiceInfo.serviceInstanceName,
510 serviceInfoFromDB.serviceInstanceName.contains(expectedServiceInfo.serviceInstanceName));
512 if (expectedServiceInfo.serviceInstanceId != null && ImmutableList.of(JobStatus.COMPLETED, JobStatus.PAUSE, JobStatus.COMPLETED_WITH_ERRORS).contains(serviceInfoFromDB.jobStatus)) {
513 MatcherAssert.assertThat("service instance id is wrong", serviceInfoFromDB.serviceInstanceId, CoreMatchers.is(expectedServiceInfo.serviceInstanceId));
515 if (expectedJobStatus.size()==1) {
516 assertEquals("job status is wrong", getExpectedRetryEnabled((JobStatus)(expectedJobStatus.toArray()[0])), serviceInfoFromDB.isRetryEnabled);
518 lastStatus = serviceInfoFromDB.jobStatus;
519 return expectedJobStatus.contains(serviceInfoFromDB.jobStatus);
523 protected ResponseEntity<List<ServiceInfo>> serviceListCall() {
524 return restTemplate.exchange(
526 org.springframework.http.HttpMethod.GET,
528 new ParameterizedTypeReference<List<ServiceInfo>>() {});
531 //serialize fields except of fields we cannot know ahead of time
532 protected static String serviceInfoDataReflected(ServiceInfo service1) {
533 return new ReflectionToStringBuilder(service1, ToStringStyle.SHORT_PREFIX_STYLE)
534 .setExcludeFieldNames("jobStatus", "templateId", "statusModifiedDate", "createdBulkDate", "serviceInstanceId", "serviceInstanceName", "isRetryEnabled")
538 protected Map<Keys, String> addBulkPendingWithCustomList(List<BasePreset> customPresets){
539 Map<Keys, String> names = generateNames();
540 final int bulkSize = 2 + customPresets.size();
542 List<BasePreset> msoBulkPresets = generateMsoCreateBulkPresets(bulkSize, names);
543 ImmutableList<BasePreset> presets = new ImmutableList.Builder<BasePreset>()
544 .add(new PresetGetSessionSlotCheckIntervalGet())
545 .add(new PresetAAIGetSubscribersGet())
546 .add(PresetAAIGetCloudOwnersByCloudRegionId.PRESET_MTN3_TO_ATT_SABABA, PresetAAIGetCloudOwnersByCloudRegionId.PRESET_MDT1_TO_ATT_NC)
547 .addAll(msoBulkPresets)
548 .addAll(customPresets)
551 List<String> jobIds = createBulkOfMacroInstances(presets, false, bulkSize, names);
552 Assert.assertEquals(jobIds.size(),bulkSize);
557 protected void verifyAuditStatuses(String jobId, List<String> statuses, JobAuditStatus.SourceStatus source) {
558 int statusesSize = statuses.size();
559 AtomicReference<List<JobAuditStatus>> actualAudits = new AtomicReference<>();
560 if (source.equals(JobAuditStatus.SourceStatus.VID)) {
561 actualAudits.set(getAuditStatuses(jobId, JobAuditStatus.SourceStatus.VID.name()));
562 org.junit.Assert.assertEquals("Received number of VID statuses is not as expected", statusesSize, actualAudits.get().size());
564 boolean isStatusedSizeAsExpected = Wait.waitFor(x-> {
565 actualAudits.set(getAuditStatuses(jobId, JobAuditStatus.SourceStatus.MSO.name()));
566 return actualAudits.get().size() == statusesSize;
568 org.junit.Assert.assertTrue("Received number of MSO statuses is not as expected. Expected: " + statusesSize + ". Received: " + actualAudits.get().size(), isStatusedSizeAsExpected);
570 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()));
573 protected void verifyInstanceAuditStatuses(List<JobAuditStatus> expectedStatuses, List<JobAuditStatus> actualStatuses) {
574 final int expectedSize = expectedStatuses.size();
575 assertTrue("Expected statuses size is "+ expectedSize +", actual size is "+actualStatuses.size(), new Integer(expectedSize).equals(actualStatuses.size()));
576 IntStream.range(0, expectedSize).forEach(i-> {
578 final JobAuditStatus expectedStatus = expectedStatuses.get(i);
579 final JobAuditStatus actualStatus = actualStatuses.get(i);
580 org.junit.Assert.assertEquals("MSO status #" + i + " is not as expected", expectedStatus.getJobStatus(), actualStatus.getJobStatus());
581 org.junit.Assert.assertEquals("MSO requestId #" + i + " is not as expected", expectedStatus.getRequestId(), actualStatus.getRequestId());
582 org.junit.Assert.assertEquals("MSO additionalInfo #" + i + " is not as expected", expectedStatus.getAdditionalInfo(), actualStatus.getAdditionalInfo());
583 org.junit.Assert.assertEquals("MSO jobID #" + i + " is not as expected", expectedStatus.getJobId(), actualStatus.getJobId());
584 org.junit.Assert.assertEquals("MSO instanceName #" + i + " is not as expected", expectedStatus.getInstanceName(), actualStatus.getInstanceName());
585 org.junit.Assert.assertEquals("MSO instanceType #" + i + " is not as expected", expectedStatus.getInstanceType(), actualStatus.getInstanceType());
588 protected static JobStatus getErrorStatus() {
589 return Features.FLAG_2008_PAUSE_VFMODULE_INSTANTIATION_FAILURE.isActive() ?
590 JobStatus.FAILED_AND_PAUSED : JobStatus.COMPLETED_WITH_ERRORS;