2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Nokia. 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=========================================================
20 package org.onap.vid.services;
22 import org.mockito.InjectMocks;
23 import org.mockito.Mock;
24 import org.onap.vid.job.Job;
25 import org.onap.vid.job.JobAdapter;
26 import org.onap.vid.job.JobsBrokerService;
27 import org.onap.vid.job.impl.JobDaoImpl;
28 import org.onap.vid.model.JobBulk;
29 import org.onap.vid.model.JobModel;
30 import org.testng.Assert;
31 import org.testng.annotations.BeforeMethod;
32 import org.testng.annotations.BeforeSuite;
33 import org.testng.annotations.Test;
35 import javax.ws.rs.NotFoundException;
36 import java.util.ArrayList;
37 import java.util.List;
38 import java.util.UUID;
40 import static org.mockito.Mockito.*;
41 import static org.mockito.MockitoAnnotations.initMocks;
43 public class BulkInstantiationServiceImplTest {
46 private JobsBrokerService jobsBrokerService;
49 private JobAdapter jobAdapter;
52 private BulkInstantiationServiceImpl testSubject;
55 public void before() {
60 public void resetMocks() {
61 reset(jobsBrokerService);
66 public void getJobTest() {
67 UUID uuid = UUID.randomUUID();
68 Job job = createJob(uuid);
69 doReturn(job).when(jobsBrokerService).peek(uuid);
70 JobModel jobModel = createJobModel(uuid);
71 when(jobAdapter.toModel(job)).thenReturn(jobModel);
73 JobModel response = testSubject.getJob(uuid);
74 Assert.assertEquals(response.getUuid(), uuid);
77 @Test(expectedExceptions = {NotFoundException.class})
78 public void getJobTest_throwsExceptionOnEmptyUUID() {
80 Job job = createJob(uuid);
81 doReturn(job).when(jobsBrokerService).peek(uuid);
82 JobModel response = testSubject.getJob(uuid);
86 @Test(expectedExceptions = {NotFoundException.class})
87 public void getJobTest_throwsExceptionCauseJobDoesNotExists() {
88 UUID uuid = UUID.randomUUID();
89 doReturn(null).when(jobsBrokerService).peek(uuid);
90 JobModel response = testSubject.getJob(uuid);
94 private Job createJob(UUID uuid) {
95 Job job = new JobDaoImpl();
100 private JobModel createJobModel(UUID uuid) {
101 JobModel jobModel = new JobModel();
102 jobModel.setUuid(uuid);
106 private JobBulk createJobBulk(List<Job> jobList) {
107 List<JobModel> jobBulkList = new ArrayList<>();
108 jobList.stream().forEach(job -> {
109 JobModel jm = new JobModel();
110 jm.setUuid(job.getUuid());
113 return new JobBulk(jobBulkList);