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.Mockito.doReturn;
28 import java.nio.file.Files;
29 import java.nio.file.Paths;
30 import java.util.Optional;
32 import org.camunda.bpm.engine.delegate.BpmnError;
33 import org.junit.Test;
34 import org.mockito.Mock;
35 import org.onap.so.bpmn.BaseTaskTest;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
38 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
39 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
40 import org.onap.so.client.aai.entities.AAIResultWrapper;
41 import org.springframework.beans.factory.annotation.Autowired;
43 public class UnassignNetworkBBTest extends BaseTaskTest {
46 private NetworkBBUtils networkBBUtils;
48 private ExtractPojosForBB extractPojosForBB;
50 private UnassignNetworkBB unassignNetworkBB;
52 private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/Network/";
53 private L3Network network;
56 public void checkRelationshipRelatedToTrueTest() throws Exception {
57 expectedException.expect(BpmnError.class);
58 network = setL3Network();
59 network.setNetworkId("testNetworkId1");
60 final String aaiResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "unassignNetworkBB_queryAAIResponse_.json")));
61 AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(aaiResponse);
62 Optional<org.onap.aai.domain.yang.L3Network> l3network = aaiResultWrapper.asBean(org.onap.aai.domain.yang.L3Network.class);
63 doReturn(network).when(extractPojosForBB).extractByKey(execution, ResourceKey.NETWORK_ID, "testNetworkId1");
64 doReturn(aaiResultWrapper).when(aaiNetworkResources).queryNetworkWrapperById(network);
65 doReturn(true).when(networkBBUtils).isRelationshipRelatedToExists(l3network, "vf-module");
66 unassignNetworkBB.checkRelationshipRelatedTo(execution, "vf-module");
67 assertThat(execution.getVariable("ErrorUnassignNetworkBB"), notNullValue());
71 public void getCloudSdncRegion25Test() throws Exception {
72 CloudRegion cloudRegion = setCloudRegion();
73 cloudRegion.setCloudRegionVersion("2.5");
74 doReturn("AAIAIC25").when(networkBBUtils).getCloudRegion(execution, SourceSystem.SDNC);
75 unassignNetworkBB.getCloudSdncRegion(execution);
76 assertEquals("AAIAIC25", execution.getVariable("cloudRegionSdnc"));
80 public void getCloudSdncRegion30Test() throws Exception {
81 CloudRegion cloudRegion = setCloudRegion();
82 cloudRegion.setCloudRegionVersion("3.0");
83 gBBInput.setCloudRegion(cloudRegion);
84 doReturn(cloudRegion.getLcpCloudRegionId()).when(networkBBUtils).getCloudRegion(execution, SourceSystem.SDNC);
85 unassignNetworkBB.getCloudSdncRegion(execution);
86 assertEquals(cloudRegion.getLcpCloudRegionId(), execution.getVariable("cloudRegionSdnc"));
90 public void errorEncounteredTest_rollback() throws Exception {
91 expectedException.expect(BpmnError.class);
92 execution.setVariable("ErrorUnassignNetworkBB", "Relationship's RelatedTo still exists in AAI, remove the relationship vf-module first.");
93 execution.setVariable("isRollbackNeeded", true);
94 unassignNetworkBB.errorEncountered(execution);
98 public void errorEncounteredTest_noRollback() throws Exception {
99 expectedException.expect(BpmnError.class);
100 execution.setVariable("ErrorUnassignNetworkBB", "Relationship's RelatedTo still exists in AAI, remove the relationship vf-module first.");
101 unassignNetworkBB.errorEncountered(execution);