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