275cd18f0b18f70bcae080e03d887165837660c5
[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 com.google.protobuf.Struct;
23 import org.junit.Before;
24 import org.junit.ClassRule;
25 import org.junit.Rule;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.junit.runners.Parameterized;
29 import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers;
30 import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader;
31 import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
32 import org.onap.so.BaseIntegrationTest;
33 import org.onap.so.GrpcNettyServer;
34 import org.onap.so.client.aai.AAIVersion;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.test.context.junit4.rules.SpringClassRule;
39 import org.springframework.test.context.junit4.rules.SpringMethodRule;
40 import java.util.Arrays;
41 import java.util.Collection;
42 import java.util.List;
43 import static com.github.tomakehurst.wiremock.client.WireMock.*;
44 import static org.assertj.core.api.Assertions.assertThat;
45 import static org.assertj.core.api.AssertionsForClassTypes.fail;
46 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.*;
47
48 @RunWith(Parameterized.class)
49 public class ControllerExecutionDETestIT extends BaseIntegrationTest {
50
51     private Logger logger = LoggerFactory.getLogger(this.getClass());
52
53     @ClassRule
54     public static final SpringClassRule springClassRule = new SpringClassRule();
55
56     @Rule
57     public final SpringMethodRule smr = new SpringMethodRule();
58
59     private static final String DOWNLOAD_ACTION = "downloadNeSw";
60     private static final String ACTIVATE_ACTION = "activateNeSw";
61     private static final String PRECHECK_ACTION = "precheck";
62     private static final String POSTCHECK_ACTION = "postcheck";
63     private static final String ASSIGN_ACTION = "config-assign";
64     private static final String DEPLOY_ACTION = "config-deploy";
65     private static final String CDS_ACTOR = "cds";
66
67     @Autowired
68     private ControllerExecutionDE controllerExecutionDE;
69
70     @Autowired
71     private GrpcNettyServer grpcNettyServer;
72
73     private static String TEST_MODEL_UUID = "6bc0b04d-1873-4721-b53d-6615225b2a28";
74     private static String TEST_SERVICE_INSTANCE_ID = "test_service_id";
75     private static String TEST_PROCESS_KEY = "processKey1";
76     private static String TEST_MSO_REQUEST_ID = "ff874603-4222-11e7-9252-005056850d2e";
77
78     private static final AAIVersion VERSION = AAIVersion.LATEST;
79
80     private static String TEST_PNF_RESOURCE_INSTANCE_NAME = "PNF_demo_resource";
81     private static String TEST_PNF_CORRELATION_ID = "PNFDemo";
82     private static String TEST_PNF_RESOURCE_BLUEPRINT_NAME = "blueprintOnap";
83     private static String TEST_PNF_RESOURCE_BLUEPRINT_VERSION = "1.0.1";
84     private static String TEST_PNF_RESOURCE_CUSTOMIZATION_UUID = "9acb3a83-8a52-412c-9a45-901764938144";
85     private static String TEST_PNF_UUID = "5df8b6de-2083-11e7-93ae-92361f002671";
86     private static String TEST_SOFTWARE_VERSION = "demo-sw-ver2.0.0";
87
88     private String description;
89     private String action;
90     private String scope;
91
92     public ControllerExecutionDETestIT(String desc, String action, String scope) {
93         this.description = desc;
94         this.action = action;
95         this.scope = scope;
96
97     }
98
99     @Parameterized.Parameters(name = "index {0}")
100     public static Collection<String[]> data() {
101         return Arrays.asList(
102                 new String[][] {{"Test JSON for action:" + ACTIVATE_ACTION + " scope:pnf", ACTIVATE_ACTION, "pnf"},
103                         {"Test JSON for action:" + DOWNLOAD_ACTION + " scope:pnf", DOWNLOAD_ACTION, "pnf"},
104                         {"Test JSON for action:" + ASSIGN_ACTION + " scope:pnf", ASSIGN_ACTION, "pnf"},
105                         {"Test JSON for action:" + DEPLOY_ACTION + " scope:pnf", DEPLOY_ACTION, "pnf"},
106                         {"Test JSON for action:" + PRECHECK_ACTION + " scope:pnf", PRECHECK_ACTION, "pnf"},
107                         {"Test JSON for action:" + POSTCHECK_ACTION + " scope:pnf", POSTCHECK_ACTION, "pnf"}});
108     }
109
110     @Before
111     public void setUp() {
112         delegateExecution.setVariable("testProcessKey", TEST_PROCESS_KEY);
113         delegateExecution.setVariable(PNF_CORRELATION_ID, TEST_PNF_CORRELATION_ID);
114         delegateExecution.setVariable(MODEL_UUID, TEST_MODEL_UUID);
115         delegateExecution.setVariable(SERVICE_INSTANCE_ID, TEST_SERVICE_INSTANCE_ID);
116         delegateExecution.setVariable(MSO_REQUEST_ID, TEST_MSO_REQUEST_ID);
117         delegateExecution.setVariable(PNF_UUID, TEST_PNF_UUID);
118         delegateExecution.setVariable(PRC_INSTANCE_NAME, TEST_PNF_RESOURCE_INSTANCE_NAME);
119         delegateExecution.setVariable(PRC_CUSTOMIZATION_UUID, TEST_PNF_RESOURCE_CUSTOMIZATION_UUID);
120         delegateExecution.setVariable(PRC_BLUEPRINT_NAME, TEST_PNF_RESOURCE_BLUEPRINT_NAME);
121         delegateExecution.setVariable(PRC_BLUEPRINT_VERSION, TEST_PNF_RESOURCE_BLUEPRINT_VERSION);
122         delegateExecution.setVariable("targetSoftwareVersion", TEST_SOFTWARE_VERSION);
123
124         delegateExecution.setVariable("actor", CDS_ACTOR);
125         delegateExecution.setVariable("action", this.action);
126         delegateExecution.setVariable("scope", this.scope);
127
128
129         /**
130          * Get the PNF entry from AAI.
131          */
132         if (action.equalsIgnoreCase(DEPLOY_ACTION)) {
133             final String aaiPnfEntry = "{  \n" + "   \"pnf-name\":\"PNFDemo\",\n" + "   \"pnf-id\":\"testtest\",\n"
134                     + "   \"in-maint\":true,\n" + "   \"resource-version\":\"1541720264047\",\n"
135                     + "   \"ipaddress-v4-oam\":\"1.1.1.1\",\n" + "   \"ipaddress-v6-oam\":\"::/128\"\n" + "}";
136             wireMockServer.stubFor(
137                     get(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo")).willReturn(okJson(aaiPnfEntry)));
138         }
139
140         grpcNettyServer.cleanMessage();
141     }
142
143     @Test
144     public void testExecution_cds_actions() {
145
146         controllerExecutionDE.execute(delegateExecution);
147         List<ExecutionServiceInput> detailedMessages = grpcNettyServer.getDetailedMessages();
148         assertThat(detailedMessages).hasSize(1);
149         try {
150             verifyRequestContentForAction(detailedMessages.get(0));
151         } catch (Exception e) {
152             e.printStackTrace();
153             fail(this.action + " request exception", e);
154         }
155     }
156
157     private void verifyRequestContentForAction(ExecutionServiceInput executionServiceInput) {
158
159         logger.info("Checking the " + this.action + " request");
160         ActionIdentifiers actionIdentifiers = executionServiceInput.getActionIdentifiers();
161
162         assertThat(actionIdentifiers.getBlueprintName()).isEqualTo(TEST_PNF_RESOURCE_BLUEPRINT_NAME);
163         assertThat(actionIdentifiers.getBlueprintVersion()).isEqualTo(TEST_PNF_RESOURCE_BLUEPRINT_VERSION);
164         assertThat(actionIdentifiers.getActionName()).isEqualTo(this.action);
165
166         CommonHeader commonHeader = executionServiceInput.getCommonHeader();
167         assertThat(commonHeader.getOriginatorId()).isEqualTo("SO");
168         assertThat(commonHeader.getRequestId()).isEqualTo(TEST_MSO_REQUEST_ID);
169
170         Struct payload = executionServiceInput.getPayload();
171         Struct requeststruct = payload.getFieldsOrThrow(this.action + "-request").getStructValue();
172
173         assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue())
174                 .isEqualTo(TEST_PNF_CORRELATION_ID);
175
176         Struct propertiesStruct = requeststruct.getFieldsOrThrow(this.action + "-properties").getStructValue();
177         assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).isEqualTo(TEST_PNF_CORRELATION_ID);
178         assertThat(propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue()).isEqualTo(TEST_MODEL_UUID);
179         assertThat(propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue())
180                 .isEqualTo(TEST_PNF_RESOURCE_CUSTOMIZATION_UUID);
181         if (action.equalsIgnoreCase(DEPLOY_ACTION)) {
182             assertThat(actionIdentifiers.getMode()).isEqualTo("async");
183             assertThat(propertiesStruct.getFieldsOrThrow("pnf-ipv4-address").getStringValue()).isEqualTo("1.1.1.1");
184             assertThat(propertiesStruct.getFieldsOrThrow("pnf-ipv6-address").getStringValue()).isEqualTo("::/128");
185         } else if (!action.equalsIgnoreCase(ASSIGN_ACTION)) {
186             assertThat(actionIdentifiers.getMode()).isEqualTo("sync");
187             assertThat(propertiesStruct.getFieldsOrThrow("target-software-version").getStringValue())
188                     .isEqualTo(TEST_SOFTWARE_VERSION);
189         } else {
190             assertThat(actionIdentifiers.getMode()).isEqualTo("sync");
191         }
192     }
193
194 }