2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 com.github.tomakehurst.wiremock.junit.WireMockRule
24 import org.camunda.bpm.engine.delegate.BpmnError
25 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
26 import org.junit.Before
29 import org.mockito.ArgumentCaptor
30 import org.mockito.Captor
31 import org.mockito.Mockito
32 import org.mockito.MockitoAnnotations
33 import org.mockito.Spy
34 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
35 import org.onap.aaiclient.client.aai.AAIObjectType
36 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
37 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
38 import javax.ws.rs.NotFoundException
39 import static org.junit.Assert.assertEquals
40 import static org.mockito.ArgumentMatchers.isA
41 import static org.mockito.Mockito.doNothing
42 import static org.mockito.Mockito.doThrow
43 import static org.mockito.Mockito.when
45 class DoCreateVFCNetworkServiceInstanceTest extends MsoGroovyTest {
48 DoCreateVFCNetworkServiceInstance doCreateVFCNetworkServiceInstance
51 public void init() throws IOException {
52 super.init("CreateVFCNSResource")
53 MockitoAnnotations.initMocks(this)
54 when(doCreateVFCNetworkServiceInstance.getAAIClient()).thenReturn(client)
58 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
61 public void testAddNSRelationship(){
62 when(mockExecution.getVariable("nsInstanceId")).thenReturn("NS12345")
63 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("MSO_dev")
64 when(mockExecution.getVariable("serviceType")).thenReturn("MSO-dev-service-type")
65 when(mockExecution.getVariable("serviceId")).thenReturn("SER12345")
66 doNothing().when(client).connect(isA(AAIResourceUri.class),isA(AAIResourceUri.class))
67 doCreateVFCNetworkServiceInstance.addNSRelationship(mockExecution);
68 AAIResourceUri nsUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,"MSO_dev","MSO-dev-service-type","NS12345")
69 AAIResourceUri relatedServiceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,"MSO_dev","MSO-dev-service-type","SER12345")
70 Mockito.verify(client).connect(nsUri,relatedServiceUri)
74 void testaddNSRelationshipError(){
75 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("globalSubscriberId1")
76 when(mockExecution.getVariable("serviceType")).thenReturn("serviceType")
77 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("serviceInstanceId")
78 when(mockExecution.getVariable("nsInstanceId")).thenReturn("nsInstanceId")
79 doThrow(new NotFoundException("Error creating relationship")).when(client).connect(isA(AAIResourceUri.class),isA(AAIResourceUri.class))
81 doCreateVFCNetworkServiceInstance.addNSRelationship(mockExecution)
82 } catch (BpmnError ex) {
83 assertEquals(ex.getErrorCode(),"MSOWorkflowException")