aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/test')
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java69
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/sdnc/SDNCLcmPayloadBuilderTest.java135
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/sdnc/SdncControllerDETest.java4
3 files changed, 199 insertions, 9 deletions
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java
index 5bd4df74bb..9adae88a5a 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java
@@ -24,10 +24,15 @@ package org.onap.so.bpmn.infrastructure.adapter.network.tasks;
import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import javax.xml.bind.JAXBException;
import org.camunda.bpm.engine.delegate.BpmnError;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
+import org.glassfish.jersey.message.internal.OutboundJaxrsResponse;
+import org.glassfish.jersey.message.internal.OutboundMessageContext;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -39,8 +44,8 @@ import org.onap.so.adapters.nwrest.DeleteNetworkResponse;
import org.onap.so.adapters.nwrest.UpdateNetworkError;
import org.onap.so.adapters.nwrest.UpdateNetworkRequest;
import org.onap.so.adapters.nwrest.UpdateNetworkResponse;
-import org.onap.so.bpmn.BaseTaskTest;
import org.onap.so.client.exception.ExceptionBuilder;
+import org.onap.so.client.orchestration.NetworkAdapterResources;
import org.onap.so.utils.Components;
import org.onap.logging.filter.base.ONAPComponents;
import static org.junit.Assert.assertTrue;
@@ -54,13 +59,19 @@ import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
-public class NetworkAdapterRestV1Test extends BaseTaskTest {
+public class NetworkAdapterRestV1Test {
- @InjectMocks
- NetworkAdapterRestV1 networkAdapterRestV1Tasks = new NetworkAdapterRestV1();
@Mock
- ExceptionBuilder exceptionBuilder = new ExceptionBuilder();
+ private ExceptionBuilder exceptionBuilder;
+ @Mock
+ private NetworkAdapterResources networkAdapterResources;
+ @InjectMocks
+ private NetworkAdapterRestV1 networkAdapterRestV1Tasks;
+
+ private DelegateExecution delegateExecution;
private static final String CREATE_NETWORK_RESPONSE = "createNetworkResponse";
private static final String DELETE_NETWORK_RESPONSE = "deleteNetworkResponse";
@@ -73,6 +84,7 @@ public class NetworkAdapterRestV1Test extends BaseTaskTest {
@Before
public void setup() {
+ initMocks(this);
delegateExecution = new DelegateExecutionFake();
}
@@ -187,6 +199,53 @@ public class NetworkAdapterRestV1Test extends BaseTaskTest {
}
}
+ @Test
+ public void callNetworkAdapter_CreateNetworkRequestSuccess() throws Exception {
+ // given
+ String messageId = "createNetReqMessageId";
+ CreateNetworkRequest createNetworkRequest = new CreateNetworkRequest();
+ createNetworkRequest.setMessageId(messageId);
+ delegateExecution.setVariable("networkAdapterRequest", createNetworkRequest);
+ Status status = Status.OK;
+ String responseEntity = "createNetworkResponse";
+ Optional<Response> response = Optional.of(createResponse(status, responseEntity));
+ when(networkAdapterResources.createNetworkAsync(createNetworkRequest)).thenReturn(response);
+ // when
+ networkAdapterRestV1Tasks.callNetworkAdapter(delegateExecution);
+ // then
+ verifyExecutionContent(status, responseEntity, messageId);
+ }
+
+ @Test
+ public void callNetworkAdapter_DeleteNetworkRequestSuccess() throws Exception {
+ // given
+ String messageId = "DeleteNetReqMessageId";
+ DeleteNetworkRequest deleteNetworkRequest = new DeleteNetworkRequest();
+ deleteNetworkRequest.setMessageId(messageId);
+ delegateExecution.setVariable("networkAdapterRequest", deleteNetworkRequest);
+ Status status = Status.OK;
+ String responseEntity = "createNetworkResponse";
+ Optional<Response> response = Optional.of(createResponse(status, responseEntity));
+ when(networkAdapterResources.deleteNetworkAsync(deleteNetworkRequest)).thenReturn(response);
+ // when
+ networkAdapterRestV1Tasks.callNetworkAdapter(delegateExecution);
+ // then
+ verifyExecutionContent(status, responseEntity, messageId);
+ }
+
+ private void verifyExecutionContent(Status status, String responseEntity, String messageId) {
+ assertEquals(delegateExecution.getVariable("NETWORKREST_networkAdapterStatusCode"),
+ Integer.toString(status.getStatusCode()));
+ assertEquals(delegateExecution.getVariable("NETWORKREST_networkAdapterResponse"), responseEntity);
+ assertEquals(delegateExecution.getVariable("NetworkAResponse_CORRELATOR"), messageId);
+ }
+
+ private Response createResponse(Status status, String responseEntity) {
+ OutboundMessageContext outboundMessageContext = new OutboundMessageContext();
+ outboundMessageContext.setEntity(responseEntity);
+ return new OutboundJaxrsResponse(status, outboundMessageContext);
+ }
+
private String createNetworkResponse(String networkResponseType, String networkId) {
return "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><" + networkResponseType + "><networkId>"
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/sdnc/SDNCLcmPayloadBuilderTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/sdnc/SDNCLcmPayloadBuilderTest.java
new file mode 100644
index 0000000000..61f2ee3432
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/sdnc/SDNCLcmPayloadBuilderTest.java
@@ -0,0 +1,135 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure.decisionpoint.impl.camunda.controller.sdnc;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.junit.Before;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.junit.runner.RunWith;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.when;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.REQUEST_PAYLOAD;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.onap.so.bpmn.infrastructure.decisionpoint.impl.camunda.controller.common.SoPropertyConstants;
+import org.onap.so.client.sdnc.lcm.beans.payload.*;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+public class SDNCLcmPayloadBuilderTest {
+ private static Logger logger = LoggerFactory.getLogger(SDNCLcmPayloadBuilderTest.class);
+
+ protected static String payload = "{" + "\"ipaddressV4Oam\": \"192.168.1.10\"," + "\"oldSwVersion\": \"v1\","
+ + "\"preCheckRuleName\": \"r101\"," + "\"preCheckAdditionalData\": \"{}\","
+ + "\"preCheckPlaybook\": \"precheck_playbook\"," + "\"swToBeDownloaded\": \"[{"
+ + "\\\"swLocation\\\": \\\"http://192.168.1.20/test.zip\\\"," + "\\\"swFileSize\\\": 123456,"
+ + "\\\"swFileCompression\\\": \\\"ZIP\\\"," + "\\\"swFileFormat\\\": \\\"binary\\\"}]\","
+ + "\"downloadNESwPlaybook\": \"downloadnesw_playbook\","
+ + "\"activateNESwPlaybook\": \"activatenesw_playbook\"," + "\"postCheckRuleName\": \"r102\","
+ + "\"postCheckAdditionalData\": \"{}\"," + "\"postCheckPlaybook\": \"postcheck_playbook\"" + "}";
+ protected String targetSoftwareVersion = "v2";
+
+ @MockBean
+ private DelegateExecution execution;
+
+ public static String getRequestPayload() {
+ return payload;
+ }
+
+ @Before
+ public void setUp() {
+ when(execution.getVariable(REQUEST_PAYLOAD)).thenReturn(payload);
+ when(execution.getVariable(SoPropertyConstants.TARGET_SOFTWARE_VERSION)).thenReturn(targetSoftwareVersion);
+ }
+
+
+ @Test
+ public final void testBuildActivateNESwPayload() {
+ String expectedPayload = "{" + "\"ipaddress-v4-oam\":\"192.168.1.10\","
+ + "\"playbook-name\":\"activatenesw_playbook\"," + "\"swVersionToBeActivated\":\"v2\"" + "}";
+
+ ActivateNESwPayload activateNESwPayload = SDNCLcmPayloadBuilder.buildActivateNESwPayload(execution);
+ try {
+ String payload = SDNCLcmPayloadBuilder.convertToSting(activateNESwPayload);
+ logger.debug("ActivateNESwPayload:\n" + payload);
+
+ assertEquals(expectedPayload, payload);
+ } catch (JsonProcessingException e) {
+ fail("Convert ActivateNESwPayload to String error: " + e.toString());
+ }
+ }
+
+ @Test
+ public final void testBuildDownloadNESwPayload() {
+ String expectedSwToBeDownloadedElement = "{" + "\"swLocation\":\"http://192.168.1.20/test.zip\","
+ + "\"swFileSize\":123456," + "\"swFileCompression\":\"ZIP\"," + "\"swFileFormat\":\"binary\"" + "}";
+ String expectedPayload =
+ "{" + "\"ipaddress-v4-oam\":\"192.168.1.10\"," + "\"playbook-name\":\"downloadnesw_playbook\","
+ + "\"swToBeDownloaded\":[" + expectedSwToBeDownloadedElement + "]" + "}";
+
+ DownloadNESwPayload downloadNESwPayload = SDNCLcmPayloadBuilder.buildDownloadNESwPayload(execution);
+ try {
+ String payload = SDNCLcmPayloadBuilder.convertToSting(downloadNESwPayload);
+ logger.debug("DownloadNESwPayload:\n" + payload);
+
+ assertEquals(expectedPayload, payload);
+ } catch (JsonProcessingException e) {
+ fail("Convert DownloadNESwPayload to String error: " + e.toString());
+ }
+ }
+
+ @Test
+ public final void testBuildUpgradePostCheckPayload() {
+ String expectedPayload = "{" + "\"ipaddress-v4-oam\":\"192.168.1.10\","
+ + "\"playbook-name\":\"postcheck_playbook\"," + "\"oldSwVersion\":\"v1\","
+ + "\"targetSwVersion\":\"v2\"," + "\"ruleName\":\"r102\"," + "\"additionalData\":\"{}\"" + "}";
+
+ UpgradePostCheckPayload upgradePostCheckPayload = SDNCLcmPayloadBuilder.buildUpgradePostCheckPayload(execution);
+ try {
+ String payload = SDNCLcmPayloadBuilder.convertToSting(upgradePostCheckPayload);
+ logger.debug("UpgradePostCheckPayload:\n" + payload);
+
+ assertEquals(expectedPayload, payload);
+ } catch (JsonProcessingException e) {
+ fail("Convert UpgradePostCheckPayload to String error: " + e.toString());
+ }
+ }
+
+ @Test
+ public final void testBuildUpgradePreCheckPayload() {
+ String expectedPayload = "{" + "\"ipaddress-v4-oam\":\"192.168.1.10\","
+ + "\"playbook-name\":\"precheck_playbook\"," + "\"oldSwVersion\":\"v1\","
+ + "\"targetSwVersion\":\"v2\"," + "\"ruleName\":\"r101\"," + "\"additionalData\":\"{}\"" + "}";
+
+ UpgradePreCheckPayload upgradePreCheckPayload = SDNCLcmPayloadBuilder.buildUpgradePreCheckPayload(execution);
+ try {
+ String payload = SDNCLcmPayloadBuilder.convertToSting(upgradePreCheckPayload);
+ logger.debug("UpgradePreCheckPayload:\n" + payload);
+
+ assertEquals(expectedPayload, payload);
+ } catch (JsonProcessingException e) {
+ fail("Convert UpgradePreCheckPayload to String error: " + e.toString());
+ }
+ }
+}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/sdnc/SdncControllerDETest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/sdnc/SdncControllerDETest.java
index 674167624e..02c7dca9ae 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/sdnc/SdncControllerDETest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/sdnc/SdncControllerDETest.java
@@ -28,7 +28,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext;
import org.onap.so.bpmn.infrastructure.decisionpoint.api.controller.ControllerPreparable;
-import org.onap.so.client.appc.ApplicationControllerAction;
import org.onap.so.client.exception.ExceptionBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
@@ -48,9 +47,6 @@ public class SdncControllerDETest {
@MockBean
private ControllerPreparable<DelegateExecution> preparable;
- @MockBean
- protected ApplicationControllerAction client;
-
@Before
public void setUp() {
when(controllerContext.getControllerActor()).thenReturn("sdnc");