replace all fixed wiremock ports
[so.git] / bpmn / so-bpmn-infrastructure-common / 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     @Captor
48     static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
49
50     @Before
51     void init() throws IOException {
52         MockitoAnnotations.initMocks(this);
53     }
54
55    @Test
56     void testPrepareUpdateInfraRequest() {
57         ExecutionEntity mockExecution = setupMock()
58         when(mockExecution.getVariable("prefix")).thenReturn(prefix)
59         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
60         when(mockExecution.getVariable(prefix + "vnfId")).thenReturn("12345")
61         when(mockExecution.getVariable(prefix + "requestInfo")).thenReturn(requestInfo)
62         when(mockExecution.getVariable(prefix + "vfModuleId")).thenReturn("12345")
63         when(mockExecution.getVariable(prefix + "vfModuleName")).thenReturn("12345")
64         when(mockExecution.getVariable("mso.adapters.openecomp.db.endpoint")).thenReturn("http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
65
66         CreateVfModuleInfra obj = new CreateVfModuleInfra()
67         obj.prepareUpdateInfraRequest(mockExecution)
68                 Mockito.verify(mockExecution).setVariable(prefix + "dbAdapterEndpoint", "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
69    }
70
71    
72    
73     private static ExecutionEntity setupMock() {
74         ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
75         when(mockProcessDefinition.getKey()).thenReturn("CreateVfModuleInfra")
76         RepositoryService mockRepositoryService = mock(RepositoryService.class)
77         when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
78         when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("CreateVfModuleInfra")
79         when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
80         ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
81         when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
82
83         ExecutionEntity mockExecution = mock(ExecutionEntity.class)
84         // Initialize prerequisite variables
85         when(mockExecution.getId()).thenReturn("100")
86         when(mockExecution.getProcessDefinitionId()).thenReturn("CreateVfModuleInfra")
87         when(mockExecution.getProcessInstanceId()).thenReturn("CreateVfModuleInfra")
88         when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
89         when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)
90
91         return mockExecution
92     }
93 }