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 static org.mockito.Mockito.*
25 import javax.ws.rs.core.UriBuilder
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
29 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake
30 import org.junit.Assert
31 import org.junit.Before
33 import org.mockito.ArgumentCaptor
34 import org.mockito.Captor
35 import org.mockito.Mockito
36 import org.mockito.MockitoAnnotations
37 import org.mockito.Spy
38 import org.onap.aai.domain.yang.VolumeGroup
39 import org.onap.so.client.aai.AAIObjectType
40 import org.onap.so.client.aai.entities.uri.AAIResourceUri
41 import org.onap.so.client.aai.entities.uri.AAIUriFactory
43 class ConfirmVolumeGroupNameTest extends MsoGroovyTest {
46 private ConfirmVolumeGroupName confirmVolumeGroupName;
49 public void init() throws IOException {
50 super.init("ConfirmVolumeGroupName")
51 MockitoAnnotations.initMocks(this);
52 when(confirmVolumeGroupName.getAAIClient()).thenReturn(client)
57 public void testQueryAAIForVolumeGroupId() {
59 AAIResourceUri resourceUri = AAIUriFactory.createResourceFromExistingURI(AAIObjectType.VOLUME_GROUP, UriBuilder.fromPath('/aai/test/volume-groups/volume-group/testVolumeGroup').build());
60 when(mockExecution.getVariable("CVGN_volumeGroupGetEndpoint")).thenReturn(resourceUri)
61 VolumeGroup volumeGroup = new VolumeGroup()
62 volumeGroup.setVolumeGroupId("Test")
63 when(client.get(VolumeGroup.class,resourceUri)).thenReturn(Optional.of(volumeGroup))
64 confirmVolumeGroupName.queryAAIForVolumeGroupId(mockExecution)
65 Mockito.verify(mockExecution).setVariable("CVGN_queryVolumeGroupResponseCode",200)
66 Mockito.verify(mockExecution).setVariable("CVGN_queryVolumeGroupResponse",volumeGroup)
70 public void testQueryAAIForVolumeGroupId_404() {
71 AAIResourceUri resourceUri = AAIUriFactory.createResourceFromExistingURI(AAIObjectType.VOLUME_GROUP, UriBuilder.fromPath('/aai/test/volume-groups/volume-group/testVolumeGroup').build());
72 when(client.get(VolumeGroup.class, resourceUri)).thenReturn(Optional.empty())
73 DelegateExecution execution = new DelegateExecutionFake()
75 execution.setVariable("CVGN_volumeGroupGetEndpoint", resourceUri)
76 confirmVolumeGroupName.queryAAIForVolumeGroupId(execution)
79 Assert.assertEquals(404, execution.getVariable("CVGN_queryVolumeGroupResponseCode"))
80 Assert.assertEquals("Volume Group not Found!", execution.getVariable("CVGN_queryVolumeGroupResponse"))