Removed deprecated Matcher imports
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / groovy / org / onap / so / bpmn / infrastructure / scripts / CreateVFCNSResourceTest.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.infrastructure.scripts
22
23 import org.camunda.bpm.engine.delegate.BpmnError
24 import org.junit.Before
25 import org.junit.Test
26 import org.mockito.Mockito
27 import org.mockito.MockitoAnnotations
28 import org.mockito.Spy
29 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
30 import org.onap.so.client.aai.AAIObjectType
31 import org.onap.so.client.aai.entities.uri.AAIResourceUri
32 import org.onap.so.client.aai.entities.uri.AAIUriFactory
33
34 import javax.ws.rs.NotFoundException
35
36 import static org.junit.Assert.assertEquals
37 import static org.mockito.ArgumentMatchers.isA
38 import static org.mockito.Mockito.doNothing
39 import static org.mockito.Mockito.doThrow
40 import static org.mockito.Mockito.when
41
42 class CreateVFCNSResourceTest extends MsoGroovyTest{
43
44     @Spy
45     CreateVFCNSResource createVFCNSResource
46
47     @Before
48     void init() throws IOException {
49         super.init("CreateVFCNSResource")
50         MockitoAnnotations.initMocks(this);
51         when(createVFCNSResource.getAAIClient()).thenReturn(client)
52     }
53
54     @Test
55     void testaddNSRelationship(){
56         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("globalSubscriberId1")
57         when(mockExecution.getVariable("serviceType")).thenReturn("serviceType")
58         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("serviceInstanceId")
59         when(mockExecution.getVariable("nsInstanceId")).thenReturn("nsInstanceId")
60         doNothing().when(client).connect(isA(AAIResourceUri.class),isA(AAIResourceUri.class))
61         createVFCNSResource.addNSRelationship(mockExecution)
62         AAIResourceUri nsUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,"globalSubscriberId1","serviceType","nsInstanceId")
63         AAIResourceUri relatedServiceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,"globalSubscriberId1","serviceType","serviceInstanceId")
64         Mockito.verify(client).connect(nsUri,relatedServiceUri)
65     }
66
67     @Test
68     void testaddNSRelationshipError(){
69         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("globalSubscriberId1")
70         when(mockExecution.getVariable("serviceType")).thenReturn("serviceType")
71         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("serviceInstanceId")
72         when(mockExecution.getVariable("nsInstanceId")).thenReturn("nsInstanceId")
73         doThrow(new NotFoundException("Error creating relationship")).when(client).connect(isA(AAIResourceUri.class),isA(AAIResourceUri.class))
74         try {
75             createVFCNSResource.addNSRelationship(mockExecution)
76         } catch (BpmnError ex) {
77             assertEquals(ex.getErrorCode(),"MSOWorkflowException")
78         }
79     }
80
81 }