a96127aa2d4136f6bd58ebc63603bfad7f9189ab
[so.git] /
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 org.mockito.Mockito.*
24
25 import javax.ws.rs.core.UriBuilder
26
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
32 import org.junit.Test
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
42
43 class ConfirmVolumeGroupNameTest extends MsoGroovyTest {
44         
45         @Spy
46         private ConfirmVolumeGroupName confirmVolumeGroupName;
47
48         @Before
49         public void init() throws IOException {
50                 super.init("ConfirmVolumeGroupName")
51                 MockitoAnnotations.initMocks(this);
52                 when(confirmVolumeGroupName.getAAIClient()).thenReturn(client)
53
54         }
55
56         @Test
57         public void testQueryAAIForVolumeGroupId() {
58
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)
67         }
68
69         @Test
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()
74                 try {
75                         execution.setVariable("CVGN_volumeGroupGetEndpoint", resourceUri)
76                         confirmVolumeGroupName.queryAAIForVolumeGroupId(execution)
77                 }
78                 catch(Exception ex){}
79                 Assert.assertEquals(404, execution.getVariable("CVGN_queryVolumeGroupResponseCode"))
80                 Assert.assertEquals("Volume Group not Found!", execution.getVariable("CVGN_queryVolumeGroupResponse"))
81                 
82         }
83 }