2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 AT&T 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.so.bpmn.infrastructure.workflow.tasks;
23 import static org.hamcrest.CoreMatchers.is;
24 import static org.junit.Assert.assertThat;
25 import static org.mockito.Matchers.any;
26 import static org.mockito.Matchers.anyBoolean;
27 import static org.mockito.Matchers.eq;
28 import static org.mockito.Mockito.doReturn;
29 import static org.mockito.Mockito.mock;
30 import static org.mockito.Mockito.never;
31 import static org.mockito.Mockito.times;
32 import static org.mockito.Mockito.verify;
33 import static org.mockito.Mockito.when;
35 import java.io.IOException;
36 import java.nio.file.Files;
37 import java.nio.file.Paths;
38 import java.util.ArrayList;
39 import java.util.Arrays;
40 import java.util.Collections;
41 import java.util.List;
43 import org.camunda.bpm.engine.delegate.DelegateExecution;
44 import org.junit.Test;
45 import org.junit.runner.RunWith;
46 import org.mockito.InjectMocks;
47 import org.mockito.Mock;
48 import org.mockito.Spy;
49 import org.mockito.runners.MockitoJUnitRunner;
50 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup;
51 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
52 import org.onap.so.client.exception.ExceptionBuilder;
53 import org.onap.so.client.orchestration.AAIConfigurationResources;
54 import org.onap.so.db.catalog.beans.ConfigurationResource;
55 import org.onap.so.db.catalog.beans.CvnfcCustomization;
56 import org.onap.so.db.catalog.beans.VnfVfmoduleCvnfcConfigurationCustomization;
57 import org.onap.so.db.catalog.beans.macro.OrchestrationFlow;
58 import org.onap.so.db.catalog.client.CatalogDbClient;
60 @RunWith(MockitoJUnitRunner.class)
61 public class WorkflowActionUnitTest {
63 private final static String JSON_FILE_LOCATION = "src/test/resources/__files/Macro/";
66 private CatalogDbClient catalogDbClient;
68 private BBInputSetup bbInputSetup;
70 private BBInputSetupUtils bbInputSetupUtils;
72 private ExceptionBuilder exceptionBuilder;
74 private AAIConfigurationResources aaiConfigurationResources;
78 private WorkflowAction workflowAction;
81 public void filterOrchFlowsHasFabricTest() {
83 List<OrchestrationFlow> flows = createFlowList(
84 "DeactivateFabricConfigurationBB",
87 "ActivateFabricConfigurationBB",
89 doReturn(Arrays.asList("yes", "yes")).when(workflowAction).traverseCatalogDbForConfiguration(any(String.class), any(String.class));
91 List<OrchestrationFlow> result = workflowAction.filterOrchFlows(flows, WorkflowType.VFMODULE, mock(DelegateExecution.class));
93 assertThat(result, is(flows));
97 public void filterOrchFlowNoFabricTest() {
98 List<OrchestrationFlow> flows = createFlowList(
99 "DeactivateFabricConfigurationBB",
102 "ActivateFabricConfigurationBB",
104 doReturn(Arrays.asList()).when(workflowAction).traverseCatalogDbForConfiguration(any(String.class), any(String.class));
106 List<OrchestrationFlow> result = workflowAction.filterOrchFlows(flows, WorkflowType.VFMODULE, mock(DelegateExecution.class));
107 List<OrchestrationFlow> expected = createFlowList(
112 assertThat(result, is(expected));
116 public void traverseCatalogDbForConfigurationTest() {
118 CvnfcCustomization cvnfcCustomization = new CvnfcCustomization();
119 VnfVfmoduleCvnfcConfigurationCustomization vfModuleCustomization = new VnfVfmoduleCvnfcConfigurationCustomization();
120 ConfigurationResource configuration = new ConfigurationResource();
121 configuration.setToscaNodeType("FabricConfiguration");
122 configuration.setModelUUID("my-uuid");
123 vfModuleCustomization.setConfigurationResource(configuration);
124 cvnfcCustomization.setVnfVfmoduleCvnfcConfigurationCustomization(Collections.singleton(vfModuleCustomization));
125 List<CvnfcCustomization> cvnfcCustomizations = Arrays.asList(cvnfcCustomization);
126 when(catalogDbClient.getCvnfcCustomizationByVnfCustomizationUUIDAndVfModuleCustomizationUUID(any(String.class), any(String.class)))
127 .thenReturn(cvnfcCustomizations);
129 List<String> results = workflowAction.traverseCatalogDbForConfiguration("myVnfCustomizationId", "myVfModuleCustomizationId");
131 assertThat(results, is(Arrays.asList("my-uuid")));
136 public void verifyFilterOrchInvocation() throws Exception {
137 DelegateExecution execution = mock(DelegateExecution.class);
139 when(execution.getVariable(eq("aLaCarte"))).thenReturn(true);
140 when(execution.getVariable(eq("bpmnRequest"))).thenReturn(getJson("ServiceMacroAssign.json"));
141 when(execution.getVariable(eq("requestUri"))).thenReturn("/v6/serviceInstances/123/vnfs/1234");
143 OrchestrationFlow flow = new OrchestrationFlow();
144 flow.setFlowName("flow x");
146 List<OrchestrationFlow> flows = Arrays.asList(flow);
147 doReturn(Arrays.asList(flow)).when(workflowAction).queryNorthBoundRequestCatalogDb(any(), any(), any(), anyBoolean());
148 workflowAction.selectExecutionList(execution);
150 verify(workflowAction, times(1)).filterOrchFlows(eq(flows), any(), any());
152 flow = new OrchestrationFlow();
153 flow.setFlowName("flow y");
154 flows = Arrays.asList(flow);
155 when(execution.getVariable(eq("aLaCarte"))).thenReturn(false);
156 workflowAction.selectExecutionList(execution);
158 verify(workflowAction, never()).filterOrchFlows(eq(flows), any(), any());
162 private String getJson(String filename) throws IOException {
163 return new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + filename)));
166 private List<OrchestrationFlow> createFlowList(String... myList) {
168 List<OrchestrationFlow> result = new ArrayList<>();
169 for (String name : myList) {
170 OrchestrationFlow flow = new OrchestrationFlow();
171 flow.setFlowName(name);