a3b2a1c8b9503bf0cc6038d2c9c2a59b2b154943
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2018 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.infrastructure.scripts
22
23 import org.junit.Before
24 import org.junit.Test
25 import org.mockito.Mockito
26 import org.mockito.Spy
27 import org.onap.aai.domain.yang.AllottedResource
28 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
29 import org.onap.so.bpmn.mock.FileUtil
30 import org.onap.aaiclient.client.aai.AAIObjectType
31 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
32 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
33 import javax.ws.rs.core.UriBuilder
34 import static org.mockito.Mockito.times
35 import static org.mockito.Mockito.when
36
37 class DoCustomDeleteE2EServiceInstanceV2Test extends MsoGroovyTest {
38
39     @Spy
40     DoCustomDeleteE2EServiceInstanceV2 doCustomDeleteE2EServiceInstanceV2
41
42     @Before
43     void init(){
44         super.init("DoCustomDeleteE2EServiceInstanceV2")
45         Mockito.when(doCustomDeleteE2EServiceInstanceV2.getAAIClient()).thenReturn(client)
46     }
47
48     @Test
49     void testPrepareServiceDeleteResource(){
50         when(mockExecution.getVariable("serviceInstance")).thenReturn(FileUtil.readResourceFile("__files/AAI/ServiceInstanceWithAR.json"))
51         def relink = "/aai/v11/business/customers/customer/testCustIdInfra/service-subscriptions/service-subscription/HNPORTAL/service-instances/service-instance/testServiceInstanceIdPortalPri/allotted-resources/allotted-resource/testAllottedResourceIdPortalPri"
52         AAIResourceUri uri = AAIUriFactory.createResourceFromExistingURI(AAIObjectType.ALLOTTED_RESOURCE, UriBuilder.fromPath(relink).build())
53         AllottedResource ar = new AllottedResource();
54         ar.setId("ar1")
55         ar.setType("ar")
56         ar.setRole("ar")
57         ar.setResourceVersion("1234")
58         when(client.get(AllottedResource.class,uri)).thenReturn(Optional.of(ar))
59         doCustomDeleteE2EServiceInstanceV2.prepareServiceDeleteResource(mockExecution)
60         Mockito.verify(client, times(1)).get(AllottedResource.class,uri)
61     }
62 }