2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 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=========================================================
19 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
21 import org.camunda.bpm.engine.delegate.DelegateExecution;
22 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
23 import org.junit.ClassRule;
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.junit.runners.Parameterized;
28 import org.mockito.InjectMocks;
29 import org.mockito.Mock;
30 import org.onap.so.bpmn.BaseTaskTest;
31 import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext;
32 import org.onap.so.client.cds.AbstractCDSProcessingBBUtils;
33 import org.onap.so.client.cds.GeneratePayloadForCds;
34 import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
35 import org.springframework.test.context.junit4.rules.SpringClassRule;
36 import org.springframework.test.context.junit4.rules.SpringMethodRule;
37 import java.util.Arrays;
38 import java.util.Collection;
39 import static org.assertj.core.api.Assertions.assertThat;
40 import static org.assertj.core.api.Assertions.fail;
41 import static org.junit.Assert.assertEquals;
42 import static org.mockito.Mockito.doNothing;
43 import static org.mockito.Mockito.doReturn;
44 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.*;
46 @RunWith(Parameterized.class)
47 public class GenericPnfCDSProcessingDETest extends BaseTaskTest {
50 public static final SpringClassRule springClassRule = new SpringClassRule();
53 public final SpringMethodRule smr = new SpringMethodRule();
56 private GenericPnfCDSProcessingDE controllerRunnable;
59 private GeneratePayloadForCds generatePayloadForCds;
62 private AbstractCDSProcessingBBUtils cdsDispather;
64 private static final String PRECHECK_ACTION = "precheck";
65 private static final String DOWNLOAD_ACTION = "downloadNESw";
66 private static final String ACTIVATE_ACTION = "activateNESw";
67 private static final String POSTCHECK_ACTION = "postcheck";
69 private String description;
70 private String action;
72 private String expectedJson;
74 public GenericPnfCDSProcessingDETest(String desc, String action, String scope, String expectedJson) {
75 this.description = desc;
78 this.expectedJson = expectedJson;
82 @Parameterized.Parameters(name = "index {0}")
83 public static Collection<String[]> data() {
84 return Arrays.asList(new String[][] {
85 {"Test JSON for action:" + PRECHECK_ACTION + " scope:pnf", PRECHECK_ACTION, "pnf",
86 buildExpectedJson(PRECHECK_ACTION, "pnf")},
87 {"Test JSON for action:" + DOWNLOAD_ACTION + " scope:pnf", DOWNLOAD_ACTION, "pnf",
88 buildExpectedJson(DOWNLOAD_ACTION, "pnf")},
89 {"Test JSON for action:" + ACTIVATE_ACTION + " scope:pnf", ACTIVATE_ACTION, "pnf",
90 buildExpectedJson(ACTIVATE_ACTION, "pnf")},
91 {"Test JSON for action:" + POSTCHECK_ACTION + " scope:pnf", POSTCHECK_ACTION, "pnf",
92 buildExpectedJson(POSTCHECK_ACTION, "pnf")},});
95 private static String buildExpectedJson(String action, String scope) {
96 return "{\"" + action + "-request\":" + "{\"" + action + "-" + "properties\":"
97 + "{\"service-instance-id\":\"test_service_id\","
98 + "\"pnf-customization-uuid\":\"9acb3a83-8a52-412c-9a45-901764938144\","
99 + "\"pnf-id\":\"5df8b6de-2083-11e7-93ae-92361f002671\","
100 + "\"target-software-version\":\"demo-sw-ver2.0.0\"," + "\"pnf-name\":\"PNFDemo\","
101 + "\"service-model-uuid\":\"6bc0b04d-1873-4721-b53d-6615225b2a28\"}," + "\"resolution-key\":\"PNFDemo\""
105 private DelegateExecution execution = new DelegateExecutionFake();
108 public void testExecution_validPnf_action_executionObjectCreated() {
112 ControllerContext controllerContext = new ControllerContext();
113 controllerContext.setExecution(execution);
114 controllerContext.setControllerActor("cds");
115 controllerContext.setControllerAction(this.action);
116 controllerContext.setControllerScope(this.scope);
117 AbstractCDSPropertiesBean bean = new AbstractCDSPropertiesBean();
118 doNothing().when(cdsDispather).constructExecutionServiceInputObject(execution);
119 doNothing().when(cdsDispather).sendRequestToCDSClient(execution);
120 doReturn(bean).when(generatePayloadForCds).buildCdsPropertiesBean(execution);
123 Boolean isUnderstandable = controllerRunnable.understand(controllerContext);
124 Boolean isReady = controllerRunnable.ready(controllerContext);
125 controllerRunnable.prepare(controllerContext);
126 controllerRunnable.run(controllerContext);
129 assertEquals(isUnderstandable, true);
130 assertEquals(isReady, true);
131 Object executionObject = execution.getVariable(EXECUTION_OBJECT);
132 assertThat(executionObject).isNotNull();
133 assertThat(executionObject).isInstanceOf(AbstractCDSPropertiesBean.class);
134 } catch (Exception e) {
136 fail("Exception thrown" + e.getMessage());