340b2776a40121b7aa6ee1f6b4760b767fdcd6c2
[so.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.service.level;
22
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.ServiceLevelConstants;
32 import org.onap.so.bpmn.infrastructure.service.level.impl.ServiceLevelPreparation;
33 import org.onap.so.client.exception.ExceptionBuilder;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.test.context.ContextConfiguration;
36 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
37 import java.util.Arrays;
38 import java.util.HashMap;
39 import java.util.List;
40 import java.util.Map;
41 import static org.assertj.core.api.Assertions.assertThat;
42
43
44 @RunWith(SpringJUnit4ClassRunner.class)
45 @ContextConfiguration(classes = {ServiceLevelPreparation.class, ExceptionBuilder.class})
46 public class ServiceLevelPreparationTest {
47
48     private static final String TEST_PNF_SCOPE = "pnf";
49     private static final String TEST_PROCESS_KEY = "testProcessKey";
50     private static final String PROCESS_KEY_VALUE = "testProcessKeyValue";
51     private static final String BPMN_REQUEST = "bpmnRequest";
52     private static final String RESOURCE_TYPE = "resourceType";
53     private static final String SERVICE_INSTANCE_ID = "serviceInstanceId";
54     private static final String PNF_NAME = "pnfName";
55     private static final List<String> PNF_HEALTH_CHECK_PARAMS = Arrays.asList(ServiceLevelConstants.SERVICE_INSTANCE_ID,
56             ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST, ServiceLevelConstants.PNF_NAME);
57
58     private Map<String, String> pnfHealthCheckTestParams = new HashMap<>();
59
60     @Autowired
61     private ServiceLevelPreparation serviceLevelPrepare;
62
63     @Autowired
64     private ExceptionBuilder exceptionBuilder;
65
66     @Rule
67     public ExpectedException thrown = ExpectedException.none();
68
69     private DelegateExecution execution = new DelegateExecutionFake();
70     private DelegateExecution invalidExecution = new DelegateExecutionFake();
71
72
73     @Before
74     public void setUpPnfUpgradeTest() {
75         pnfHealthCheckTestParams.put("TEST_SERVICE_MODEL_INFO", "d4c6855e-3be2-5dtu-9390-c999a38829bc");
76         pnfHealthCheckTestParams.put("TEST_SERVICE_INSTANCE_NAME", "test_service_id");
77         pnfHealthCheckTestParams.put("TEST_PNF_CORRELATION_ID", "pnfCorrelationId");
78         pnfHealthCheckTestParams.put("TEST_MODEL_UUID", "6bc0b04d-1873-4721-b53d-6615225b2a28");
79         pnfHealthCheckTestParams.put("TEST_PNF_UUID", "c93g70d9-8de3-57f1-7de1-f5690ac2b005");
80         pnfHealthCheckTestParams.put("TEST_PRC_BLUEPRINT_NAME", "serviceUpgrade");
81         pnfHealthCheckTestParams.put("TEST_PRC_BLUEPRINT_VERSION", "1.0.2");
82         pnfHealthCheckTestParams.put("TEST_PRC_CUSTOMIZATION_UUID", "PRC_customizationUuid");
83         pnfHealthCheckTestParams.put("TEST_RESOURCE_CUSTOMIZATION_UUID_PARAM", "9acb3a83-8a52-412c-9a45-901764938144");
84         pnfHealthCheckTestParams.put("TEST_PRC_INSTANCE_NAME", "Demo_pnf");
85         pnfHealthCheckTestParams.put("TEST_PRC_CONTROLLER_ACTOR", "cds");
86         pnfHealthCheckTestParams.put("TEST_REQUEST_PAYLOAD", "test_payload");
87
88         for (String param : PNF_HEALTH_CHECK_PARAMS) {
89             execution.setVariable(param, pnfHealthCheckTestParams.get("TEST_" + param));
90         }
91         execution.setVariable(RESOURCE_TYPE, TEST_PNF_SCOPE);
92         execution.setVariable(TEST_PROCESS_KEY, PROCESS_KEY_VALUE);
93         execution.setVariable(BPMN_REQUEST, "bpmnRequestValue");
94         execution.setVariable(SERVICE_INSTANCE_ID, "serviceInstanceIdValue");
95         execution.setVariable(PNF_NAME, "PnfDemo");
96
97         invalidExecution.setVariables(execution.getVariables());
98     }
99
100     @Test
101     public void executePnfUpgradeSuccessTest() throws Exception {
102         serviceLevelPrepare.execute(execution);
103         // Expect the pnf health check workflow to be set in to execution if validation is successful
104         assertThat(String.valueOf(execution.getVariable(ServiceLevelConstants.WORKFLOW_TO_INVOKE)))
105                 .isEqualTo("GenericPnfHealthCheck");
106     }
107
108     @Test
109     public void validateFailureParamsForPnfTest() throws Exception {
110         invalidExecution.removeVariable(BPMN_REQUEST);
111         // BPMN exception is thrown in case of validation failure or invalid execution
112         thrown.expect(BpmnError.class);
113         serviceLevelPrepare.validateParamsWithScope(invalidExecution, TEST_PNF_SCOPE, PNF_HEALTH_CHECK_PARAMS);
114     }
115
116     @Test
117     public void invalidScopeExecuteTest() throws Exception {
118         invalidExecution.setVariable(RESOURCE_TYPE, "InvalidResource");
119         // BPMN workflow exception is expected incase of invalid resource type other than pnf/vnf
120         thrown.expect(BpmnError.class);
121         serviceLevelPrepare.execute(invalidExecution);
122     }
123
124     @Test
125     public void invokeServiceLevelPrepareWithoutScope() throws Exception {
126         invalidExecution.removeVariable(RESOURCE_TYPE);
127         thrown.expect(BpmnError.class);
128         serviceLevelPrepare.execute(invalidExecution);
129
130     }
131
132 }
133
134