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
33 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
34 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
36 import javax.ws.rs.NotFoundException
38 import static org.junit.Assert.assertEquals
39 import static org.mockito.ArgumentMatchers.isA
40 import static org.mockito.Mockito.doNothing
41 import static org.mockito.Mockito.doThrow
42 import static org.mockito.Mockito.when
44 class CreateVFCNSResourceTest extends MsoGroovyTest{
47 CreateVFCNSResource createVFCNSResource
50 void init() throws IOException {
51 super.init("CreateVFCNSResource")
52 MockitoAnnotations.initMocks(this);
53 when(createVFCNSResource.getAAIClient()).thenReturn(client)
57 void testaddNSRelationship(){
58 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("globalSubscriberId1")
59 when(mockExecution.getVariable("serviceType")).thenReturn("serviceType")
60 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("serviceInstanceId")
61 when(mockExecution.getVariable("nsInstanceId")).thenReturn("nsInstanceId")
62 doNothing().when(client).connect(isA(AAIResourceUri.class),isA(AAIResourceUri.class))
63 createVFCNSResource.addNSRelationship(mockExecution)
64 AAIResourceUri nsUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("globalSubscriberId1").serviceSubscription("serviceType").serviceInstance("nsInstanceId"))
65 AAIResourceUri relatedServiceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("globalSubscriberId1").serviceSubscription("serviceType").serviceInstance("serviceInstanceId"))
66 Mockito.verify(client).connect(nsUri,relatedServiceUri)
70 void testaddNSRelationshipError(){
71 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("globalSubscriberId1")
72 when(mockExecution.getVariable("serviceType")).thenReturn("serviceType")
73 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("serviceInstanceId")
74 when(mockExecution.getVariable("nsInstanceId")).thenReturn("nsInstanceId")
75 doThrow(new NotFoundException("Error creating relationship")).when(client).connect(isA(AAIResourceUri.class),isA(AAIResourceUri.class))
77 createVFCNSResource.addNSRelationship(mockExecution)
78 } catch (BpmnError ex) {
79 assertEquals(ex.getErrorCode(),"MSOWorkflowException")