2 * ============LICENSE_START======================================================= Copyright (C) 2019 Nordix
3 * Foundation. ================================================================================ Licensed under the
4 * Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may
5 * obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
9 * either express or implied. See the License for the specific language governing permissions and limitations under the
12 * SPDX-License-Identifier: Apache-2.0 ============LICENSE_END=========================================================
15 package org.onap.so.bpmn.infrastructure.pnf.delegate;
17 import static org.assertj.core.api.Assertions.assertThat;
18 import static org.assertj.core.api.Assertions.assertThatThrownBy;
19 import static org.assertj.core.api.Assertions.fail;
20 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.EXECUTION_OBJECT;
21 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.MODEL_UUID;
22 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.MSO_REQUEST_ID;
23 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID;
24 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
25 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_BLUEPRINT_NAME;
26 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_BLUEPRINT_VERSION;
27 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_CUSTOMIZATION_UUID;
28 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_INSTANCE_NAME;
29 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.SERVICE_INSTANCE_ID;
30 import com.fasterxml.jackson.databind.JsonNode;
31 import com.fasterxml.jackson.databind.ObjectMapper;
32 import java.io.IOException;
33 import org.camunda.bpm.engine.delegate.BpmnError;
34 import org.camunda.bpm.engine.delegate.DelegateExecution;
35 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 import org.onap.so.bpmn.core.WorkflowException;
40 import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
41 import org.onap.so.client.cds.beans.ConfigAssignPropertiesForPnf;
42 import org.onap.so.client.cds.beans.ConfigAssignRequestPnf;
43 import org.onap.so.client.exception.ExceptionBuilder;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.test.context.ContextConfiguration;
46 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
48 @RunWith(SpringJUnit4ClassRunner.class)
49 @ContextConfiguration(classes = {ExceptionBuilder.class, PrepareConfigAssignDelegate.class})
50 public class PrepareConfigAssignDelegateTest {
52 private static String TEST_MODEL_UUID = "6bc0b04d-1873-4721-b53d-6615225b2a28";
53 private static String TEST_SERVICE_INSTANCE_ID = "test_service_id";
54 private static String TEST_PROCESS_KEY = "processKey1";
55 private static String TEST_PNF_RESOURCE_INSTANCE_NAME = "PNF_demo_resource";
56 private static String TEST_PNF_CORRELATION_ID = "PNFDemo";
57 private static String TEST_PNF_RESOURCE_BLUEPRINT_NAME = "blueprintOnap";
58 private static String TEST_PNF_RESOURCE_BLUEPRINT_VERSION = "1.0.1";
59 private static String TEST_PNF_RESOURCE_CUSTOMIZATION_UUID = "9acb3a83-8a52-412c-9a45-901764938144";
60 private static String TEST_MSO_REQUEST_ID = "ff874603-4222-11e7-9252-005056850d2e";
61 private static String TEST_PNF_UUID = "5df8b6de-2083-11e7-93ae-92361f002671";
64 private PrepareConfigAssignDelegate prepareConfigAssignDelegate;
66 private DelegateExecution execution = new DelegateExecutionFake();
70 execution.setVariable("testProcessKey", TEST_PROCESS_KEY);
71 execution.setVariable(PNF_CORRELATION_ID, TEST_PNF_CORRELATION_ID);
72 execution.setVariable(MODEL_UUID, TEST_MODEL_UUID);
73 execution.setVariable(SERVICE_INSTANCE_ID, TEST_SERVICE_INSTANCE_ID);
74 execution.setVariable(MSO_REQUEST_ID, TEST_MSO_REQUEST_ID);
75 execution.setVariable(PNF_UUID, TEST_PNF_UUID);
76 execution.setVariable(PRC_INSTANCE_NAME, TEST_PNF_RESOURCE_INSTANCE_NAME);
77 execution.setVariable(PRC_CUSTOMIZATION_UUID, TEST_PNF_RESOURCE_CUSTOMIZATION_UUID);
78 execution.setVariable(PRC_BLUEPRINT_NAME, TEST_PNF_RESOURCE_BLUEPRINT_NAME);
79 execution.setVariable(PRC_BLUEPRINT_VERSION, TEST_PNF_RESOURCE_BLUEPRINT_VERSION);
83 public void testExecution_validPnf_executionObjectCreated() {
85 prepareConfigAssignDelegate.execute(execution);
86 Object executionObject = execution.getVariable(EXECUTION_OBJECT);
87 assertThat(executionObject).isNotNull();
88 assertThat(executionObject).isInstanceOf(AbstractCDSPropertiesBean.class);
89 checkCDSPropertiesBean((AbstractCDSPropertiesBean) executionObject);
90 } catch (Exception e) {
92 fail("Exception thrown" + e.getMessage());
96 private void checkCDSPropertiesBean(AbstractCDSPropertiesBean executionObject) {
97 assertThat(executionObject.getBlueprintName()).matches(TEST_PNF_RESOURCE_BLUEPRINT_NAME);
98 assertThat(executionObject.getBlueprintVersion()).matches(TEST_PNF_RESOURCE_BLUEPRINT_VERSION);
99 assertThat(executionObject.getRequestId()).matches(TEST_MSO_REQUEST_ID);
100 assertThat(executionObject.getSubRequestId()).matches(TEST_PNF_UUID);
101 assertThat(executionObject.getMode()).matches("sync");
102 assertThat(executionObject.getActionName()).matches("config-assign");
103 assertThat(executionObject.getOriginatorId()).matches("SO");
105 assertThat(executionObject.getRequestObject()).isNotNull();
106 String requestObject = executionObject.getRequestObject();
108 checkRequestJson(requestObject);
111 private void checkRequestJson(String requestObject) {
113 ObjectMapper mapper = new ObjectMapper();
114 JsonNode tree = mapper.readTree(requestObject);
115 ConfigAssignRequestPnf configAssignRequestPnf =
116 mapper.treeToValue(tree.at("/config-assign-request"), ConfigAssignRequestPnf.class);
117 assertThat(configAssignRequestPnf.getResolutionKey()).matches(TEST_PNF_CORRELATION_ID);
119 ConfigAssignPropertiesForPnf properties = configAssignRequestPnf.getConfigAssignPropertiesForPnf();
120 assertThat(properties.getServiceInstanceId()).matches(TEST_SERVICE_INSTANCE_ID);
121 assertThat(properties.getPnfName()).matches(TEST_PNF_CORRELATION_ID);
122 assertThat(properties.getPnfId()).matches(TEST_PNF_UUID);
123 assertThat(properties.getPnfCustomizationUuid()).matches(TEST_PNF_RESOURCE_CUSTOMIZATION_UUID);
124 assertThat(properties.getServiceModelUuid()).matches(TEST_MODEL_UUID);
125 } catch (IOException e) {
127 fail("Check request body is json message" + e.getMessage());