2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.vid.job.impl;
23 import com.google.common.collect.ImmutableMap;
24 import org.apache.commons.lang3.RandomUtils;
25 import org.onap.vid.job.Job;
26 import org.onap.vid.job.JobAdapter;
27 import org.onap.vid.job.JobType;
28 import org.onap.vid.job.command.JobCommandFactoryTest;
29 import org.testng.annotations.Test;
31 import java.util.UUID;
33 import static org.testng.Assert.assertEquals;
34 import static org.testng.Assert.assertNotEquals;
35 import static org.testng.AssertJUnit.assertNotNull;
37 public class JobAdapterTest {
40 public void testCreateServiceInstantiationJob() {
41 JobAdapter jobAdapter = new JobAdapterImpl();
43 JobType jobType = JobType.NoOp;
44 JobAdapter.AsyncJobRequest request = new JobCommandFactoryTest.MockedRequest(42,"nothing");
45 UUID templateId = UUID.randomUUID();
46 String userId = "ou012t";
47 String optimisticUniqueServiceInstanceName = "optimisticUniqueServiceInstanceName";
48 int indexInBulk = RandomUtils.nextInt();
49 Job job = jobAdapter.createServiceInstantiationJob(
54 optimisticUniqueServiceInstanceName,
58 assertEquals(job.getType(), jobType);
59 assertEquals(job.getSharedData().getRequest(), request);
60 assertEquals(job.getSharedData().getRequestType(), request.getClass());
61 assertEquals(job.getSharedData().getUserId(), userId);
62 assertEquals(job.getSharedData().getJobUuid(), job.getUuid());
63 assertEquals(job.getSharedData().getRootJobId(), job.getUuid());
64 assertNotNull(job.getUuid());
65 assertEquals(job.getTemplateId(), templateId);
66 assertEquals(job.getData().get("optimisticUniqueServiceInstanceName"), optimisticUniqueServiceInstanceName);
67 assertEquals((int)job.getIndexInBulk(), indexInBulk );
68 assertEquals(job.getStatus(), Job.JobStatus.PENDING);
72 public void testCreateChildJob() {
74 JobAdapter jobAdapter = new JobAdapterImpl();
76 UUID templateId = UUID.randomUUID();
77 String userId = "ou012t";
78 String optimisticUniqueServiceInstanceName = "optimisticUniqueServiceInstanceName";
79 int indexInBulk = RandomUtils.nextInt();
80 Job grandJob = jobAdapter.createServiceInstantiationJob(
82 new JobCommandFactoryTest.MockedRequest(99, "anything"),
85 optimisticUniqueServiceInstanceName,
89 Job.JobStatus jobStatus = Job.JobStatus.PAUSE;
90 JobType jobType = JobType.NoOp;
91 JobAdapter.AsyncJobRequest request = new JobCommandFactoryTest.MockedRequest(42,"nothing");
92 Job parentJob = jobAdapter.createChildJob(jobType, jobStatus, request, grandJob.getSharedData(), ImmutableMap.of());
94 assertEquals(parentJob.getType(), jobType);
95 assertEquals(parentJob.getSharedData().getRequest(), request);
96 assertEquals(parentJob.getSharedData().getRequestType(), request.getClass());
97 assertEquals(parentJob.getSharedData().getUserId(), userId);
98 assertEquals(parentJob.getSharedData().getJobUuid(), parentJob.getUuid());
99 assertNotNull(parentJob.getUuid());
100 assertNotEquals(parentJob.getUuid(), grandJob.getUuid());
101 assertEquals(parentJob.getStatus(), jobStatus);
102 assertEquals(parentJob.getSharedData().getRootJobId(), grandJob.getUuid());
104 Job.JobStatus jobStatus2 = Job.JobStatus.IN_PROGRESS;
105 JobType jobType2 = JobType.AggregateState;
106 JobAdapter.AsyncJobRequest request2 = new JobCommandFactoryTest.MockedRequest(66,"abc");
107 Job job = jobAdapter.createChildJob(jobType2, jobStatus2, request2, parentJob.getSharedData(), ImmutableMap.of());
109 assertEquals(job.getType(), jobType2);
110 assertEquals(job.getSharedData().getRequest(), request2);
111 assertEquals(job.getSharedData().getRequestType(), request2.getClass());
112 assertEquals(job.getSharedData().getUserId(), userId);
113 assertEquals(job.getSharedData().getJobUuid(), job.getUuid());
114 assertNotNull(job.getUuid());
115 assertNotEquals(job.getUuid(), parentJob.getUuid());
116 assertEquals(job.getStatus(), jobStatus2);
117 assertEquals(job.getSharedData().getRootJobId(), grandJob.getUuid());