2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Nokia 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.ImmutableList;
24 import com.google.common.collect.ImmutableMap;
25 import org.mockito.Mock;
26 import org.onap.vid.job.Job;
27 import org.onap.vid.job.JobAdapter;
28 import org.onap.vid.job.JobType;
29 import org.onap.vid.model.JobBulk;
30 import org.onap.vid.model.JobModel;
31 import org.testng.annotations.BeforeMethod;
32 import org.testng.annotations.Test;
34 import java.util.List;
35 import java.util.UUID;
36 import java.util.stream.Stream;
38 import static org.assertj.core.api.Assertions.assertThat;
39 import static org.mockito.Mockito.when;
40 import static org.mockito.MockitoAnnotations.initMocks;
42 public class JobAdapterImplTest {
45 private static final int SAMPLE_INDEX = 10;
46 private static final String SAMPLE_USER_ID = "sampleUserId";
52 private JobAdapter.AsyncJobRequest asyncJobRequest;
54 private UUID sampleUuid=UUID.randomUUID();
56 private JobAdapterImpl jobAdapter = new JobAdapterImpl();
62 when(job.getUuid()).thenReturn(sampleUuid);
63 when(job.getStatus()).thenReturn(Job.JobStatus.IN_PROGRESS);
64 when(job.getTemplateId()).thenReturn(sampleUuid);
68 public void shouldConvertJobToJobModel() {
71 JobModel convertedJob = jobAdapter.toModel(job);
73 assertThat(convertedJob.getUuid()).isEqualByComparingTo(sampleUuid);
74 assertThat(convertedJob.getStatus()).isEqualByComparingTo(Job.JobStatus.IN_PROGRESS);
75 assertThat(convertedJob.getTemplateId()).isEqualByComparingTo(sampleUuid);
80 public void shouldProperlyCreateJob() {
81 UUID uuid = UUID.randomUUID();
83 Job createdJob = jobAdapter.createJob(JobType.ServiceInstantiation, asyncJobRequest, uuid, SAMPLE_USER_ID, SAMPLE_INDEX);
85 assertThat(createdJob.getStatus()).isEqualByComparingTo(Job.JobStatus.PENDING);
86 assertThat(createdJob.getTemplateId()).isEqualByComparingTo(uuid);
87 assertThat(createdJob.getType()).isEqualByComparingTo(JobType.ServiceInstantiation);
88 assertThat(createdJob.getData()).isEqualTo(ImmutableMap.of("request", asyncJobRequest, "userId", SAMPLE_USER_ID));
92 public void shouldProperlyCreateBulkOfJobs(){
93 List<Job> bulkOfJobs = jobAdapter.createBulkOfJobs(ImmutableMap.of("count", 5, "type", JobType.InProgressStatus.name()));
96 assertThat(bulkOfJobs).hasSize(5);
98 Stream<Job> jobStream = bulkOfJobs.stream().filter(x -> JobType.InProgressStatus.equals(x.getType()) && Job.JobStatus.PENDING.equals(x.getStatus()));
100 assertThat(jobStream).hasSize(5);
105 public void shouldConvertListToBulkJob(){
106 JobBulk jobBulk = jobAdapter.toModelBulk(ImmutableList.of(job, job));
108 assertThat(jobBulk.getJobs()).hasSize(2);