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.junit.Assert.assertEquals;
25 import java.nio.file.Files;
26 import java.nio.file.Paths;
28 import org.camunda.bpm.engine.delegate.BpmnError;
29 import org.junit.Test;
30 import org.onap.so.bpmn.BaseTaskTest;
31 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
32 import org.onap.so.client.aai.entities.AAIResultWrapper;
33 import org.springframework.beans.factory.annotation.Autowired;
35 public class UnassignNetworkBBTest extends BaseTaskTest {
37 private UnassignNetworkBB unassignNetworkBB;
39 private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/Network/";
42 public void checkRelationshipRelatedToTrueTest() throws Exception {
43 expectedException.expect(BpmnError.class);
44 final String aaiResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "unassignNetworkBB_queryAAIResponse_.json")));
45 AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(aaiResponse);
46 execution.setVariable("l3NetworkAAIResultWrapper", aaiResultWrapper);
48 unassignNetworkBB.checkRelationshipRelatedTo(execution, "vf-module");
52 public void checkRelationshipRelatedToFalseTest() throws Exception {
53 final String aaiResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "unassignNetworkBB_queryAAIResponse_.json")));
54 AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(aaiResponse);
55 execution.setVariable("l3NetworkAAIResultWrapper", aaiResultWrapper);
57 unassignNetworkBB.checkRelationshipRelatedTo(execution, "kfc-module");
58 //expected result is no exception
62 public void getCloudSdncRegion25Test() throws Exception {
63 CloudRegion cloudRegion = setCloudRegion();
64 cloudRegion.setCloudRegionVersion("2.5");
65 unassignNetworkBB.getCloudSdncRegion(execution);
66 assertEquals("AAIAIC25", execution.getVariable("cloudRegionSdnc"));
70 public void getCloudSdncRegion30Test() throws Exception {
71 CloudRegion cloudRegion = setCloudRegion();
72 cloudRegion.setCloudRegionVersion("3.0");
73 gBBInput.setCloudRegion(cloudRegion);
74 unassignNetworkBB.getCloudSdncRegion(execution);
75 assertEquals(cloudRegion.getLcpCloudRegionId(), execution.getVariable("cloudRegionSdnc"));
79 public void errorEncounteredTest_rollback() throws Exception {
80 expectedException.expect(BpmnError.class);
81 execution.setVariable("ErrorUnassignNetworkBB", "Relationship's RelatedTo still exists in AAI, remove the relationship vf-module first.");
82 execution.setVariable("isRollbackNeeded", true);
83 unassignNetworkBB.errorEncountered(execution);
87 public void errorEncounteredTest_noRollback() throws Exception {
88 expectedException.expect(BpmnError.class);
89 execution.setVariable("ErrorUnassignNetworkBB", "Relationship's RelatedTo still exists in AAI, remove the relationship vf-module first.");
90 unassignNetworkBB.errorEncountered(execution);