Springboot 2.0 upgrade
[so.git] / bpmn / MSOCommonBPMN / src / test / groovy / org / onap / so / bpmn / common / scripts / ConfirmVolumeGroupTenantTest.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 static com.shazam.shazamcrest.MatcherAssert.assertThat
24 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs
25 import static org.mockito.Mockito.spy
26 import static org.mockito.Mockito.times
27 import static org.mockito.Mockito.when
28
29 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
30 import org.junit.Before
31 import org.junit.Test
32 import org.mockito.ArgumentCaptor
33 import org.mockito.Captor
34 import org.mockito.Mockito
35 import org.onap.aai.domain.yang.Relationship
36 import org.onap.aai.domain.yang.RelationshipData
37 import org.onap.aai.domain.yang.RelationshipList
38 import org.onap.aai.domain.yang.VolumeGroup
39 import org.onap.so.client.aai.AAIObjectType
40 import org.onap.so.client.aai.entities.AAIResultWrapper
41 import org.onap.so.client.aai.entities.uri.AAIResourceUri
42 import org.onap.so.client.aai.entities.uri.AAIUriFactory
43 import org.onap.so.constants.Defaults
44
45 class ConfirmVolumeGroupTenantTest extends MsoGroovyTest {
46
47     @Captor
48     static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
49
50     @Before
51     public void init(){
52         super.init("ConfirmVolumeGroupTenant")
53     }
54     @Test
55     void testpreProcessRequest() {
56         VolumeGroup expectedVolumeGroup = new VolumeGroup();
57         expectedVolumeGroup.setVolumeGroupId("VolumeGroupId")
58         RelationshipList relationshipList = new RelationshipList();
59         Relationship relationship = new Relationship();
60         relationship.setRelatedTo("tenant")
61         RelationshipData data = new RelationshipData();
62         data.setRelationshipKey("tenant.tenant-id")
63         data.setRelationshipValue("tenantId")
64         relationship.setRelatedLink("/cloud-infrastructure/cloud-regions/cloud-region/" + Defaults.CLOUD_OWNER.toString() + "/cloudRegionId/tenants/tenant/tenantId")
65         relationship.getRelationshipData().add(data)
66         relationshipList.getRelationship().add(relationship)
67         expectedVolumeGroup.setRelationshipList(relationshipList)
68         
69         
70         expectedVolumeGroup.setRelationshipList(relationshipList)
71         ConfirmVolumeGroupTenant confirmVolumeGroupTenant = spy(ConfirmVolumeGroupTenant.class)
72         when(confirmVolumeGroupTenant.getAAIClient()).thenReturn(client)
73         when(mockExecution.getVariable("aicCloudRegion")).thenReturn("aicCloudRegionId");
74         when(mockExecution.getVariable("volumeGroupId")).thenReturn("volumeGroupId");
75         when(mockExecution.getVariable("aai.endpoint")).thenReturn('http://localhost:8090')
76         when(mockExecution.getVariable("volumeGroupName")).thenReturn('testVolumeGroupName')
77         when(mockExecution.getVariable("tenantId")).thenReturn('tenantId')
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/')
82         AAIResourceUri arURI = AAIUriFactory. createResourceUri(AAIObjectType.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), "aicCloudRegionId","volumeGroupId")
83         AAIResultWrapper wrapper = new AAIResultWrapper(expectedVolumeGroup)
84         when(client.get(arURI)).thenReturn(wrapper)
85         confirmVolumeGroupTenant.preProcessRequest(mockExecution)
86         Mockito.verify(mockExecution, times(4)).setVariable(captor.capture(), captor.capture())
87         List<ExecutionEntity> executionEntities = captor.getAllValues()
88
89         assertThat(executionEntities.get(3), sameBeanAs(expectedVolumeGroup))
90     }
91 }