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.infrastructure.scripts
24 import org.camunda.bpm.engine.delegate.BpmnError
25 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
26 import org.junit.Assert
27 import org.junit.Before
30 import org.junit.rules.ExpectedException
31 import org.junit.runner.RunWith
32 import org.mockito.ArgumentCaptor
33 import org.mockito.Captor
34 import org.mockito.MockitoAnnotations
35 import org.mockito.runners.MockitoJUnitRunner
36 import org.onap.aai.domain.yang.GenericVnf
37 import org.onap.aai.domain.yang.VfModule
38 import org.onap.aai.domain.yang.VolumeGroup
39 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
40 import org.onap.so.bpmn.mock.FileUtil
41 import org.onap.so.client.aai.AAIObjectType
42 import org.onap.so.client.aai.entities.AAIResultWrapper
43 import org.onap.so.client.aai.entities.uri.AAIResourceUri
44 import org.onap.so.client.aai.entities.uri.AAIUriFactory
45 import org.onap.so.constants.Defaults
47 import javax.ws.rs.core.UriBuilder
49 import static org.mockito.Mockito.*
51 @RunWith(MockitoJUnitRunner.class)
52 class UpdateVfModuleVolumeInfraV1Test extends MsoGroovyTest{
54 def prefix = "UPDVfModVol_"
56 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
59 public ExpectedException thrown = ExpectedException.none()
64 super.init("UpdateVfModuleVolumeInfraV1")
65 MockitoAnnotations.initMocks(this)
69 void testQueryAAIForVfModule() {
70 ExecutionEntity mockExecution = setupMock()
71 when(mockExecution.getVariable("prefix")).thenReturn(prefix)
72 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
73 when(mockExecution.getVariable("UPDVfModVol_relatedVfModuleLink")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf/12345/vf-modules/vf-module/12345")
74 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
75 when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7")
76 when(mockExecution.getVariable("aai.auth")).thenReturn("757A94191D685FD2092AC1490730A4FC")
78 UpdateVfModuleVolumeInfraV1 obj = spy(UpdateVfModuleVolumeInfraV1.class)
79 when(obj.getAAIClient()).thenReturn(client)
80 AAIResourceUri uri = AAIUriFactory.createResourceFromExistingURI(AAIObjectType.VF_MODULE, UriBuilder.fromPath("/aai/v8/network/generic-vnfs/generic-vnf/12345/vf-modules/vf-module/12345").build())
81 VfModule vfModule = new VfModule();
82 vfModule.setVfModuleId("12345")
83 vfModule.setModelInvariantId("ff5256d2-5a33-55df-13ab-12abad84e7ff")
84 when(client.get(VfModule.class,uri)).thenReturn(Optional.of(vfModule))
85 obj.queryAAIForVfModule(mockExecution, "true")
87 verify(mockExecution, atLeastOnce()).setVariable("UPDVfModVol_personaModelId", "ff5256d2-5a33-55df-13ab-12abad84e7ff")
91 void testQueryAAIForVolumeGroup() {
92 String aicCloudRegion = "aicCloudRegionId"
93 String volumeGroupId = "volumeGroupId"
94 when(mockExecution.getVariable("UPDVfModVol_volumeGroupId")).thenReturn(volumeGroupId)
95 when(mockExecution.getVariable("UPDVfModVol_aicCloudRegion")).thenReturn(aicCloudRegion)
97 UpdateVfModuleVolumeInfraV1 obj = spy(UpdateVfModuleVolumeInfraV1.class)
98 when(obj.getAAIClient()).thenReturn(client)
99 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), aicCloudRegion, volumeGroupId)
100 VolumeGroup volumeGroup = new VolumeGroup();
101 volumeGroup.setVolumeGroupId(volumeGroupId)
103 AAIResultWrapper wrapper = new AAIResultWrapper(FileUtil.readResourceFile("__files/aai/VolumeGroupWithTenant.json"))
104 when(client.get(uri)).thenReturn(wrapper)
105 thrown.expect(BpmnError.class)
106 obj.queryAAIForVolumeGroup(mockExecution, "true")
110 void testQueryAAIForGenericVnf() {
111 String vnfId = "vnfId"
112 when(mockExecution.getVariable("vnfId")).thenReturn(vnfId)
114 UpdateVfModuleVolumeInfraV1 obj = spy(UpdateVfModuleVolumeInfraV1.class)
115 when(obj.getAAIClient()).thenReturn(client)
117 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
118 GenericVnf genericVnf = new GenericVnf()
119 genericVnf.setVnfId(vnfId)
120 genericVnf.setVnfName("testvnfName")
121 when(client.get(GenericVnf.class,uri)).thenReturn(Optional.of(genericVnf))
122 obj.queryAAIForGenericVnf(mockExecution, "true")
123 verify(mockExecution).setVariable("UPDVfModVol_AAIQueryGenericVfnResponse", genericVnf)
127 void testQueryAAIForGenericVnfNodata() {
128 String vnfId = "vnfId"
129 when(mockExecution.getVariable("vnfId")).thenReturn(vnfId)
131 UpdateVfModuleVolumeInfraV1 obj = spy(UpdateVfModuleVolumeInfraV1.class)
132 when(obj.getAAIClient()).thenReturn(client)
134 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
135 when(client.get(GenericVnf.class,uri)).thenReturn(Optional.empty())
136 thrown.expect(BpmnError.class)
137 obj.queryAAIForGenericVnf(mockExecution, "true")
138 verify(mockExecution).setVariable("UPDVfModVol_AAIQueryGenericVfnResponse", genericVnf)
142 void testPrepVnfAdapterRest() {
143 when(mockExecution.getVariable("prefix")).thenReturn(prefix)
144 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
145 when(mockExecution.getVariable(prefix + "aicCloudRegion")).thenReturn("RDM2WAGPLCP")
146 when(mockExecution.getVariable(prefix + "tenantId")).thenReturn("")
147 VolumeGroup volumeGroup = new VolumeGroup();
148 volumeGroup.setHeatStackId("heatStackId")
149 when(mockExecution.getVariable(prefix + "aaiVolumeGroupResponse")).thenReturn(volumeGroup)
150 when(mockExecution.getVariable(prefix + "vnfType")).thenReturn("vnf1")
151 when(mockExecution.getVariable(prefix + "vnfVersion")).thenReturn("1")
152 GenericVnf genericVnf = new GenericVnf()
153 genericVnf.setVnfId("vnfId")
154 genericVnf.setVnfName("testvnfName")
155 when(mockExecution.getVariable(prefix + "AAIQueryGenericVfnResponse")).thenReturn(genericVnf)
156 when(mockExecution.getVariable(prefix + "requestId")).thenReturn("12345")
157 when(mockExecution.getVariable(prefix + "serviceId")).thenReturn("12345")
158 when(mockExecution.getVariable("mso-request-id")).thenReturn("12345")
159 when(mockExecution.getVariable("mso.workflow.message.endpoint")).thenReturn('http://localhost:28080/mso/WorkflowMessage')
160 when(mockExecution.getVariable("mso.use.qualified.host")).thenReturn("true")
162 UpdateVfModuleVolumeInfraV1 obj = new UpdateVfModuleVolumeInfraV1()
163 obj.prepVnfAdapterRest(mockExecution, "true")
165 verify(mockExecution, times(1)).setVariable(captor.capture(), captor.capture())
166 String updateVolumeGroupRequest = captor.getValue()
167 Assert.assertTrue(updateVolumeGroupRequest.contains("testvnfName"))