Springboot 2.0 upgrade
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / groovy / org / onap / so / bpmn / infrastructure / scripts / DoUpdateE2EServiceInstanceTest.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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.bpmn.infrastructure.scripts
22
23 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
24 import org.junit.Before
25 import org.junit.Test
26 import org.mockito.ArgumentCaptor
27 import org.mockito.Captor
28 import org.mockito.Mockito
29 import org.onap.aai.domain.yang.ServiceInstance
30 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
31
32 import static com.shazam.shazamcrest.MatcherAssert.assertThat
33 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs
34 import static org.mockito.Mockito.times
35 import static org.mockito.Mockito.when
36
37 /**
38  * @author sushilma
39  * @since January 10, 2018
40  */
41 class DoUpdateE2EServiceInstanceTest extends MsoGroovyTest{
42
43
44     @Before
45     public void init() {
46         super.init("DoUpdateE2EServiceInstance")
47     }
48     @Captor
49     static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
50     @Test
51     public void testPreProcessRequest(){
52         mockData()
53         ServiceInstance expectedServiceInstanceData = getExpectedServiceInstance()
54         DoUpdateE2EServiceInstance serviceInstance = new DoUpdateE2EServiceInstance()
55         serviceInstance.preProcessAAIPUT(mockExecution)
56         Mockito.verify(mockExecution, times(1)).setVariable(captor.capture(), captor.capture())
57         assertThat(captor.getValue(), sameBeanAs(expectedServiceInstanceData))
58     }
59
60     private ServiceInstance getExpectedServiceInstance() {
61         ServiceInstance expectedServiceInstanceData = new ServiceInstance()
62         expectedServiceInstanceData.setServiceInstanceId("1234")
63         expectedServiceInstanceData.setServiceInstanceName("volte-service")
64         expectedServiceInstanceData.setServiceType("E2E Service")
65         expectedServiceInstanceData.setServiceRole("E2E Service")
66         return expectedServiceInstanceData
67     }
68
69     private void mockData() {
70         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
71         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("12345")
72         when(mockExecution.getVariable("serviceType")).thenReturn("TRANSPORT")
73         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("1234")
74         when(mockExecution.getVariable("serviceInstanceName")).thenReturn("volte-service")
75         when(mockExecution.getVariable("uuiRequest")).thenReturn("""{"service":{"serviceDefId":"c1d4305f-cdbd-4bbe-9069-a2f4978fd89e" , "templateId" : "d4df5c27-98a1-4812-a8aa-c17f055b7a3f"}}""")
76         when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("/mso/sdncadapter/")
77         when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
78         when(mockExecution.getVariable("mso.workflow.default.aai.customer.version")).thenReturn("8")
79         when(mockExecution.getVariable("mso.workflow.default.aai.v8.customer.uri")).thenReturn('/aai/v8/business/customers/customer')
80         when(mockExecution.getVariable("URN_mso_workflow_sdncadapter_callback")).thenReturn('/testUrl')
81     }
82
83 }