Springboot 2.0 upgrade
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / flowspecific / tasks / NetworkBBUtilsTest.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 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
26
27 import java.nio.file.Files;
28 import java.nio.file.Paths;
29 import java.util.Optional;
30
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.mockito.InjectMocks;
34 import org.mockito.Mockito;
35 import org.onap.aai.domain.yang.L3Network;
36 import org.onap.so.bpmn.BaseTaskTest;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
38 import org.onap.so.client.aai.entities.AAIResultWrapper;
39 import org.springframework.beans.factory.annotation.Autowired;
40
41 public class NetworkBBUtilsTest  extends BaseTaskTest{
42         @InjectMocks
43         private NetworkBBUtils networkBBUtils = new NetworkBBUtils();
44         
45         private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/Network/";
46         
47         private CloudRegion cloudRegion;
48         
49         @Before
50         public void before() {
51                 cloudRegion = setCloudRegion();
52         }
53
54         @Test
55         public void isRelationshipRelatedToExistsTrueTest() throws Exception {
56                 final String aaiResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "unassignNetworkBB_queryAAIResponse_.json")));
57                 AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(aaiResponse); 
58                 Optional<L3Network> l3network = aaiResultWrapper.asBean(L3Network.class);
59                 
60                 boolean isVfModule = networkBBUtils.isRelationshipRelatedToExists(l3network, "vf-module");
61                 assertTrue(isVfModule);
62                 
63         }
64         
65         @Test
66         public void isRelationshipRelatedToExistsFalseTest() throws Exception {
67                 final String aaiResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "queryAAIResponse.json")));
68                 AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(aaiResponse); 
69                 Optional<L3Network> l3network = aaiResultWrapper.asBean(L3Network.class);
70                 
71                 boolean isVfModule = networkBBUtils.isRelationshipRelatedToExists(l3network, "vf-module");
72                 assertFalse(isVfModule);
73                 
74         }       
75         
76         @Test
77         public void getCloudRegionSDNC25Test() throws Exception {
78                 cloudRegion.setCloudRegionVersion("2.5");
79                 
80                 NetworkBBUtils spyAssign = Mockito.spy(NetworkBBUtils.class);
81                 String cloudRegionId = spyAssign.getCloudRegion(execution, SourceSystem.SDNC);
82                 Mockito.verify(spyAssign).getCloudRegion(execution, SourceSystem.SDNC);
83
84                 assertEquals("AAIAIC25", cloudRegionId);
85         }       
86         
87         @Test
88         public void getCloudRegionSDNC30Test() throws Exception {
89                 cloudRegion.setCloudRegionVersion("3.0");
90                 
91                 NetworkBBUtils spyAssign = Mockito.spy(NetworkBBUtils.class);
92                 String cloudRegionId = spyAssign.getCloudRegion(execution, SourceSystem.SDNC);
93                 Mockito.verify(spyAssign).getCloudRegion(execution, SourceSystem.SDNC);
94
95                 assertEquals(cloudRegion.getLcpCloudRegionId(), cloudRegionId);
96         }       
97         
98         @Test
99         public void getCloudRegionPO25Test() throws Exception {
100                 cloudRegion.setCloudRegionVersion("2.5");
101                 
102                 NetworkBBUtils spyAssign = Mockito.spy(NetworkBBUtils.class);
103                 String cloudRegionId = spyAssign.getCloudRegion(execution, SourceSystem.PO);
104                 Mockito.verify(spyAssign).getCloudRegion(execution, SourceSystem.PO);
105
106                 assertEquals(cloudRegion.getLcpCloudRegionId(), cloudRegionId);
107         }       
108         
109         @Test
110         public void getCloudRegionPO30Test() throws Exception {
111                 cloudRegion.setCloudRegionVersion("3.0");
112                 
113                 NetworkBBUtils spyAssignPO = Mockito.spy(NetworkBBUtils.class);
114                 String cloudRegionIdPO = spyAssignPO.getCloudRegion(execution, SourceSystem.PO);
115                 Mockito.verify(spyAssignPO).getCloudRegion(execution, SourceSystem.PO);
116
117                 assertEquals(cloudRegion.getLcpCloudRegionId(), cloudRegionIdPO);               
118         }       
119 }