blob: 289cd998bed2b363a75d9249d67c2df5eae3dbca [file] [log] [blame]
Aharoni, Pavel (pa0916)8c70f072018-11-18 00:07:12 +02001/*-
2 * ============LICENSE_START=======================================================
3 * OSAM
4 * ================================================================================
5 * Copyright (C) 2018 AT&T
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
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
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=========================================================
19 */
20package org.onap.osam.job.impl;
21
22import com.google.common.collect.ImmutableMap;
23import org.apache.commons.lang3.RandomUtils;
24import org.onap.osam.job.dao.job.JobStatus;
25import org.onap.osam.job.dao.job.OsamJob;
26import org.onap.osam.job.IJobFactory;
27import org.onap.osam.job.JobType;
28import org.onap.osam.job.command.JobCommandFactoryTest;
29import org.testng.annotations.Test;
30
31import java.util.UUID;
32
33import static org.testng.Assert.assertEquals;
34import static org.testng.Assert.assertNotEquals;
35import static org.testng.AssertJUnit.assertNotNull;
36
37public class JobAdapterTest {
38
39 @Test
40 public void testCreateServiceInstantiationJob() {
41 IJobFactory jobAdapter = new JobFactory();
42
43 JobType jobType = JobType.NoOp;
44 IJobFactory.AsyncJobRequest request = new JobCommandFactoryTest.MockedRequest(42,"nothing");
45 String userId = "ou012t";
46 String optimisticUniqueServiceInstanceName = "optimisticUniqueServiceInstanceName";
47 int indexInBulk = RandomUtils.nextInt();
48 OsamJob job = jobAdapter.createRootJob(
49 jobType,
50 request,
51 userId,
52 indexInBulk,
53 ImmutableMap.of());
54
55 assertEquals(job.getType(), jobType);
56 assertEquals(job.getSharedData().getRequest(), request);
57 assertEquals(job.getSharedData().getRequestType(), request.getClass());
58 assertEquals(job.getSharedData().getUserId(), userId);
59 assertEquals(job.getSharedData().getJobUuid(), job.getUuid());
60 assertEquals(job.getSharedData().getRootJobId(), job.getUuid());
61 assertNotNull(job.getUuid());
62 assertEquals((int)job.getIndexInBulk(), indexInBulk );
63 assertEquals(job.getStatus(), JobStatus.PENDING);
64 }
65
66 @Test
67 public void testCreateChildJob() {
68
69 IJobFactory jobAdapter = new JobFactory();
70
71 String userId = "ou012t";
72 String optimisticUniqueServiceInstanceName = "optimisticUniqueServiceInstanceName";
73 int indexInBulk = RandomUtils.nextInt();
74 OsamJob grandJob = jobAdapter.createRootJob(
75 JobType.HttpCall,
76 new JobCommandFactoryTest.MockedRequest(99, "anything"),
77 userId,
78 indexInBulk,
79 ImmutableMap.of()
80 );
81
82 JobStatus jobStatus = JobStatus.PAUSE;
83 JobType jobType = JobType.NoOp;
84 IJobFactory.AsyncJobRequest request = new JobCommandFactoryTest.MockedRequest(42,"nothing");
85 OsamJob parentJob = jobAdapter.createChildJob(jobType, jobStatus, request, grandJob.getSharedData(), ImmutableMap.of());
86
87 assertEquals(parentJob.getType(), jobType);
88 assertEquals(parentJob.getSharedData().getRequest(), request);
89 assertEquals(parentJob.getSharedData().getRequestType(), request.getClass());
90 assertEquals(parentJob.getSharedData().getUserId(), userId);
91 assertEquals(parentJob.getSharedData().getJobUuid(), parentJob.getUuid());
92 assertNotNull(parentJob.getUuid());
93 assertNotEquals(parentJob.getUuid(), grandJob.getUuid());
94 assertEquals(parentJob.getStatus(), jobStatus);
95 assertEquals(parentJob.getSharedData().getRootJobId(), grandJob.getUuid());
96
97 JobStatus jobStatus2 = JobStatus.IN_PROGRESS;
98 JobType jobType2 = JobType.HttpCall;
99 IJobFactory.AsyncJobRequest request2 = new JobCommandFactoryTest.MockedRequest(66,"abc");
100 OsamJob job = jobAdapter.createChildJob(jobType2, jobStatus2, request2, parentJob.getSharedData(), ImmutableMap.of());
101
102 assertEquals(job.getType(), jobType2);
103 assertEquals(job.getSharedData().getRequest(), request2);
104 assertEquals(job.getSharedData().getRequestType(), request2.getClass());
105 assertEquals(job.getSharedData().getUserId(), userId);
106 assertEquals(job.getSharedData().getJobUuid(), job.getUuid());
107 assertNotNull(job.getUuid());
108 assertNotEquals(job.getUuid(), parentJob.getUuid());
109 assertEquals(job.getStatus(), jobStatus2);
110 assertEquals(job.getSharedData().getRootJobId(), grandJob.getUuid());
111
112 }
113}