2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation.
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
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.service.level;
23 import org.camunda.bpm.engine.delegate.BpmnError;
24 import org.camunda.bpm.engine.delegate.DelegateExecution;
25 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
26 import org.junit.Before;
27 import org.junit.Rule;
28 import org.junit.Test;
29 import org.junit.rules.ExpectedException;
30 import org.junit.runner.RunWith;
31 import org.onap.so.bpmn.infrastructure.service.level.impl.ServiceLevelPreparation;
32 import org.onap.so.client.exception.ExceptionBuilder;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.test.context.ContextConfiguration;
35 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
36 import java.util.Arrays;
37 import java.util.HashMap;
38 import java.util.List;
40 import static org.assertj.core.api.Assertions.assertThat;
41 import static org.onap.so.bpmn.infrastructure.service.level.AbstractServiceLevelPreparable.RESOURCE_TYPE;
42 import static org.onap.so.bpmn.infrastructure.service.level.AbstractServiceLevelPreparable.WORKFLOW_TO_INVOKE;
46 @RunWith(SpringJUnit4ClassRunner.class)
47 @ContextConfiguration(classes = {ServiceLevelPreparation.class, ExceptionBuilder.class})
48 public class ServiceLevelPreparationTest {
50 private static final String TEST_PNF_SCOPE = "pnf";
51 private static final String TEST_PROCESS_KEY = "testProcessKey";
52 private static final String PROCESS_KEY_VALUE = "testProcessKeyValue";
53 private static final List<String> PNF_HEALTH_CHECK_PARAMS = Arrays.asList("SERVICE_MODEL_INFO",
54 "SERVICE_INSTANCE_NAME", "PNF_CORRELATION_ID", "MODEL_UUID", "PNF_UUID", "PRC_BLUEPRINT_NAME",
55 "PRC_BLUEPRINT_VERSION", "PRC_CUSTOMIZATION_UUID", "RESOURCE_CUSTOMIZATION_UUID_PARAM", "PRC_INSTANCE_NAME",
56 "PRC_CONTROLLER_ACTOR", "REQUEST_PAYLOAD");
57 private Map<String, String> pnfHealthCheckTestParams = new HashMap<>();
60 private ServiceLevelPreparation serviceLevelPrepare;
63 private ExceptionBuilder exceptionBuilder;
66 public ExpectedException thrown = ExpectedException.none();
68 private DelegateExecution execution = new DelegateExecutionFake();
69 private DelegateExecution invalidExecution = new DelegateExecutionFake();
73 public void setUpPnfUpgradeTest() {
74 pnfHealthCheckTestParams.put("TEST_SERVICE_MODEL_INFO", "d4c6855e-3be2-5dtu-9390-c999a38829bc");
75 pnfHealthCheckTestParams.put("TEST_SERVICE_INSTANCE_NAME", "test_service_id");
76 pnfHealthCheckTestParams.put("TEST_PNF_CORRELATION_ID", "pnfCorrelationId");
77 pnfHealthCheckTestParams.put("TEST_MODEL_UUID", "6bc0b04d-1873-4721-b53d-6615225b2a28");
78 pnfHealthCheckTestParams.put("TEST_PNF_UUID", "c93g70d9-8de3-57f1-7de1-f5690ac2b005");
79 pnfHealthCheckTestParams.put("TEST_PRC_BLUEPRINT_NAME", "serviceUpgrade");
80 pnfHealthCheckTestParams.put("TEST_PRC_BLUEPRINT_VERSION", "1.0.2");
81 pnfHealthCheckTestParams.put("TEST_PRC_CUSTOMIZATION_UUID", "PRC_customizationUuid");
82 pnfHealthCheckTestParams.put("TEST_RESOURCE_CUSTOMIZATION_UUID_PARAM", "9acb3a83-8a52-412c-9a45-901764938144");
83 pnfHealthCheckTestParams.put("TEST_PRC_INSTANCE_NAME", "Demo_pnf");
84 pnfHealthCheckTestParams.put("TEST_PRC_CONTROLLER_ACTOR", "cds");
85 pnfHealthCheckTestParams.put("TEST_REQUEST_PAYLOAD", "test_payload");
87 for (String param : PNF_HEALTH_CHECK_PARAMS) {
88 execution.setVariable(param, pnfHealthCheckTestParams.get("TEST_" + param));
90 execution.setVariable(RESOURCE_TYPE, TEST_PNF_SCOPE);
91 execution.setVariable(TEST_PROCESS_KEY, PROCESS_KEY_VALUE);
93 invalidExecution.setVariables(execution.getVariables());
97 public void executePnfUpgradeSuccessTest() throws Exception {
98 serviceLevelPrepare.execute(execution);
99 // Expect the pnf health check workflow to be set in to execution if validation is successful
100 assertThat(String.valueOf(execution.getVariable(WORKFLOW_TO_INVOKE))).isEqualTo("GenericPnfHealthCheck");
104 public void validateFailureParamsForPnfTest() throws Exception {
105 invalidExecution.removeVariable("PNF_UUID");
106 invalidExecution.setVariable("PRC_BLUEPRINT_NAME", null);
107 // BPMN exception is thrown in case of validation failure or invalid execution
108 thrown.expect(BpmnError.class);
109 serviceLevelPrepare.validateParamsWithScope(invalidExecution, TEST_PNF_SCOPE, PNF_HEALTH_CHECK_PARAMS);
113 public void invalidScopeExecuteTest() throws Exception {
114 invalidExecution.setVariable(RESOURCE_TYPE, "InvalidResource");
115 // BPMN workflow exception is expected incase of invalid resource type other than pnf/vnf
116 thrown.expect(BpmnError.class);
117 serviceLevelPrepare.execute(invalidExecution);
121 public void invokeServiceLevelPrepareWithoutScope() throws Exception {
122 invalidExecution.removeVariable(RESOURCE_TYPE);
123 thrown.expect(BpmnError.class);
124 serviceLevelPrepare.execute(invalidExecution);