Containerization feature of SO
[so.git] / bpmn / so-bpmn-infrastructure-flows / src / test / groovy / org / onap / so / bpmn / infrastructure / scripts / CreateCustomE2EServiceInstanceTest.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 com.github.tomakehurst.wiremock.junit.WireMockRule
24 import org.camunda.bpm.engine.ProcessEngineServices
25 import org.camunda.bpm.engine.RepositoryService
26 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
27 import org.camunda.bpm.engine.repository.ProcessDefinition
28 import org.junit.Before
29 import org.junit.Rule
30 import org.junit.Test
31 import org.junit.runner.RunWith
32 import org.mockito.ArgumentCaptor
33 import org.mockito.Captor
34 import org.mockito.Mockito
35 import org.mockito.MockitoAnnotations
36 import org.mockito.runners.MockitoJUnitRunner
37
38 import static org.junit.Assert.assertNotNull
39 import static org.mockito.Mockito.*
40
41 @RunWith(MockitoJUnitRunner.class)
42 class CreateCustomE2EServiceInstanceTest {
43
44     @Rule
45     public WireMockRule wireMockRule = new WireMockRule(28090);
46
47     @Before
48     public void init() throws IOException {
49         MockitoAnnotations.initMocks(this);
50     }
51
52     @Captor
53     static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
54
55     @Test
56     public void testPrepareInitServiceOperationStatus (){
57         ExecutionEntity mockExecution = setupMock()
58         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("12345")
59         when(mockExecution.getVariable("mso.adapters.openecomp.db.endpoint")).thenReturn("http://localhost:28090/dbadapters/RequestsDbAdapter")
60         CreateCustomE2EServiceInstance obj = new CreateCustomE2EServiceInstance();
61         obj.prepareInitServiceOperationStatus(mockExecution)
62         Mockito.verify(mockExecution, times(5)).setVariable(captor.capture(), captor.capture())
63         def updateVolumeGroupRequest = captor.getValue()
64         assertNotNull(updateVolumeGroupRequest);
65     }
66
67     private ExecutionEntity setupMock() {
68         ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
69         when(mockProcessDefinition.getKey()).thenReturn("CreateCustomE2EServiceInstance")
70         RepositoryService mockRepositoryService = mock(RepositoryService.class)
71         when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
72         when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("CreateCustomE2EServiceInstance")
73         when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
74         ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
75         when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
76         ExecutionEntity mockExecution = mock(ExecutionEntity.class)
77         when(mockExecution.getId()).thenReturn("100")
78         when(mockExecution.getProcessDefinitionId()).thenReturn("CreateCustomE2EServiceInstance")
79         when(mockExecution.getProcessInstanceId()).thenReturn("CreateCustomE2EServiceInstance")
80         when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
81         when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)
82         return mockExecution
83     }
84 }