Springboot 2.0 upgrade
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / groovy / org / onap / so / bpmn / infrastructure / scripts / DoCreateE2EServiceInstanceTest.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 static com.shazam.shazamcrest.MatcherAssert.assertThat
24 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs
25 import static org.mockito.Mockito.times
26 import static org.mockito.Mockito.when
27
28 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
29 import org.junit.Before
30 import org.junit.Test
31 import org.mockito.ArgumentCaptor
32 import org.mockito.Captor
33 import org.mockito.Mockito
34 import org.onap.aai.domain.yang.ServiceInstance
35 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
36
37 /**
38  * @author sushilma
39  * @since January 10, 2018
40  */
41 class DoCreateE2EServiceInstanceTest extends MsoGroovyTest{
42
43
44     @Before
45     public void init() {
46         super.init("DoCreateE2EServiceInstance")
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         DoCreateE2EServiceInstance serviceInstance = new DoCreateE2EServiceInstance()
55         serviceInstance.preProcessRequest(mockExecution)
56         Mockito.verify(mockExecution, times(7)).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         expectedServiceInstanceData.setOrchestrationStatus("Created")
67         return expectedServiceInstanceData
68     }
69
70     private void mockData() {
71         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
72         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("12345")
73         when(mockExecution.getVariable("serviceType")).thenReturn("TRANSPORT")
74         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("1234")
75         when(mockExecution.getVariable("serviceInstanceName")).thenReturn("volte-service")
76         when(mockExecution.getVariable("uuiRequest")).thenReturn("""{"service":{"serviceDefId":"c1d4305f-cdbd-4bbe-9069-a2f4978fd89e" , "templateId" : "d4df5c27-98a1-4812-a8aa-c17f055b7a3f"}}""")
77         when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("/mso/sdncadapter/")
78         when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
79         when(mockExecution.getVariable("mso.workflow.default.aai.customer.version")).thenReturn("8")
80         when(mockExecution.getVariable("mso.workflow.default.aai.v8.customer.uri")).thenReturn('/aai/v8/business/customers/customer')
81         when(mockExecution.getVariable("URN_mso_workflow_sdncadapter_callback")).thenReturn('/testUrl')
82     }
83
84 }