align logic to new so api
[vid.git] / vid-app-common / src / test / java / org / onap / vid / services / ExternalWorkflowsServiceImplTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2019 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
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 package org.onap.vid.services;
22
23
24 import org.mockito.Mock;
25 import org.mockito.MockitoAnnotations;
26 import org.onap.vid.model.ArtifactInfo;
27 import org.onap.vid.model.SOWorkflow;
28 import org.onap.vid.model.SOWorkflowList;
29 import org.onap.vid.model.WorkflowInputParameter;
30 import org.onap.vid.model.WorkflowSource;
31 import org.onap.vid.model.WorkflowSpecification;
32 import org.onap.vid.model.WorkflowSpecificationWrapper;
33 import org.onap.vid.mso.MsoBusinessLogic;
34 import org.testng.annotations.BeforeMethod;
35 import org.testng.annotations.Test;
36
37 import java.util.Collections;
38 import java.util.List;
39 import java.util.UUID;
40
41 import static org.assertj.core.api.Assertions.assertThat;
42 import static org.mockito.Mockito.when;
43
44 public class ExternalWorkflowsServiceImplTest {
45
46     @Mock
47     private MsoBusinessLogic msoBusinessLogic;
48
49
50     private static final UUID SAMPLE_UUID = UUID.randomUUID();
51
52     @BeforeMethod
53     public void init() {
54         MockitoAnnotations.initMocks(this);
55     }
56
57     @Test
58     public void shouldReturnWorkflowsOnValidResponse() {
59         // given
60         ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(msoBusinessLogic);
61         WorkflowInputParameter parameter = new WorkflowInputParameter("sampleLabel", "text",
62                 true, Collections.EMPTY_LIST, "sampleName", "userParams", "description");
63         SOWorkflowList workflowList = createWorkflowList(parameter);
64         SOWorkflow workflow = new SOWorkflow(SAMPLE_UUID.toString(), "sampleName", WorkflowSource.SDC, Collections.singletonList(parameter));
65         when(msoBusinessLogic.getWorkflowListByModelId("test")).thenReturn(workflowList);
66         // when
67         List<SOWorkflow> workflows = extWorkflowsService.getWorkflows("test");
68         // then
69         assertThat(workflows).hasSize(1).contains(workflow);
70     }
71
72     private SOWorkflowList createWorkflowList(WorkflowInputParameter parameter) {
73         ArtifactInfo artifactInfo = new ArtifactInfo("workflow", SAMPLE_UUID.toString(), "sampleArtifactName",
74                 "sampleVersion", "sampleDescription", "sampleName", "sampleOperation", "sdc", "vnf");
75         WorkflowSpecification specification = new WorkflowSpecification(artifactInfo, Collections.EMPTY_LIST, Collections.singletonList(parameter));
76         WorkflowSpecificationWrapper wrapper = new WorkflowSpecificationWrapper(specification);
77         return new SOWorkflowList(Collections.singletonList(wrapper));
78     }
79
80 }