2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.common.scripts
23 import com.github.tomakehurst.wiremock.junit.WireMockRule
25 import static org.junit.Assert.*;
26 import static org.mockito.Mockito.*
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;
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
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
57 import static com.github.tomakehurst.wiremock.client.WireMock.*
58 import static org.mockito.Mockito.*
60 @RunWith(MockitoJUnitRunner.class)
62 class ConfirmVolumeGroupNameTest extends MsoGroovyTest {
65 ArgumentCaptor<ExecutionEntity> captor= ArgumentCaptor.forClass(ExecutionEntity.class);
68 public WireMockRule wireMockRule = new WireMockRule(8090);
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')
79 ConfirmVolumeGroupName confirmVolumeGroupName = new ConfirmVolumeGroupName()
80 confirmVolumeGroupName.queryAAIForVolumeGroupId(mockExecution)
81 verify(mockExecution).setVariable("CVGN_queryVolumeGroupResponseCode",200)
82 verify(mockExecution).setVariable("CVGN_queryVolumeGroupResponse","")
86 public void testQueryAAIForVolumeGroupId_404() {
88 ExecutionEntity mockExecution = setupMock()
90 when(mockExecution.getVariable("CVGN_volumeGroupGetEndpoint")).thenReturn('/aai/test/volume-groups/volume-group/testVolumeGroup')
91 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
95 ConfirmVolumeGroupName confirmVolumeGroupName = new ConfirmVolumeGroupName()
96 confirmVolumeGroupName.queryAAIForVolumeGroupId(mockExecution)
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())
106 private void mockData() {
107 stubFor(get(urlMatching("/aai/test/volume-groups/volume-group/testVolumeGroup"))
108 .willReturn(aResponse()
112 private ExecutionEntity setupMock() {
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)