Springboot 2.0 upgrade
[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 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.ArgumentMatchers.eq;
25 import static org.mockito.Mockito.doThrow;
26 import static org.mockito.Mockito.when;
27
28 import org.camunda.bpm.engine.delegate.BpmnError;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.ArgumentMatchers;
32 import org.mockito.InjectMocks;
33 import org.onap.so.bpmn.BaseTaskTest;
34 import org.onap.so.bpmn.common.BuildingBlockExecution;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
36 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
37 import org.onap.so.client.exception.BBObjectNotFoundException;
38 import org.onap.so.db.catalog.beans.OrchestrationStatus;
39
40 public class AssignNetworkTest extends BaseTaskTest {
41         
42         @InjectMocks
43         private AssignNetwork assignNetwork = new AssignNetwork();
44         
45         private L3Network network;
46         
47         @Before
48         public void before() throws BBObjectNotFoundException {
49                 network = setL3Network();
50                 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));     
51                 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.NETWORK_ID), any())).thenReturn(network);
52         }
53         
54         @Test
55         public void networkNotFoundTest() throws Exception {
56                 //network status to PRECREATED - when it was NOT found by name
57                 try {
58                         network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID,execution.getLookupMap().get(ResourceKey.NETWORK_ID));
59                 } catch(BBObjectNotFoundException e) {
60                 }
61                 
62                 network.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
63                 boolean networkFound = assignNetwork.networkFoundByName(execution);
64                 assertEquals(false, networkFound);
65         }
66
67         @Test
68         public void networkFoundTest() throws Exception {
69                 try {
70                         network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID,execution.getLookupMap().get(ResourceKey.NETWORK_ID));
71                 } catch(BBObjectNotFoundException e) {
72                 }
73                 boolean networkFound = assignNetwork.networkFoundByName(execution);
74                 assertEquals(true, networkFound);
75         }
76 }