2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.onap.so.bpmn.infrastructure.decisionpoint.impl.buildingblock;
22 import static org.junit.Assert.assertEquals;
23 import static org.mockito.Mockito.verify;
24 import static org.mockito.Mockito.when;
25 import static org.onap.so.bpmn.infrastructure.decisionpoint.impl.buildingblock.MockControllerBB.TEST_ACTION;
26 import static org.onap.so.bpmn.infrastructure.decisionpoint.impl.buildingblock.MockControllerBB.TEST_ACTOR;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.onap.so.bpmn.common.BuildingBlockExecution;
31 import org.onap.so.client.exception.ExceptionBuilder;
32 import org.onap.so.db.catalog.beans.ControllerSelectionReference;
33 import org.onap.so.db.catalog.beans.PnfResourceCustomization;
34 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
35 import org.onap.so.db.catalog.client.CatalogDbClient;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.boot.test.mock.mockito.MockBean;
38 import org.springframework.test.context.ContextConfiguration;
39 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
41 @RunWith(SpringJUnit4ClassRunner.class)
42 @ContextConfiguration(classes = {ControllerExecutionBB.class, MockControllerBB.class, ExceptionBuilder.class})
43 public class ControllerExecutionBBTest {
45 private static final String ACTOR_PARAM = "actor";
46 private static final String ACTION_PARAM = "action";
47 private static final String RESOURCE_TYPE_PARAM = "resource_type";
49 private static final String TEST_RESOURCE_CUSTOMIZATION_UUID = "68dc9a92-214c-11e7-93ae-92361f002680";
50 private static final String TEST_CATALOGDB_CONTROLLER_ACTOR = "cds";
51 private static final String TEST_RESOURCE_TYPE = "Firewall";
52 private static final String TEST_CONTROLLER_REFERENCE_ACTOR = "sdnc";
53 private static final String TEST_SCOPE = "pnf";
56 private ControllerExecutionBB controllerExecutionBB;
59 private BuildingBlockExecution execution;
62 private CatalogDbClient client;
65 private PnfResourceCustomization pnfResourceCustomization;
68 private VnfResourceCustomization vnfResourceCustomization;
71 private ControllerSelectionReference controllerSelectionReference;
75 when(execution.getVariable(ACTOR_PARAM)).thenReturn(TEST_ACTOR);
76 when(execution.getVariable(ACTION_PARAM)).thenReturn(MockControllerBB.TEST_ACTION);
78 when(pnfResourceCustomization.getControllerActor()).thenReturn(TEST_CATALOGDB_CONTROLLER_ACTOR);
79 when(client.getPnfResourceCustomizationByModelCustomizationUUID(TEST_RESOURCE_CUSTOMIZATION_UUID))
80 .thenReturn(pnfResourceCustomization);
82 when(execution.getVariable(RESOURCE_TYPE_PARAM)).thenReturn(TEST_RESOURCE_TYPE);
83 when(controllerSelectionReference.getControllerName()).thenReturn(TEST_CONTROLLER_REFERENCE_ACTOR);
84 when(client.getControllerSelectionReferenceByVnfTypeAndActionCategory(TEST_RESOURCE_TYPE, TEST_ACTION))
85 .thenReturn(controllerSelectionReference);
89 public void testExecution_validInput_expectedOutput() {
90 controllerExecutionBB.execute(execution);
91 verify(execution).setVariable("stage", "ready");
92 verify(execution).setVariable("stage", "prepare");
93 verify(execution).setVariable("stage", "run");
97 public void testGetController_availableInExecutionContext_returnFromExecutionContext() {
98 String controllerActor = controllerExecutionBB.getControllerActor(execution, TEST_SCOPE, "", TEST_ACTION);
99 assertEquals(TEST_ACTOR, controllerActor);
103 public void testGetController_soRefDataInExecutionContext_returnFromControllerReference() {
104 when(execution.getVariable(ACTOR_PARAM)).thenReturn("so-ref-data");
105 String controllerActor = controllerExecutionBB.getControllerActor(execution, TEST_SCOPE, "", TEST_ACTION);
106 assertEquals(TEST_CONTROLLER_REFERENCE_ACTOR, controllerActor);
110 public void testGetController_notAvailableInExecutionContext_returnFromCatalogdb() {
111 when(execution.getVariable(ACTOR_PARAM)).thenReturn("");
112 String controllerActor = controllerExecutionBB.getControllerActor(execution, TEST_SCOPE,
113 TEST_RESOURCE_CUSTOMIZATION_UUID, TEST_ACTION);
114 assertEquals("The controller actor should be the same as in the catalogdb", TEST_CATALOGDB_CONTROLLER_ACTOR,
119 public void testGetController_notAvailableInExecutionContextAndSoRefDataInCatalogdb_returnFromControllerReference() {
120 when(execution.getVariable(ACTOR_PARAM)).thenReturn("");
121 when(pnfResourceCustomization.getControllerActor()).thenReturn("SO-REF-DATA");
122 String controllerActor = controllerExecutionBB.getControllerActor(execution, TEST_SCOPE,
123 TEST_RESOURCE_CUSTOMIZATION_UUID, TEST_ACTION);
124 assertEquals("The controller actor should be the same as in the catalogdb", TEST_CONTROLLER_REFERENCE_ACTOR,
129 public void testGetController_notAvailableInExecutionContextAndCatalogdb_returnFromControllerReference() {
130 when(execution.getVariable(ACTOR_PARAM)).thenReturn("");
131 when(pnfResourceCustomization.getControllerActor()).thenReturn("");
133 String controllerActor = controllerExecutionBB.getControllerActor(execution, TEST_SCOPE,
134 TEST_RESOURCE_CUSTOMIZATION_UUID, TEST_ACTION);
135 assertEquals("The controller actor should be the same as in the controller reference table",
136 TEST_CONTROLLER_REFERENCE_ACTOR, controllerActor);
140 public void testGetController_notAvailableInExecutionContextVnfType_returnFromCatalogdb() {
141 when(execution.getVariable(ACTOR_PARAM)).thenReturn("");
143 String expectedVnfControllerActor = "appc";
145 String[] controllerScopeArray = new String[] {"vnf", "vfModule"};
147 for (String controllerScope : controllerScopeArray) {
149 when(vnfResourceCustomization.getControllerActor()).thenReturn(expectedVnfControllerActor);
150 when(client.getVnfResourceCustomizationByModelCustomizationUUID(TEST_RESOURCE_CUSTOMIZATION_UUID))
151 .thenReturn(vnfResourceCustomization);
153 String controllerActor = controllerExecutionBB.getControllerActor(execution, controllerScope,
154 TEST_RESOURCE_CUSTOMIZATION_UUID, TEST_ACTION);
156 assertEquals("The controller actor should be the same as in the catalogdb for scope: " + controllerScope,
157 expectedVnfControllerActor, controllerActor);