aa3ab113a011761349f73b4fda2fadbbbee2c5fa
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / adapter / vnfm / tasks / MonitorVnfmNodeJobTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks;
22
23 import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.CREATE_VNF_NODE_STATUS;
24 import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.DELETE_VNF_NODE_STATUS;
25 import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.VNF_CREATED;
26 import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.VNF_ASSIGNED;
27 import static org.junit.Assert.assertNull;
28 import static org.junit.Assert.assertTrue;
29 import static org.mockito.ArgumentMatchers.any;
30 import static org.mockito.ArgumentMatchers.eq;
31 import static org.mockito.Mockito.verify;
32 import static org.mockito.Mockito.when;
33 import java.util.UUID;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.mockito.Mock;
37 import org.onap.aai.domain.yang.GenericVnf;
38 import org.onap.so.bpmn.BaseTaskTest;
39 import org.onap.so.bpmn.common.BuildingBlockExecution;
40 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
41
42 /**
43  * 
44  * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech)
45  *
46  */
47 public class MonitorVnfmNodeJobTest extends BaseTaskTest {
48
49   private static final String VNF_ID = UUID.randomUUID().toString();
50
51   private static final String VNF_NAME = "VNF_NAME";
52
53   private MonitorVnfmNodeTask objUnderTest;
54
55   @Mock
56   private VnfmAdapterServiceProvider mockedVnfmAdapterServiceProvider;
57
58   private final BuildingBlockExecution stubbedxecution = new StubbedBuildingBlockExecution();
59
60   @Before
61   public void setUp() {
62     objUnderTest = getEtsiVnfMonitorNodeJobTask();
63   }
64
65   @Test
66   public void testGetNodeStatusCreate() throws Exception {
67     GenericVnf vnf = getGenericVnf();
68     vnf.setOrchestrationStatus(VNF_CREATED);
69     when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(vnf);
70     objUnderTest.getNodeStatus(stubbedxecution);
71     assertTrue(stubbedxecution.getVariable(CREATE_VNF_NODE_STATUS));
72   }
73
74   @Test
75   public void testGetNodeStatusDelete() throws Exception {
76     GenericVnf vnf = getGenericVnf();
77     vnf.setOrchestrationStatus(VNF_ASSIGNED);
78     when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(vnf);
79     objUnderTest.getNodeStatus(stubbedxecution);
80     assertTrue(stubbedxecution.getVariable(DELETE_VNF_NODE_STATUS));
81   }
82
83   @Test
84   public void testGetNodeStatusException() throws Exception {
85     when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenThrow(RuntimeException.class);
86     objUnderTest.getNodeStatus(stubbedxecution);
87     assertNull(stubbedxecution.getVariable(CREATE_VNF_NODE_STATUS));
88     assertNull(stubbedxecution.getVariable(DELETE_VNF_NODE_STATUS));
89     verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1220),
90         any(Exception.class));
91   }
92
93   @Test
94   public void testTimeOutLogFailue() throws Exception {
95     objUnderTest.timeOutLogFailue(stubbedxecution);
96     verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1221),
97         eq("Node operation time out"));
98   }
99
100   private GenericVnf getGenericVnf() {
101     final GenericVnf genericVnf = new GenericVnf();
102     genericVnf.setVnfId(VNF_ID);
103     genericVnf.setVnfName(VNF_NAME);
104     return genericVnf;
105   }
106
107   private MonitorVnfmNodeTask getEtsiVnfMonitorNodeJobTask() {
108     return new MonitorVnfmNodeTask(extractPojosForBB, exceptionUtil);
109   }
110
111 }