Containerization feature of SO
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / flowspecific / tasks / AssignNetworkTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 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 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
21
22 import static org.junit.Assert.assertEquals;
23
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.onap.so.bpmn.BaseTaskTest;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
29 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
30 import org.onap.so.client.exception.BBObjectNotFoundException;
31 import org.onap.so.db.catalog.beans.OrchestrationStatus;
32 import org.springframework.beans.factory.annotation.Autowired;
33
34 public class AssignNetworkTest extends BaseTaskTest {
35         
36         @Autowired
37         private AssignNetwork assignNetwork;
38         
39         private ServiceInstance serviceInstance;
40         private L3Network network;
41         
42         @Before
43         public void before() {
44                 serviceInstance = setServiceInstance();
45                 network = setL3Network();
46         }
47         
48         @Test
49         public void hasCollectionTest() throws Exception {
50                 setServiceInstance();
51                 //collection present by default base test setup
52                 boolean hasCollection = assignNetwork.hasCollection(execution);
53                 assertEquals(true, hasCollection);
54                 
55                 boolean skip = assignNetwork.skipNetworkCreationInAAI(execution);
56                 assertEquals(false, skip);
57         }
58         
59         @Test
60         public void hasNoCollectionTest() throws Exception {
61                 //clear collection
62                 try {
63                         serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
64                 } catch(BBObjectNotFoundException e) {
65                         serviceInstance = setServiceInstance();
66                 }
67                 serviceInstance.setCollection(null);
68                 boolean hasCollection = assignNetwork.hasCollection(execution);
69                 assertEquals(false, hasCollection);
70                 
71                 boolean skip = assignNetwork.skipNetworkCreationInAAI(execution);
72                 assertEquals(true, skip);
73         }
74         
75         @Test
76         public void hasNoCollectionNoNetworkTest() throws Exception {
77                 //clear collection and updated network status to PRECREATED - when it was NOT found by name
78                 try {
79                         serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
80                         network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID,execution.getLookupMap().get(ResourceKey.NETWORK_ID));
81                 } catch(BBObjectNotFoundException e) {
82                         serviceInstance = setServiceInstance();
83                 }
84                 serviceInstance.setCollection(null);
85                 network.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
86                 boolean hasCollection = assignNetwork.hasCollection(execution);
87                 boolean networkFound = assignNetwork.networkFoundByName(execution);
88                 assertEquals(false, hasCollection);
89                 assertEquals(false, networkFound);
90                 
91                 boolean skip = assignNetwork.skipNetworkCreationInAAI(execution);
92                 assertEquals(true, skip);
93         }
94
95         @Test
96         public void hasNetworkNoCollectionTest() throws Exception {
97                 //clear collection and updated network status to INVENTORIED - when it was found by name
98                 try {
99                         serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
100                         network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID,execution.getLookupMap().get(ResourceKey.NETWORK_ID));
101                 } catch(BBObjectNotFoundException e) {
102                         serviceInstance = setServiceInstance();
103                 }
104                 serviceInstance.setCollection(null);
105                 network.setOrchestrationStatus(OrchestrationStatus.INVENTORIED);
106                 boolean hasCollection = assignNetwork.hasCollection(execution);
107                 boolean networkFound = assignNetwork.networkFoundByName(execution);
108                 assertEquals(false, hasCollection);
109                 assertEquals(true, networkFound);
110                 
111                 boolean skip = assignNetwork.skipNetworkCreationInAAI(execution);
112                 assertEquals(true, skip);
113         }
114         
115 }