replace all fixed wiremock ports
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / groovy / org / onap / so / bpmn / infrastructure / scripts / DoCreateVnfTest.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.Assert
29 import org.junit.Before
30 import org.junit.Rule
31 import org.junit.Test
32 import org.junit.runner.RunWith
33 import org.mockito.ArgumentCaptor
34 import org.mockito.Captor
35 import org.mockito.Mockito
36 import org.mockito.MockitoAnnotations
37 import org.mockito.runners.MockitoJUnitRunner
38 import org.onap.so.bpmn.core.WorkflowException
39 import org.onap.so.bpmn.core.domain.VnfResource
40
41 import static org.mockito.Mockito.*
42
43 @RunWith(MockitoJUnitRunner.class)
44 class DoCreateVnfTest {
45     def prefix = "DoCVNF_"
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 testPreProcessRequest() {
57         ExecutionEntity mockExecution = setupMock()
58         when(mockExecution.getVariable("prefix")).thenReturn(prefix)
59         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
60         when(mockExecution.getVariable("msoRequestId")).thenReturn("12345")
61         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("MIS/1604/0026/SW_INTERNET")
62         when(mockExecution.getVariable("vnfType")).thenReturn("vRRaas")
63         when(mockExecution.getVariable("vnfName")).thenReturn("skask-test")
64
65         when(mockExecution.getVariable("productFamilyId")).thenReturn("RDM2WAGPLCP")
66         when(mockExecution.getVariable("lcpCloudRegionId")).thenReturn("MDTWNJ21")
67
68         when(mockExecution.getVariable("vnfResourceDecomposition")).thenReturn(new VnfResource())
69         when(mockExecution.getVariable("mso-request-id")).thenReturn("testRequestId-1503410089303")
70         when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://localhost:28080/mso/SDNCAdapterCallbackService")
71
72
73
74         DoCreateVnf obj = new DoCreateVnf()
75         obj.preProcessRequest(mockExecution)
76
77         Mockito.verify(mockExecution, times(31)).setVariable(captor.capture(), captor.capture())
78         List list = captor.getAllValues()
79         String str = list.get(51)
80         Assert.assertEquals("http://localhost:28080/mso/SDNCAdapterCallbackService", str)
81     }
82  
83     private static ExecutionEntity setupMock() {
84         ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
85         when(mockProcessDefinition.getKey()).thenReturn("DoCreateVnf")
86         RepositoryService mockRepositoryService = mock(RepositoryService.class)
87         when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
88         when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("DoCreateVnf")
89         when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
90         ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
91         when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
92
93         ExecutionEntity mockExecution = mock(ExecutionEntity.class)
94         // Initialize prerequisite variables
95         when(mockExecution.getId()).thenReturn("100")
96         when(mockExecution.getProcessDefinitionId()).thenReturn("DoCreateVnf")
97         when(mockExecution.getProcessInstanceId()).thenReturn("DoCreateVnf")
98         when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
99         when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)
100
101         return mockExecution
102     }
103 }