Replaced all tabs with spaces in java and pom.xml
[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 import org.camunda.bpm.engine.delegate.BpmnError;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.mockito.ArgumentMatchers;
31 import org.mockito.InjectMocks;
32 import org.onap.so.bpmn.BaseTaskTest;
33 import org.onap.so.bpmn.common.BuildingBlockExecution;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
35 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
36 import org.onap.so.client.exception.BBObjectNotFoundException;
37 import org.onap.so.db.catalog.beans.OrchestrationStatus;
38
39 public class AssignNetworkTest extends BaseTaskTest {
40
41     @InjectMocks
42     private AssignNetwork assignNetwork = new AssignNetwork();
43
44     private L3Network network;
45
46     @Before
47     public void before() throws BBObjectNotFoundException {
48         network = setL3Network();
49         doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
50                 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
51         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))).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);
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);
71         } catch (BBObjectNotFoundException e) {
72         }
73         boolean networkFound = assignNetwork.networkFoundByName(execution);
74         assertEquals(true, networkFound);
75     }
76 }