2 * ============LICENSE_START=======================================================
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
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 org.camunda.bpm.engine.delegate.DelegateExecution
24 import org.junit.Before
25 import org.junit.Ignore
27 import org.mockito.Mockito
28 import org.mockito.internal.stubbing.answers.DoesNothing
29 import org.onap.aai.domain.yang.AllottedResource
30 import org.onap.so.client.aai.AAIObjectType
31 import org.onap.so.client.aai.entities.AAIResultWrapper
32 import org.onap.so.client.aai.entities.uri.AAIResourceUri
33 import org.onap.so.client.aai.entities.uri.AAIUriFactory
34 import javax.ws.rs.core.UriBuilder
35 import static org.junit.Assert.assertEquals
36 import static org.junit.Assert.assertTrue
37 import static org.mockito.ArgumentMatchers.any
38 import static org.mockito.ArgumentMatchers.anyObject
39 import static org.mockito.ArgumentMatchers.isA
40 import static org.mockito.Mockito.atLeastOnce
41 import static org.mockito.Mockito.doNothing
42 import static org.mockito.Mockito.doThrow
43 import static org.mockito.Mockito.mock
44 import static org.mockito.Mockito.spy
45 import static org.mockito.Mockito.verify
46 import static org.mockito.Mockito.when
49 class AllottedResourceUtilsTest extends MsoGroovyTest{
51 private static final String ALLOTTED_RESOURSE_URI = "/aai/v11/business/customers/customer/MSO-MUX-User/service-subscriptions/service-subscription/MSO-vCB/service-instances/service-instance/a1f53c6a-81a3-4e44-a900-d64f3b131d35/allotted-resources/allotted-resource/ID"
53 AllottedResourceUtils allottedResourceUtils
57 super.init("AllottedResourceUtils")
58 allottedResourceUtils = spy(new AllottedResourceUtils(mock(AbstractServiceTaskProcessor.class)))
59 when(allottedResourceUtils.getAAIClient()).thenReturn(client)
65 String allottedResourceId = "allottedResourceId"
66 AllottedResource expectedAllottedResource = new AllottedResource()
67 expectedAllottedResource.setId("ID")
68 expectedAllottedResource.setResourceVersion("1.2")
69 when(client.get(any(AAIResourceUri.class))).thenReturn(new AAIResultWrapper(expectedAllottedResource))
70 AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.ALLOTTED_RESOURCE, allottedResourceId)
71 when(allottedResourceUtils.setExecutionVariables(mockExecution,expectedAllottedResource,resourceUri)).thenAnswer(new DoesNothing())
72 boolean allottedResource = allottedResourceUtils.ifExistsAR(mockExecution,allottedResourceId)
73 assertTrue(allottedResource)
78 println "************ testGetARbyLink ************* "
80 AllottedResource expectedAllottedResource = new AllottedResource()
81 expectedAllottedResource.setId("ID")
82 AAIResourceUri uri = AAIUriFactory.createResourceFromExistingURI(AAIObjectType.ALLOTTED_RESOURCE, UriBuilder.fromPath(ALLOTTED_RESOURSE_URI).build())
83 when(client.get(AllottedResource.class, uri)).thenReturn(Optional.of(expectedAllottedResource))
84 Optional<AllottedResource> allottedResource = allottedResourceUtils.getARbyLink(mockExecution, ALLOTTED_RESOURSE_URI,"")
85 assertEquals(expectedAllottedResource.getId(),allottedResource.get().getId())
89 void updateAROrchStatus() {
90 allottedResourceUtils.updateAROrchStatus(mockExecution,"PENDING",ALLOTTED_RESOURSE_URI)
95 allottedResourceUtils.deleteAR(mockExecution,ALLOTTED_RESOURSE_URI)
96 verify(mockExecution,atLeastOnce()).setVariable("wasDeleted","true")