161f879716c5f0389f7fe610a1a1870292ae09d9
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / onap / so / client / cds / AbstractCDSProcessingBBUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2019 TechMahindra.
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 package org.onap.so.client.cds;
22
23 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.ArgumentMatchers.anyInt;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.times;
27 import static org.mockito.Mockito.verify;
28 import static org.mockito.Mockito.when;
29
30 import java.util.UUID;
31
32 import org.camunda.bpm.engine.delegate.DelegateExecution;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.InjectMocks;
37 import org.mockito.Mock;
38 import org.mockito.junit.MockitoJUnitRunner;
39 import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
40 import org.onap.so.client.exception.ExceptionBuilder;
41
42 @RunWith(MockitoJUnitRunner.class)
43 public class AbstractCDSProcessingBBUtilsTest {
44     @InjectMocks
45     private AbstractCDSProcessingBBUtils abstractCDSProcessingBBUtils = new AbstractCDSProcessingBBUtils();
46     @InjectMocks
47     AbstractCDSPropertiesBean abstractCDSPropertiesBean = new AbstractCDSPropertiesBean();
48     @Mock
49     ExceptionBuilder exceptionUtil;
50
51     @Before
52     public void init(){
53         String requestObject = "{\"config-assign-request\":{\"resolution-key\":\"resolutionKey\", \"config-assign-properties\":{\"service-instance-id\":\"serviceInstanceId\", \"vnf-id\":\"vnfId\", \"vnf-name\":\"vnfName\", \"service-model-uuid\":\"serviceModelUuid\", \"vnf-customization-uuid\":\"vnfCustomizationUuid\",\"Instance1\":\"Instance1Value\",\"Instance2\":\"Instance2Value\",\"Param3\":\"Param3Value\"}}}";
54         String blueprintName = "blueprintName";
55         String blueprintVersion = "blueprintVersion";
56         String actionName = "actionName";
57         String mode = "mode";
58         String requestId = "123456";
59         String originatorId = "originatorId";
60         String subRequestId = UUID.randomUUID().toString();
61
62         abstractCDSPropertiesBean.setActionName(actionName);
63         abstractCDSPropertiesBean.setBlueprintName(blueprintName);
64         abstractCDSPropertiesBean.setBlueprintVersion(blueprintVersion);
65         abstractCDSPropertiesBean.setMode(mode);
66         abstractCDSPropertiesBean.setOriginatorId(originatorId);
67         abstractCDSPropertiesBean.setRequestId(requestId);
68         abstractCDSPropertiesBean.setRequestObject(requestObject);
69         abstractCDSPropertiesBean.setSubRequestId(subRequestId);
70     }
71
72     @Test
73     public void preProcessRequestTest() throws Exception {
74
75         DelegateExecution execution = mock(DelegateExecution.class);
76         when(execution.getVariable("executionObject")).thenReturn(abstractCDSPropertiesBean);
77
78         abstractCDSProcessingBBUtils.constructExecutionServiceInputObject(execution);
79         verify(exceptionUtil, times(0))
80             .buildAndThrowWorkflowException(any(DelegateExecution.class), anyInt(), any(Exception.class));
81     }
82
83     @Test
84     public void sendRequestToCDSClientTest() {
85
86         DelegateExecution execution = mock(DelegateExecution.class);
87         when(execution.getVariable("executionServiceInput")).thenReturn(abstractCDSPropertiesBean);
88         abstractCDSProcessingBBUtils.sendRequestToCDSClient(execution);
89         verify(exceptionUtil, times(1))
90             .buildAndThrowWorkflowException(any(DelegateExecution.class), anyInt(), any(Exception.class));
91
92     }
93
94 }