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 / ModifyRANNssiBBTaskTest.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.core.JsonProcessingException;
25 import junit.framework.TestCase;
26 import org.camunda.bpm.engine.delegate.BpmnError;
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.aai.domain.yang.SliceProfile;
37 import org.onap.aaiclient.client.aai.AAIRestClientImpl;
38 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
39 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
40 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder;
41 import org.onap.so.bpmn.common.BuildingBlockExecution;
42 import org.onap.so.bpmn.common.InjectionHelper;
43 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
44 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
45 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
46 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
47 import org.onap.so.client.exception.BBObjectNotFoundException;
48 import org.onap.so.client.exception.ExceptionBuilder;
49 import org.onap.so.db.catalog.beans.OrchestrationStatus;
50 import java.util.*;
51 import static org.junit.Assert.*;
52 import static org.mockito.ArgumentMatchers.any;
53 import static org.mockito.ArgumentMatchers.eq;
54 import static org.mockito.Mockito.*;
55 import static org.mockito.Mockito.times;
56
57 @RunWith(MockitoJUnitRunner.Silent.class)
58
59 public class ModifyRANNssiBBTaskTest {
60     @Mock
61     BuildingBlockExecution execution;
62     @Mock
63     ServiceInstance serviceInstance;
64     @Mock
65     private AAIResourceUri allotedResourceURI;
66     private org.onap.aai.domain.yang.Customer customer = new org.onap.aai.domain.yang.Customer();
67     @Mock
68     private ModelInfoServiceInstance modelInfoServiceInstance;
69     @Mock
70     protected ExtractPojosForBB extractPojosForBBMock;
71
72     @Mock
73     protected InjectionHelper injectionHelper;
74
75     private String operationalState = "ENABLED";
76     private String administrativeState = "UNLOCKED";
77     private String serviceInstanceId = "123";
78     private ServiceSubscription serviceSubscription;
79     @Mock
80     protected ExceptionBuilder exceptionUtil;
81     String serviceType;
82
83     private String sliceProfileServiceInstanceId = "123";
84
85     private AAIRestClientImpl aaiRestClient = new AAIRestClientImpl();
86
87     @Mock
88     private GeneralBuildingBlock gBB = new GeneralBuildingBlock();
89
90     @Rule
91     public ExpectedException expectedException = ExpectedException.none();
92     @Mock
93     ModifyRANNssiBBTask modifyRANNssiBBTask = new ModifyRANNssiBBTask();
94
95     @Before
96     public void before() throws BBObjectNotFoundException {
97         serviceInstance.setServiceInstanceId("123");
98         modelInfoServiceInstance.setModelUuid("235");
99         ServiceInstance serviceInstance = new ServiceInstance();
100         when(extractPojosForBBMock.extractByKey(any(), eq(ResourceKey.SERVICE_INSTANCE_ID)))
101                 .thenReturn(serviceInstanceId);
102         when(extractPojosForBBMock.extractByKey(any(), eq(ResourceKey.ServiceInstance))).thenReturn(serviceInstance);
103         when(extractPojosForBBMock.extractByKey(any(), eq(ResourceKey.ModelInfoServiceInstance)))
104                 .thenReturn(modelInfoServiceInstance);
105         when(extractPojosForBBMock.extractByKey(any(), eq(ResourceKey.operationalState))).thenReturn(operationalState);
106         when(extractPojosForBBMock.extractByKey(any(), eq(ResourceKey.administrativeState)))
107                 .thenReturn(administrativeState);
108         serviceSubscription = new ServiceSubscription();
109         serviceSubscription.setServiceType(serviceType);
110     }
111
112     @Test
113     public void modifyNssiTest() throws JsonProcessingException {
114
115         doNothing().when(modifyRANNssiBBTask).modifyNssi(execution);
116         modifyRANNssiBBTask.modifyNssi(execution);
117         verify(modifyRANNssiBBTask, times(1)).modifyNssi(execution);
118     }
119 }
120
121