2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.decisionpoint.impl.camunda.controller.sdnc;
23 import com.fasterxml.jackson.core.JsonProcessingException;
24 import org.camunda.bpm.engine.delegate.DelegateExecution;
25 import org.junit.Before;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28 import org.junit.runner.RunWith;
29 import org.junit.Test;
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.fail;
32 import static org.mockito.Mockito.when;
33 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.REQUEST_PAYLOAD;
34 import org.springframework.boot.test.mock.mockito.MockBean;
35 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
36 import org.onap.so.bpmn.infrastructure.decisionpoint.impl.camunda.controller.common.SoPropertyConstants;
37 import org.onap.so.client.sdnc.lcm.beans.payload.*;
39 @RunWith(SpringJUnit4ClassRunner.class)
40 public class SDNCLcmPayloadBuilderTest {
41 private static Logger logger = LoggerFactory.getLogger(SDNCLcmPayloadBuilderTest.class);
43 protected static String payload = "{" + "\"ipaddressV4Oam\": \"192.168.1.10\"," + "\"oldSwVersion\": \"v1\","
44 + "\"preCheckRuleName\": \"r101\"," + "\"preCheckAdditionalData\": \"{}\","
45 + "\"preCheckPlaybook\": \"precheck_playbook\"," + "\"swToBeDownloaded\": \"[{"
46 + "\\\"swLocation\\\": \\\"http://192.168.1.20/test.zip\\\"," + "\\\"swFileSize\\\": 123456,"
47 + "\\\"swFileCompression\\\": \\\"ZIP\\\"," + "\\\"swFileFormat\\\": \\\"binary\\\"}]\","
48 + "\"downloadNESwPlaybook\": \"downloadnesw_playbook\","
49 + "\"activateNESwPlaybook\": \"activatenesw_playbook\"," + "\"postCheckRuleName\": \"r102\","
50 + "\"postCheckAdditionalData\": \"{}\"," + "\"postCheckPlaybook\": \"postcheck_playbook\"" + "}";
51 protected String targetSoftwareVersion = "v2";
54 private DelegateExecution execution;
56 public static String getRequestPayload() {
62 when(execution.getVariable(REQUEST_PAYLOAD)).thenReturn(payload);
63 when(execution.getVariable(SoPropertyConstants.TARGET_SOFTWARE_VERSION)).thenReturn(targetSoftwareVersion);
68 public final void testBuildActivateNESwPayload() {
69 String expectedPayload = "{" + "\"ipaddress-v4-oam\":\"192.168.1.10\","
70 + "\"playbook-name\":\"activatenesw_playbook\"," + "\"swVersionToBeActivated\":\"v2\"" + "}";
72 ActivateNESwPayload activateNESwPayload = SDNCLcmPayloadBuilder.buildActivateNESwPayload(execution);
74 String payload = SDNCLcmPayloadBuilder.convertToSting(activateNESwPayload);
75 logger.debug("ActivateNESwPayload:\n" + payload);
77 assertEquals(expectedPayload, payload);
78 } catch (JsonProcessingException e) {
79 fail("Convert ActivateNESwPayload to String error: " + e.toString());
84 public final void testBuildDownloadNESwPayload() {
85 String expectedSwToBeDownloadedElement = "{" + "\"swLocation\":\"http://192.168.1.20/test.zip\","
86 + "\"swFileSize\":123456," + "\"swFileCompression\":\"ZIP\"," + "\"swFileFormat\":\"binary\"" + "}";
87 String expectedPayload =
88 "{" + "\"ipaddress-v4-oam\":\"192.168.1.10\"," + "\"playbook-name\":\"downloadnesw_playbook\","
89 + "\"swToBeDownloaded\":[" + expectedSwToBeDownloadedElement + "]" + "}";
91 DownloadNESwPayload downloadNESwPayload = SDNCLcmPayloadBuilder.buildDownloadNESwPayload(execution);
93 String payload = SDNCLcmPayloadBuilder.convertToSting(downloadNESwPayload);
94 logger.debug("DownloadNESwPayload:\n" + payload);
96 assertEquals(expectedPayload, payload);
97 } catch (JsonProcessingException e) {
98 fail("Convert DownloadNESwPayload to String error: " + e.toString());
103 public final void testBuildUpgradePostCheckPayload() {
104 String expectedPayload = "{" + "\"ipaddress-v4-oam\":\"192.168.1.10\","
105 + "\"playbook-name\":\"postcheck_playbook\"," + "\"oldSwVersion\":\"v1\","
106 + "\"targetSwVersion\":\"v2\"," + "\"ruleName\":\"r102\"," + "\"additionalData\":\"{}\"" + "}";
108 UpgradePostCheckPayload upgradePostCheckPayload = SDNCLcmPayloadBuilder.buildUpgradePostCheckPayload(execution);
110 String payload = SDNCLcmPayloadBuilder.convertToSting(upgradePostCheckPayload);
111 logger.debug("UpgradePostCheckPayload:\n" + payload);
113 assertEquals(expectedPayload, payload);
114 } catch (JsonProcessingException e) {
115 fail("Convert UpgradePostCheckPayload to String error: " + e.toString());
120 public final void testBuildUpgradePreCheckPayload() {
121 String expectedPayload = "{" + "\"ipaddress-v4-oam\":\"192.168.1.10\","
122 + "\"playbook-name\":\"precheck_playbook\"," + "\"oldSwVersion\":\"v1\","
123 + "\"targetSwVersion\":\"v2\"," + "\"ruleName\":\"r101\"," + "\"additionalData\":\"{}\"" + "}";
125 UpgradePreCheckPayload upgradePreCheckPayload = SDNCLcmPayloadBuilder.buildUpgradePreCheckPayload(execution);
127 String payload = SDNCLcmPayloadBuilder.convertToSting(upgradePreCheckPayload);
128 logger.debug("UpgradePreCheckPayload:\n" + payload);
130 assertEquals(expectedPayload, payload);
131 } catch (JsonProcessingException e) {
132 fail("Convert UpgradePreCheckPayload to String error: " + e.toString());