blob: 9c82b45a2a8e5c05ed160cf967962c9fcae28359 [file] [log] [blame]
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +03001/*-
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 */
20
21
22
23package org.onap.osam.job.command;
24
25import com.google.common.collect.ImmutableMap;
26import org.mockito.Mock;
27import org.mockito.MockitoAnnotations;
28import org.onap.osam.job.Job;
29import org.onap.osam.job.JobCommand;
30import org.onap.osam.job.JobType;
31import org.testng.annotations.BeforeMethod;
32import org.testng.annotations.DataProvider;
33import org.testng.annotations.Test;
34
35import java.util.Arrays;
36import java.util.Map;
37import java.util.UUID;
38import java.util.stream.Collectors;
39
40import static org.hamcrest.CoreMatchers.equalTo;
41import static org.hamcrest.MatcherAssert.assertThat;
42import static org.mockito.Mockito.verify;
43import static org.mockito.Mockito.when;
44
45public class JobCommandFactoryTest {
46
47 private JobCommandFactory jobCommandFactory;
48
49 @Mock
50 private Job job;
51
52 @Mock
53 private JobCommand mockCommand;
54
55 @BeforeMethod
56 public void initMocks() {
57 MockitoAnnotations.initMocks(this);
58 }
59
60 @BeforeMethod
61 public void setUp() {
62 jobCommandFactory = new JobCommandFactory(any -> mockCommand);
63 }
64
65 @DataProvider
66 public Object[][] jobTypes() {
67 return Arrays.stream(
68 JobType.values()
69 ).map(v -> new Object[]{v}).collect(Collectors.toList()).toArray(new Object[][]{});
70
71 }
72
73 @Test(dataProvider = "jobTypes")
74 public void givenJob_createCommandCallsTheInitAndReturnsTheInstance(JobType jobType) {
75
76 final UUID uuid = UUID.randomUUID();
77 final Map<String, Object> data = ImmutableMap.of("foo", "bar");
78
79 when(job.getType()).thenReturn(jobType);
80 when(job.getUuid()).thenReturn(uuid);
81 when(job.getData()).thenReturn(data);
82
83 final JobCommand command = jobCommandFactory.toCommand(job);
84
85 verify(mockCommand).init(uuid, data);
86
87 assertThat(command, equalTo(mockCommand));
88 }
89
90}