Code changes in BPMN infra for RAN Slice Use case
[so.git] / bpmn / so-bpmn-moi / src / test / java / org / onap / so / bpmn / moi / tasks / AssignRANNssiBBTasksTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (c) 2022 Deutsche telekom
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
21
22 package org.onap.so.bpmn.moi.tasks;
23
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import org.camunda.bpm.engine.delegate.BpmnError;
26 import org.onap.aai.domain.yang.Customer;
27 import org.junit.Before;
28 import org.junit.Rule;
29 import org.junit.Test;
30 import org.junit.rules.ExpectedException;
31 import org.junit.runner.RunWith;
32 import org.mockito.Mock;
33 import org.mockito.junit.MockitoJUnitRunner;
34 import org.onap.aai.domain.yang.ServiceInstance;
35 import org.onap.aai.domain.yang.ServiceSubscription;
36 import org.onap.aaiclient.client.aai.AAIRestClientImpl;
37 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
38 import org.onap.so.bpmn.common.BuildingBlockExecution;
39 import org.onap.so.bpmn.common.InjectionHelper;
40 import org.onap.so.bpmn.moi.util.SliceProfileAaiToMoiMapperUtil;
41 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
42 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
43 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
44 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
45 import org.onap.so.client.exception.BBObjectNotFoundException;
46 import org.onap.so.client.exception.ExceptionBuilder;
47 import java.util.*;
48 import static org.mockito.ArgumentMatchers.any;
49 import static org.mockito.ArgumentMatchers.eq;
50 import static org.mockito.Mockito.*;
51 import static org.mockito.Mockito.times;
52
53 @RunWith(MockitoJUnitRunner.Silent.class)
54
55 public class AssignRANNssiBBTasksTest {
56     @Mock
57     protected InjectionHelper injectionHelper;
58     @Mock
59     protected ObjectMapper mapper = new ObjectMapper();
60     @Mock
61     protected AAIRestClientImpl aaiRestClient = new AAIRestClientImpl();
62     @Mock
63     protected SliceProfileAaiToMoiMapperUtil mapperUtil;
64     @Mock
65     GeneralBuildingBlock gBB;
66     @Mock
67     ServiceInstance serviceInstance;
68     @Mock
69     protected ExceptionBuilder exceptionUtil;
70     @Mock
71     AssignRANNssiBBTasks assignRANNssiBBTasks;
72     @Mock
73     private BuildingBlockExecution execution;
74     @Mock
75     private ModelInfoServiceInstance modelInfoServiceInstance;
76     @Mock
77     protected ExtractPojosForBB extractPojosForBBMock;
78
79
80     private String operationalState;
81     private String administrativeState;
82
83     private String sliceProfileServiceInstanceId = "215";
84
85     private String serviceInstanceId = "123";
86
87     Customer customerA = new Customer();
88
89     @Mock
90     private AAIResourceUri allotedResourceURI;
91     String serviceType;
92
93     String globalCustomerId;
94
95     private UUID allottedResourceUuidUuid = UUID.randomUUID();
96
97     @Rule
98     public final ExpectedException exception = ExpectedException.none();
99     private ServiceSubscription serviceSubscription;
100
101     @Rule
102     public ExpectedException expectedException = ExpectedException.none();
103
104     @Before
105     public void before() throws BBObjectNotFoundException {
106
107         serviceInstance.setServiceInstanceId("123");
108         modelInfoServiceInstance.setModelUuid("235");
109         ServiceInstance serviceInstance = new ServiceInstance();
110         when(extractPojosForBBMock.extractByKey(any(), eq(ResourceKey.SERVICE_INSTANCE_ID)))
111                 .thenReturn(serviceInstanceId);
112         when(extractPojosForBBMock.extractByKey(any(), eq(ResourceKey.ServiceInstance))).thenReturn(serviceInstance);
113         when(extractPojosForBBMock.extractByKey(any(), eq(ResourceKey.ModelInfoServiceInstance)))
114                 .thenReturn(modelInfoServiceInstance);
115         when(extractPojosForBBMock.extractByKey(any(), eq(ResourceKey.operationalState))).thenReturn(operationalState);
116         when(extractPojosForBBMock.extractByKey(any(), eq(ResourceKey.administrativeState)))
117                 .thenReturn(administrativeState);
118         serviceSubscription = new ServiceSubscription();
119         serviceSubscription.setServiceType(serviceType);
120         doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
121                 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
122     }
123
124     @Test
125     public void createNssiTest() throws Exception {
126         doNothing().when(assignRANNssiBBTasks).createNssi(execution);
127         assignRANNssiBBTasks.createNssi(execution);
128         verify(assignRANNssiBBTasks, times(1)).createNssi(execution);
129         System.out.println("sucess");
130     }
131
132     @Test
133     public void createSliceProfileInstanceTest() {
134         doNothing().when(assignRANNssiBBTasks).createSliceProfileInstance(execution);
135         assignRANNssiBBTasks.createSliceProfileInstance(execution);
136         verify(assignRANNssiBBTasks, times(1)).createSliceProfileInstance(execution);
137         System.out.println("sucess");
138     }
139
140     @Test
141     public void allotResourcesTest() {
142         doNothing().when(assignRANNssiBBTasks).allotResources(execution);
143         assignRANNssiBBTasks.allotResources(execution);
144         verify(assignRANNssiBBTasks, times(1)).allotResources(execution);
145     }
146
147     @Test
148     public void addSliceProfileToNssiTest() {
149         doNothing().when(assignRANNssiBBTasks).addSliceProfileToNssi(execution);
150         assignRANNssiBBTasks.addSliceProfileToNssi(execution);
151         verify(assignRANNssiBBTasks, times(1)).addSliceProfileToNssi(execution);
152         System.out.println("sucess");
153     }
154
155     @Test
156     public void activateNssiTest() {
157         doNothing().when(assignRANNssiBBTasks).activateNssi(execution);
158         assignRANNssiBBTasks.activateNssi(execution);
159         verify(assignRANNssiBBTasks, times(1)).activateNssi(execution);
160     }
161
162 }