Removed deprecated Matcher imports
[so.git] / bpmn / MSOCommonBPMN / src / test / groovy / org / onap / so / bpmn / common / scripts / AllottedResourceUtilsTest.groovy
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.common.scripts
22
23 import org.camunda.bpm.engine.delegate.DelegateExecution
24 import org.junit.Before
25 import org.junit.Ignore
26 import org.junit.Test
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
47
48
49 class AllottedResourceUtilsTest extends MsoGroovyTest{
50
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"
52
53     AllottedResourceUtils allottedResourceUtils
54
55     @Before
56     void init(){
57         super.init("AllottedResourceUtils")
58         allottedResourceUtils = spy(new AllottedResourceUtils(mock(AbstractServiceTaskProcessor.class)))
59         when(allottedResourceUtils.getAAIClient()).thenReturn(client)
60     }
61
62     @Test
63     @Ignore
64     void getARbyId() {
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)
74     }
75
76     @Test
77     void getARbyLink() {
78         println "************ testGetARbyLink ************* "
79
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())
86     }
87
88     @Test
89     void updateAROrchStatus() {
90         allottedResourceUtils.updateAROrchStatus(mockExecution,"PENDING",ALLOTTED_RESOURSE_URI)
91     }
92
93     @Test
94     void deleteAR() {
95         allottedResourceUtils.deleteAR(mockExecution,ALLOTTED_RESOURSE_URI)
96         verify(mockExecution,atLeastOnce()).setVariable("wasDeleted","true")
97     }
98
99 }