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 org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
39 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
40 import javax.ws.rs.NotFoundException
41 import static org.junit.Assert.assertEquals
42 import static org.mockito.ArgumentMatchers.isA
43 import static org.mockito.Mockito.doNothing
44 import static org.mockito.Mockito.doThrow
45 import static org.mockito.Mockito.when
47 class DoCreateVFCNetworkServiceInstanceTest extends MsoGroovyTest {
50 DoCreateVFCNetworkServiceInstance doCreateVFCNetworkServiceInstance
53 public void init() throws IOException {
54 super.init("CreateVFCNSResource")
55 MockitoAnnotations.initMocks(this)
56 when(doCreateVFCNetworkServiceInstance.getAAIClient()).thenReturn(client)
60 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
63 public void testAddNSRelationship(){
64 when(mockExecution.getVariable("nsInstanceId")).thenReturn("NS12345")
65 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("MSO_dev")
66 when(mockExecution.getVariable("serviceType")).thenReturn("MSO-dev-service-type")
67 when(mockExecution.getVariable("serviceId")).thenReturn("SER12345")
68 doNothing().when(client).connect(isA(AAIResourceUri.class),isA(AAIResourceUri.class))
69 doCreateVFCNetworkServiceInstance.addNSRelationship(mockExecution);
70 AAIResourceUri nsUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("MSO_dev").serviceSubscription("MSO-dev-service-type").serviceInstance("NS12345"))
71 AAIResourceUri relatedServiceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("MSO_dev").serviceSubscription("MSO-dev-service-type").serviceInstance("SER12345"))
72 Mockito.verify(client).connect(nsUri,relatedServiceUri)
76 void testaddNSRelationshipError(){
77 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("globalSubscriberId1")
78 when(mockExecution.getVariable("serviceType")).thenReturn("serviceType")
79 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("serviceInstanceId")
80 when(mockExecution.getVariable("nsInstanceId")).thenReturn("nsInstanceId")
81 doThrow(new NotFoundException("Error creating relationship")).when(client).connect(isA(AAIResourceUri.class),isA(AAIResourceUri.class))
83 doCreateVFCNetworkServiceInstance.addNSRelationship(mockExecution)
84 } catch (BpmnError ex) {
85 assertEquals(ex.getErrorCode(),"MSOWorkflowException")