2 * ============LICENSE_START=======================================================
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
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=========================================================
22 package org.onap.so.bpmn.moi.tasks;
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;
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;
53 @RunWith(MockitoJUnitRunner.Silent.class)
55 public class AssignRANNssiBBTasksTest {
57 protected InjectionHelper injectionHelper;
59 protected ObjectMapper mapper = new ObjectMapper();
61 protected AAIRestClientImpl aaiRestClient = new AAIRestClientImpl();
63 protected SliceProfileAaiToMoiMapperUtil mapperUtil;
65 GeneralBuildingBlock gBB;
67 ServiceInstance serviceInstance;
69 protected ExceptionBuilder exceptionUtil;
71 AssignRANNssiBBTasks assignRANNssiBBTasks;
73 private BuildingBlockExecution execution;
75 private ModelInfoServiceInstance modelInfoServiceInstance;
77 protected ExtractPojosForBB extractPojosForBBMock;
80 private String operationalState;
81 private String administrativeState;
83 private String sliceProfileServiceInstanceId = "215";
85 private String serviceInstanceId = "123";
87 Customer customerA = new Customer();
90 private AAIResourceUri allotedResourceURI;
93 String globalCustomerId;
95 private UUID allottedResourceUuidUuid = UUID.randomUUID();
98 public final ExpectedException exception = ExpectedException.none();
99 private ServiceSubscription serviceSubscription;
102 public ExpectedException expectedException = ExpectedException.none();
105 public void before() throws BBObjectNotFoundException {
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));
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");
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");
141 public void allotResourcesTest() {
142 doNothing().when(assignRANNssiBBTasks).allotResources(execution);
143 assignRANNssiBBTasks.allotResources(execution);
144 verify(assignRANNssiBBTasks, times(1)).allotResources(execution);
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");
156 public void activateNssiTest() {
157 doNothing().when(assignRANNssiBBTasks).activateNssi(execution);
158 assignRANNssiBBTasks.activateNssi(execution);
159 verify(assignRANNssiBBTasks, times(1)).activateNssi(execution);