860780a2fc47e5ceb953b1247f9a8df78e671121
[so.git] /
1 /*-
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
8  *
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.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.onap.so.bpmn.infrastructure.decisionpoint.impl.camunda;
21
22 import static org.assertj.core.api.Assertions.assertThat;
23 import static org.assertj.core.api.AssertionsForClassTypes.fail;
24 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.MODEL_UUID;
25 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.MSO_REQUEST_ID;
26 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID;
27 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
28 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_BLUEPRINT_NAME;
29 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_BLUEPRINT_VERSION;
30 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_CUSTOMIZATION_UUID;
31 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_INSTANCE_NAME;
32 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.SERVICE_INSTANCE_ID;
33 import com.google.protobuf.Struct;
34 import java.util.List;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers;
38 import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader;
39 import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
40 import org.onap.so.BaseIntegrationTest;
41 import org.onap.so.GrpcNettyServer;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
45 import org.springframework.beans.factory.annotation.Autowired;
46
47 public class ControllerExecutionDETestIT extends BaseIntegrationTest {
48
49     private Logger logger = LoggerFactory.getLogger(this.getClass());
50
51     @Autowired
52     private ControllerExecutionDE controllerExecutionDE;
53
54     @Autowired
55     private GrpcNettyServer grpcNettyServer;
56
57     private GenericVnf genericVnf;
58
59     private static String TEST_MODEL_UUID = "6bc0b04d-1873-4721-b53d-6615225b2a28";
60     private static String TEST_SERVICE_INSTANCE_ID = "test_service_id";
61     private static String TEST_PROCESS_KEY = "processKey1";
62     private static String TEST_MSO_REQUEST_ID = "ff874603-4222-11e7-9252-005056850d2e";
63
64     private static String TEST_CDS_ACTION = "config-assign";
65     private static String TEST_APPC_ACTION = "HealthCheck";
66
67     private static String TEST_PNF_RESOURCE_INSTANCE_NAME = "PNF_demo_resource";
68     private static String TEST_PNF_CORRELATION_ID = "PNFDemo";
69     private static String TEST_PNF_RESOURCE_BLUEPRINT_NAME = "blueprintOnap";
70     private static String TEST_PNF_RESOURCE_BLUEPRINT_VERSION = "1.0.1";
71     private static String TEST_PNF_RESOURCE_CUSTOMIZATION_UUID = "9acb3a83-8a52-412c-9a45-901764938144";
72     private static String TEST_PNF_UUID = "5df8b6de-2083-11e7-93ae-92361f002671";
73
74     @Before
75     public void setUp() {
76         delegateExecution.setVariable(MODEL_UUID, TEST_MODEL_UUID);
77         delegateExecution.setVariable(SERVICE_INSTANCE_ID, TEST_SERVICE_INSTANCE_ID);
78         delegateExecution.setVariable(MSO_REQUEST_ID, TEST_MSO_REQUEST_ID);
79         delegateExecution.setVariable("testProcessKey", TEST_PROCESS_KEY);
80
81         grpcNettyServer.cleanMessage();
82     }
83
84     @Test
85     public void testExecution_cdsConfigAssign_actionExecuted() {
86
87         configureCdsConfigAssign();
88
89         controllerExecutionDE.execute(delegateExecution);
90         List<ExecutionServiceInput> detailedMessages = grpcNettyServer.getDetailedMessages();
91         assertThat(detailedMessages).hasSize(1);
92         try {
93             checkConfigAssign(detailedMessages.get(0));
94         } catch (Exception e) {
95             e.printStackTrace();
96             fail("ConfigAssign request exception", e);
97         }
98     }
99
100     private void configureCdsConfigAssign() {
101         delegateExecution.setVariable("actor", "cds");
102         delegateExecution.setVariable("action", TEST_CDS_ACTION);
103         delegateExecution.setVariable("scope", "pnf");
104
105         delegateExecution.setVariable(PNF_CORRELATION_ID, TEST_PNF_CORRELATION_ID);
106         delegateExecution.setVariable(PNF_UUID, TEST_PNF_UUID);
107         delegateExecution.setVariable(PRC_INSTANCE_NAME, TEST_PNF_RESOURCE_INSTANCE_NAME);
108         delegateExecution.setVariable(PRC_CUSTOMIZATION_UUID, TEST_PNF_RESOURCE_CUSTOMIZATION_UUID);
109         delegateExecution.setVariable(PRC_BLUEPRINT_NAME, TEST_PNF_RESOURCE_BLUEPRINT_NAME);
110         delegateExecution.setVariable(PRC_BLUEPRINT_VERSION, TEST_PNF_RESOURCE_BLUEPRINT_VERSION);
111     }
112
113     private void checkConfigAssign(ExecutionServiceInput executionServiceInput) {
114
115         logger.info("Checking the configAssign request");
116         ActionIdentifiers actionIdentifiers = executionServiceInput.getActionIdentifiers();
117
118         /**
119          * the fields of actionIdentifiers should match the one in the
120          * response/createVcpeResCustServiceSimplifiedTest_catalogdb.json.
121          */
122         assertThat(actionIdentifiers.getBlueprintName()).isEqualTo(TEST_PNF_RESOURCE_BLUEPRINT_NAME);
123         assertThat(actionIdentifiers.getBlueprintVersion()).isEqualTo(TEST_PNF_RESOURCE_BLUEPRINT_VERSION);
124         assertThat(actionIdentifiers.getActionName()).isEqualTo(TEST_CDS_ACTION);
125         assertThat(actionIdentifiers.getMode()).isEqualTo("sync");
126
127         CommonHeader commonHeader = executionServiceInput.getCommonHeader();
128         assertThat(commonHeader.getOriginatorId()).isEqualTo("SO");
129         assertThat(commonHeader.getRequestId()).isEqualTo(TEST_MSO_REQUEST_ID);
130
131         Struct payload = executionServiceInput.getPayload();
132         Struct requeststruct = payload.getFieldsOrThrow("config-assign-request").getStructValue();
133
134         assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue())
135                 .isEqualTo(TEST_PNF_CORRELATION_ID);
136         Struct propertiesStruct = requeststruct.getFieldsOrThrow("config-assign-properties").getStructValue();
137
138         assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).isEqualTo(TEST_PNF_CORRELATION_ID);
139         assertThat(propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue()).isEqualTo(TEST_MODEL_UUID);
140         assertThat(propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue())
141                 .isEqualTo(TEST_PNF_RESOURCE_CUSTOMIZATION_UUID);
142     }
143
144 }