Containerization feature of SO
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / flowspecific / tasks / UnassignNetworkBBTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
22
23 import static org.junit.Assert.assertEquals;
24
25 import java.nio.file.Files;
26 import java.nio.file.Paths;
27
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;
34
35 public class UnassignNetworkBBTest extends BaseTaskTest {
36         @Autowired
37         private UnassignNetworkBB unassignNetworkBB;
38         
39         private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/Network/";  
40         
41         @Test
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);
47                 
48                 unassignNetworkBB.checkRelationshipRelatedTo(execution, "vf-module");
49         }       
50         
51         @Test
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);
56                 
57                 unassignNetworkBB.checkRelationshipRelatedTo(execution, "kfc-module");
58                 //expected result is no exception
59         }       
60         
61         @Test
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"));
67         }       
68         
69         @Test
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"));
76         }       
77         
78         @Test
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);
84         }
85         
86         @Test
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);
91         }       
92 }