2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
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;
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;
40 public class AssignNetworkTest extends BaseTaskTest {
43 private AssignNetwork assignNetwork = new AssignNetwork();
45 private L3Network network;
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);
55 public void networkNotFoundTest() throws Exception {
56 //network status to PRECREATED - when it was NOT found by name
58 network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID,execution.getLookupMap().get(ResourceKey.NETWORK_ID));
59 } catch(BBObjectNotFoundException e) {
62 network.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
63 boolean networkFound = assignNetwork.networkFoundByName(execution);
64 assertEquals(false, networkFound);
68 public void networkFoundTest() throws Exception {
70 network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID,execution.getLookupMap().get(ResourceKey.NETWORK_ID));
71 } catch(BBObjectNotFoundException e) {
73 boolean networkFound = assignNetwork.networkFoundByName(execution);
74 assertEquals(true, networkFound);