Containerization feature of SO
[so.git] / bpmn / MSOCommonBPMN / src / test / groovy / org / onap / so / bpmn / common / scripts / ConfirmVolumeGroupNameTest.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.common.scripts
22
23 import com.github.tomakehurst.wiremock.junit.WireMockRule
24
25 import static org.junit.Assert.*;
26 import static org.mockito.Mockito.*
27
28 import org.onap.so.rest.HttpHeader
29 import org.mockito.MockitoAnnotations
30 import org.mockito.runners.MockitoJUnitRunner
31 import org.mockito.internal.debugging.MockitoDebuggerImpl
32 import org.junit.Before
33 import org.onap.so.bpmn.common.scripts.AaiUtil;
34 import org.junit.Rule;
35 import org.junit.Test
36 import org.junit.Ignore
37 import org.junit.runner.RunWith
38 import org.junit.Before;
39 import org.junit.Test;
40 import org.camunda.bpm.engine.ProcessEngineServices
41 import org.camunda.bpm.engine.RepositoryService
42 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
43 import org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl
44 import org.camunda.bpm.engine.repository.ProcessDefinition
45 import org.junit.Assert
46 import org.junit.Before
47 import org.junit.Rule
48 import org.junit.Test
49 import org.junit.runner.RunWith
50 import org.mockito.ArgumentCaptor
51 import org.mockito.Captor
52 import org.mockito.Mockito
53 import org.mockito.runners.MockitoJUnitRunner
54 import org.onap.so.bpmn.common.scripts.ConfirmVolumeGroupName
55 import org.onap.so.bpmn.core.WorkflowException
56
57 import static com.github.tomakehurst.wiremock.client.WireMock.*
58 import static org.mockito.Mockito.*
59
60 @RunWith(MockitoJUnitRunner.class)
61 @Ignore
62 class ConfirmVolumeGroupNameTest extends MsoGroovyTest {
63
64         @Captor
65         ArgumentCaptor<ExecutionEntity> captor=  ArgumentCaptor.forClass(ExecutionEntity.class);
66
67         @Rule
68         public WireMockRule wireMockRule = new WireMockRule(8090);
69
70         @Test
71         public void testQueryAAIForVolumeGroupId() {
72                 ExecutionEntity mockExecution = setupMock()
73                 when(mockExecution.getVariable("aai.endpoint")).thenReturn('http://localhost:8090')
74                 when(mockExecution.getVariable("CVGN_volumeGroupGetEndpoint")).thenReturn('/aai/test/volume-groups/volume-group/testVolumeGroup')
75                 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
76
77                 mockData()
78
79                 ConfirmVolumeGroupName confirmVolumeGroupName = new ConfirmVolumeGroupName()
80                 confirmVolumeGroupName.queryAAIForVolumeGroupId(mockExecution)
81                 verify(mockExecution).setVariable("CVGN_queryVolumeGroupResponseCode",200)
82                 verify(mockExecution).setVariable("CVGN_queryVolumeGroupResponse","")
83         }
84
85         @Test
86         public void testQueryAAIForVolumeGroupId_404() {
87
88                 ExecutionEntity mockExecution = setupMock()
89                 try {
90                         when(mockExecution.getVariable("CVGN_volumeGroupGetEndpoint")).thenReturn('/aai/test/volume-groups/volume-group/testVolumeGroup')
91                         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
92
93                         mockData()
94
95                         ConfirmVolumeGroupName confirmVolumeGroupName = new ConfirmVolumeGroupName()
96                         confirmVolumeGroupName.queryAAIForVolumeGroupId(mockExecution)
97                 }
98                 catch(Exception ex){
99
100                 }
101                 Mockito.verify(mockExecution,times(4)).setVariable(captor.capture(),captor.capture())
102                 WorkflowException workflowException = captor.getValue()
103                 Assert.assertEquals("AAI GET Failed",workflowException.getErrorMessage())
104                 Assert.assertEquals(500,workflowException.getErrorCode())
105         }
106         private void  mockData() {
107                 stubFor(get(urlMatching("/aai/test/volume-groups/volume-group/testVolumeGroup"))
108                                 .willReturn(aResponse()
109                                 .withStatus(200)))
110         }
111
112         private ExecutionEntity setupMock() {
113
114                 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
115                 when(mockProcessDefinition.getKey()).thenReturn("ConfirmVolumeGroupName")
116                 RepositoryService mockRepositoryService = mock(RepositoryService.class)
117                 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
118                 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("ConfirmVolumeGroupName")
119                 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
120                 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
121                 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
122                 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
123                 when(mockExecution.getId()).thenReturn("100")
124                 when(mockExecution.getProcessDefinitionId()).thenReturn("ConfirmVolumeGroupName")
125                 when(mockExecution.getProcessInstanceId()).thenReturn("ConfirmVolumeGroupName")
126                 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
127                 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)
128                 return mockExecution
129         }
130 }