2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 AT&T Intellectual Property. 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.flowspecific.tasks;
23 import static org.hamcrest.CoreMatchers.notNullValue;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertThat;
26 import static org.mockito.ArgumentMatchers.any;
27 import static org.mockito.ArgumentMatchers.eq;
28 import static org.mockito.Mockito.doReturn;
29 import static org.mockito.Mockito.doThrow;
31 import java.nio.file.Files;
32 import java.nio.file.Paths;
33 import java.util.Optional;
35 import org.camunda.bpm.engine.delegate.BpmnError;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.mockito.InjectMocks;
39 import org.mockito.Mock;
40 import org.onap.so.bpmn.BaseTaskTest;
41 import org.onap.so.bpmn.common.BuildingBlockExecution;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
44 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
45 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
46 import org.onap.so.client.aai.entities.AAIResultWrapper;
47 import org.springframework.beans.factory.annotation.Autowired;
49 public class UnassignNetworkBBTest extends BaseTaskTest {
52 private NetworkBBUtils networkBBUtils;
55 private UnassignNetworkBB unassignNetworkBB = new UnassignNetworkBB();
57 private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/Network/";
58 private L3Network network;
62 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
63 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
67 public void checkRelationshipRelatedToTrueTest() throws Exception {
68 expectedException.expect(BpmnError.class);
69 network = setL3Network();
70 network.setNetworkId("testNetworkId1");
71 final String aaiResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "unassignNetworkBB_queryAAIResponse_.json")));
72 AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(aaiResponse);
73 Optional<org.onap.aai.domain.yang.L3Network> l3network = aaiResultWrapper.asBean(org.onap.aai.domain.yang.L3Network.class);
75 doReturn(network).when(extractPojosForBB).extractByKey(execution, ResourceKey.NETWORK_ID, "testNetworkId1");
76 doReturn(aaiResultWrapper).when(aaiNetworkResources).queryNetworkWrapperById(network);
78 doReturn(true).when(networkBBUtils).isRelationshipRelatedToExists(any(Optional.class), eq("vf-module"));
80 unassignNetworkBB.checkRelationshipRelatedTo(execution, "vf-module");
81 assertThat(execution.getVariable("ErrorUnassignNetworkBB"), notNullValue());
85 public void getCloudSdncRegion25Test() throws Exception {
86 CloudRegion cloudRegion = setCloudRegion();
87 cloudRegion.setCloudRegionVersion("2.5");
88 doReturn("AAIAIC25").when(networkBBUtils).getCloudRegion(execution, SourceSystem.SDNC);
89 unassignNetworkBB.getCloudSdncRegion(execution);
90 assertEquals("AAIAIC25", execution.getVariable("cloudRegionSdnc"));
94 public void getCloudSdncRegion30Test() throws Exception {
95 CloudRegion cloudRegion = setCloudRegion();
96 cloudRegion.setCloudRegionVersion("3.0");
97 gBBInput.setCloudRegion(cloudRegion);
98 doReturn(cloudRegion.getLcpCloudRegionId()).when(networkBBUtils).getCloudRegion(execution, SourceSystem.SDNC);
99 unassignNetworkBB.getCloudSdncRegion(execution);
100 assertEquals(cloudRegion.getLcpCloudRegionId(), execution.getVariable("cloudRegionSdnc"));
104 public void errorEncounteredTest_rollback() throws Exception {
105 expectedException.expect(BpmnError.class);
106 execution.setVariable("ErrorUnassignNetworkBB", "Relationship's RelatedTo still exists in AAI, remove the relationship vf-module first.");
107 execution.setVariable("isRollbackNeeded", true);
108 unassignNetworkBB.errorEncountered(execution);
112 public void errorEncounteredTest_noRollback() throws Exception {
113 expectedException.expect(BpmnError.class);
114 execution.setVariable("ErrorUnassignNetworkBB", "Relationship's RelatedTo still exists in AAI, remove the relationship vf-module first.");
115 unassignNetworkBB.errorEncountered(execution);