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.infrastructure.scripts
23 import org.camunda.bpm.engine.delegate.BpmnError
24 import org.junit.Before
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.aaiclient.client.aai.AAIObjectType
31 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
32 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
34 import javax.ws.rs.NotFoundException
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
42 class CreateVFCNSResourceTest extends MsoGroovyTest{
45 CreateVFCNSResource createVFCNSResource
48 void init() throws IOException {
49 super.init("CreateVFCNSResource")
50 MockitoAnnotations.initMocks(this);
51 when(createVFCNSResource.getAAIClient()).thenReturn(client)
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)
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))
75 createVFCNSResource.addNSRelationship(mockExecution)
76 } catch (BpmnError ex) {
77 assertEquals(ex.getErrorCode(),"MSOWorkflowException")