Springboot 2.0 upgrade
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / groovy / org / onap / so / bpmn / infrastructure / scripts / DoCreateVFCNetworkServiceInstanceTest.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
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 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
27 import org.junit.Rule
28 import org.junit.Test
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.so.client.aai.AAIObjectType
36 import org.onap.so.client.aai.entities.uri.AAIResourceUri
37 import org.onap.so.client.aai.entities.uri.AAIUriFactory
38 import javax.ws.rs.NotFoundException
39 import static org.junit.Assert.assertEquals
40 import static org.mockito.Matchers.isA
41 import static org.mockito.Mockito.doNothing
42 import static org.mockito.Mockito.doThrow
43 import static org.mockito.Mockito.when
44
45 class DoCreateVFCNetworkServiceInstanceTest extends MsoGroovyTest {
46
47     @Spy
48     DoCreateVFCNetworkServiceInstance doCreateVFCNetworkServiceInstance
49
50     @Before
51     public void init() throws IOException {
52         super.init("CreateVFCNSResource")
53         MockitoAnnotations.initMocks(this)
54         when(doCreateVFCNetworkServiceInstance.getAAIClient()).thenReturn(client)
55     }
56
57     @Captor
58     static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
59
60     @Test
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)
71     }
72
73     @Test
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))
80         try {
81             doCreateVFCNetworkServiceInstance.addNSRelationship(mockExecution)
82         } catch (BpmnError ex) {
83             assertEquals(ex.getErrorCode(),"MSOWorkflowException")
84         }
85     }
86
87 }