Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 1 | /*-
|
| 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 |
|
| 23 | package org.onap.osam.job.command;
|
| 24 |
|
| 25 | import com.google.common.collect.ImmutableMap;
|
| 26 | import org.mockito.Mock;
|
| 27 | import org.mockito.MockitoAnnotations;
|
| 28 | import org.onap.osam.job.Job;
|
| 29 | import org.onap.osam.job.JobCommand;
|
| 30 | import org.onap.osam.job.JobType;
|
| 31 | import org.testng.annotations.BeforeMethod;
|
| 32 | import org.testng.annotations.DataProvider;
|
| 33 | import org.testng.annotations.Test;
|
| 34 |
|
| 35 | import java.util.Arrays;
|
| 36 | import java.util.Map;
|
| 37 | import java.util.UUID;
|
| 38 | import java.util.stream.Collectors;
|
| 39 |
|
| 40 | import static org.hamcrest.CoreMatchers.equalTo;
|
| 41 | import static org.hamcrest.MatcherAssert.assertThat;
|
| 42 | import static org.mockito.Mockito.verify;
|
| 43 | import static org.mockito.Mockito.when;
|
| 44 |
|
| 45 | public 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 | }
|