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.ConfirmVolumeGroupTenant
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 ConfirmVolumeGroupTenantTest extends MsoGroovyTest {
65 ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class);
68 public WireMockRule wireMockRule = new WireMockRule(8090);
71 public void testpreProcessRequest() {
72 ExecutionEntity mockExecution = setupMock()
73 when(mockExecution.getVariable("aai.endpoint")).thenReturn('http://localhost:8090')
74 when(mockExecution.getVariable("volumeGroupId")).thenReturn('testVolumeGroupId')
75 when(mockExecution.getVariable("volumeGroupName")).thenReturn('testVolumeGroupName')
76 when(mockExecution.getVariable("tenantId")).thenReturn('tenantId')
77 when(mockExecution.getVariable("aicCloudRegion")).thenReturn('aicCloudRegion')
78 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
79 when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8')
80 when(mockExecution.getVariable("mso.workflow.default.aai.v8.cloud-region.uri")).thenReturn('/aai/v8/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner')
81 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/')
87 ConfirmVolumeGroupTenant confirmVolumeGroupTenant = new ConfirmVolumeGroupTenant()
88 confirmVolumeGroupTenant.preProcessRequest(mockExecution)
89 /* Mockito.verify(mockExecution, times(5)).setVariable(captor.capture(), captor.capture())*/
90 verify(mockExecution).setVariable("prefix", "CVGT_")
91 verify(mockExecution).setVariable("queryVolumeGroupResponseCode", 200)
92 verify(mockExecution).setVariable("queryAAIVolumeGroupResponse", "<volume-group xmlns=\"http://org.openecomp.aai.inventory/v10\"><volume-group-id>17ef4658-bd1f-4ef0-9ca0-ea76e2bf122c</volume-group-id><volume-group-name>MSOTESTVOL103a-vSAMP12_base_module-0_vol</volume-group-name><heat-stack-id>9d1f53e3-3158-44f8-8032-a6bf40bbc9db</heat-stack-id><vnf-type>pcrf-capacity</vnf-type><orchestration-status>Active</orchestration-status><resource-version>0000020</resource-version><relationship-list><relationship><related-to>tenant</related-to><relationship-data><relationship-key>cloud-region.cloud-owner</relationship-key><relationship-value>CloudOwner</relationship-value></relationship-data><relationship-data><relationship-key>cloud-region.cloud-region-id</relationship-key><relationship-value>RegionOne</relationship-value></relationship-data><relationship-data><relationship-key>tenant.tenant-id</relationship-key><relationship-value>22eb191dd41a4f3c9be370fc638322f4</relationship-value></relationship-data></relationship></relationship-list></volume-group>")
93 verify(mockExecution).setVariable("tenantIdsMatch", false)
94 verify(mockExecution).setVariable("groupNamesMatch", false)
98 private void mockData() {
99 stubFor(get(urlMatching("/aai/v8/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/aicCloudRegion/volume-groups/volume-group/testVolumeGroupId"))
100 .willReturn(aResponse()
102 .withBody("<volume-group xmlns=\"http://org.openecomp.aai.inventory/v10\"><volume-group-id>17ef4658-bd1f-4ef0-9ca0-ea76e2bf122c</volume-group-id><volume-group-name>MSOTESTVOL103a-vSAMP12_base_module-0_vol</volume-group-name><heat-stack-id>9d1f53e3-3158-44f8-8032-a6bf40bbc9db</heat-stack-id><vnf-type>pcrf-capacity</vnf-type><orchestration-status>Active</orchestration-status><resource-version>0000020</resource-version><relationship-list><relationship><related-to>tenant</related-to><relationship-data><relationship-key>cloud-region.cloud-owner</relationship-key><relationship-value>CloudOwner</relationship-value></relationship-data><relationship-data><relationship-key>cloud-region.cloud-region-id</relationship-key><relationship-value>RegionOne</relationship-value></relationship-data><relationship-data><relationship-key>tenant.tenant-id</relationship-key><relationship-value>22eb191dd41a4f3c9be370fc638322f4</relationship-value></relationship-data></relationship></relationship-list></volume-group>")))
105 private ExecutionEntity setupMock() {
107 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
108 when(mockProcessDefinition.getKey()).thenReturn("ConfirmVolumeGroupTenant")
109 RepositoryService mockRepositoryService = mock(RepositoryService.class)
110 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
111 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("ConfirmVolumeGroupTenant")
112 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
113 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
114 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
116 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
117 when(mockExecution.getId()).thenReturn("100")
118 when(mockExecution.getProcessDefinitionId()).thenReturn("ConfirmVolumeGroupTenant")
119 when(mockExecution.getProcessInstanceId()).thenReturn("ConfirmVolumeGroupTenant")
120 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
121 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)