Containerization feature of SO
[so.git] / bpmn / so-bpmn-infrastructure-flows / src / test / groovy / org / onap / so / bpmn / infrastructure / scripts / CreateVfModuleInfraTest.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.mockito.Mockito.mock
39 import static org.mockito.Mockito.when
40
41 @RunWith(MockitoJUnitRunner.class)
42 class CreateVfModuleInfraTest {
43
44     def prefix = "CVFMI_"
45     def requestInfo = "<requestInfo><request-id>12345</request-id></requestInfo>"
46
47     @Rule
48     public WireMockRule wireMockRule = new WireMockRule(28090)
49
50     @Captor
51     static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
52
53     @Before
54     void init() throws IOException {
55         MockitoAnnotations.initMocks(this);
56     }
57
58    @Test
59     void testPrepareUpdateInfraRequest() {
60         ExecutionEntity mockExecution = setupMock()
61         when(mockExecution.getVariable("prefix")).thenReturn(prefix)
62         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
63         when(mockExecution.getVariable(prefix + "vnfId")).thenReturn("12345")
64         when(mockExecution.getVariable(prefix + "requestInfo")).thenReturn(requestInfo)
65         when(mockExecution.getVariable(prefix + "vfModuleId")).thenReturn("12345")
66         when(mockExecution.getVariable(prefix + "vfModuleName")).thenReturn("12345")
67         when(mockExecution.getVariable("mso.adapters.openecomp.db.endpoint")).thenReturn("http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
68
69         CreateVfModuleInfra obj = new CreateVfModuleInfra()
70         obj.prepareUpdateInfraRequest(mockExecution)
71                 Mockito.verify(mockExecution).setVariable(prefix + "dbAdapterEndpoint", "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
72    }
73
74    
75    
76     private static ExecutionEntity setupMock() {
77         ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
78         when(mockProcessDefinition.getKey()).thenReturn("CreateVfModuleInfra")
79         RepositoryService mockRepositoryService = mock(RepositoryService.class)
80         when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
81         when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("CreateVfModuleInfra")
82         when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
83         ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
84         when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
85
86         ExecutionEntity mockExecution = mock(ExecutionEntity.class)
87         // Initialize prerequisite variables
88         when(mockExecution.getId()).thenReturn("100")
89         when(mockExecution.getProcessDefinitionId()).thenReturn("CreateVfModuleInfra")
90         when(mockExecution.getProcessInstanceId()).thenReturn("CreateVfModuleInfra")
91         when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
92         when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)
93
94         return mockExecution
95     }
96 }