1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
package org.onap.vid.job.impl;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.RandomUtils;
import org.onap.vid.job.Job;
import org.onap.vid.job.JobAdapter;
import org.onap.vid.job.JobType;
import org.onap.vid.job.command.JobCommandFactoryTest;
import org.testng.annotations.Test;
import java.util.UUID;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import static org.testng.AssertJUnit.assertNotNull;
public class JobAdapterTest {
@Test
public void testCreateServiceInstantiationJob() {
JobAdapter jobAdapter = new JobAdapterImpl();
JobType jobType = JobType.NoOp;
JobAdapter.AsyncJobRequest request = new JobCommandFactoryTest.MockedRequest(42,"nothing");
UUID templateId = UUID.randomUUID();
String userId = "ou012t";
String optimisticUniqueServiceInstanceName = "optimisticUniqueServiceInstanceName";
int indexInBulk = RandomUtils.nextInt();
Job job = jobAdapter.createServiceInstantiationJob(
jobType,
request,
templateId,
userId,
optimisticUniqueServiceInstanceName,
indexInBulk
);
assertEquals(job.getType(), jobType);
assertEquals(job.getSharedData().getRequest(), request);
assertEquals(job.getSharedData().getRequestType(), request.getClass());
assertEquals(job.getSharedData().getUserId(), userId);
assertEquals(job.getSharedData().getJobUuid(), job.getUuid());
assertEquals(job.getSharedData().getRootJobId(), job.getUuid());
assertNotNull(job.getUuid());
assertEquals(job.getTemplateId(), templateId);
assertEquals(job.getData().get("optimisticUniqueServiceInstanceName"), optimisticUniqueServiceInstanceName);
assertEquals((int)job.getIndexInBulk(), indexInBulk );
assertEquals(job.getStatus(), Job.JobStatus.PENDING);
}
@Test
public void testCreateChildJob() {
JobAdapter jobAdapter = new JobAdapterImpl();
UUID templateId = UUID.randomUUID();
String userId = "ou012t";
String optimisticUniqueServiceInstanceName = "optimisticUniqueServiceInstanceName";
int indexInBulk = RandomUtils.nextInt();
Job grandJob = jobAdapter.createServiceInstantiationJob(
JobType.HttpCall,
new JobCommandFactoryTest.MockedRequest(99, "anything"),
templateId,
userId,
optimisticUniqueServiceInstanceName,
indexInBulk
);
Job.JobStatus jobStatus = Job.JobStatus.PAUSE;
JobType jobType = JobType.NoOp;
JobAdapter.AsyncJobRequest request = new JobCommandFactoryTest.MockedRequest(42,"nothing");
Job parentJob = jobAdapter.createChildJob(jobType, jobStatus, request, grandJob.getSharedData(), ImmutableMap.of());
assertEquals(parentJob.getType(), jobType);
assertEquals(parentJob.getSharedData().getRequest(), request);
assertEquals(parentJob.getSharedData().getRequestType(), request.getClass());
assertEquals(parentJob.getSharedData().getUserId(), userId);
assertEquals(parentJob.getSharedData().getJobUuid(), parentJob.getUuid());
assertNotNull(parentJob.getUuid());
assertNotEquals(parentJob.getUuid(), grandJob.getUuid());
assertEquals(parentJob.getStatus(), jobStatus);
assertEquals(parentJob.getSharedData().getRootJobId(), grandJob.getUuid());
Job.JobStatus jobStatus2 = Job.JobStatus.IN_PROGRESS;
JobType jobType2 = JobType.AggregateState;
JobAdapter.AsyncJobRequest request2 = new JobCommandFactoryTest.MockedRequest(66,"abc");
Job job = jobAdapter.createChildJob(jobType2, jobStatus2, request2, parentJob.getSharedData(), ImmutableMap.of());
assertEquals(job.getType(), jobType2);
assertEquals(job.getSharedData().getRequest(), request2);
assertEquals(job.getSharedData().getRequestType(), request2.getClass());
assertEquals(job.getSharedData().getUserId(), userId);
assertEquals(job.getSharedData().getJobUuid(), job.getUuid());
assertNotNull(job.getUuid());
assertNotEquals(job.getUuid(), parentJob.getUuid());
assertEquals(job.getStatus(), jobStatus2);
assertEquals(job.getSharedData().getRootJobId(), grandJob.getUuid());
}
}
|