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.ProcessEngineServices
25 import org.camunda.bpm.engine.RepositoryService
26 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
27 import org.camunda.bpm.engine.repository.ProcessDefinition
28 import org.junit.Before
31 import org.junit.runner.RunWith
32 import org.mockito.ArgumentCaptor
33 import org.mockito.Captor
34 import org.mockito.MockitoAnnotations
35 import org.mockito.runners.MockitoJUnitRunner
37 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse
38 import static com.github.tomakehurst.wiremock.client.WireMock.put
39 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor
40 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching
41 import static org.mockito.Mockito.mock
42 import static org.mockito.Mockito.times
43 import static org.mockito.Mockito.verify
44 import static org.mockito.Mockito.when
48 * @since January 10, 2018
50 @RunWith(MockitoJUnitRunner.class)
51 class DoCreateVFCNetworkServiceInstanceTest {
54 public WireMockRule wireMockRule = new WireMockRule(28090)
56 public void init() throws IOException {
57 MockitoAnnotations.initMocks(this);
61 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
64 public void testAddNSRelationship(){
65 ExecutionEntity mockExecution = setupMock()
66 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
67 when(mockExecution.getVariable("nsInstanceId")).thenReturn("NS12345")
68 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("MSO_dev")
69 when(mockExecution.getVariable("serviceType")).thenReturn("MSO-dev-service-type")
70 when(mockExecution.getVariable("serviceId")).thenReturn("SER12345")
71 when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7")
72 when(mockExecution.getVariable("aai.auth")).thenReturn("757A94191D685FD2092AC1490730A4FC")
73 MockPutServiceInstance("MSO_dev", "MSO-dev-service-type", "SER12345");
74 DoCreateVFCNetworkServiceInstance DoCreateVFCNetworkServiceInstance = new DoCreateVFCNetworkServiceInstance()
75 DoCreateVFCNetworkServiceInstance.addNSRelationship(mockExecution);
76 verify(mockExecution, times(1)).getVariable("aai.endpoint")
77 verify(mockExecution, times(1)).getVariable("mso.msoKey")
78 verify(mockExecution, times(1)).getVariable("aai.auth")
81 private ExecutionEntity setupMock() {
82 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
83 when(mockProcessDefinition.getKey()).thenReturn("DoCreateVFCNetworkServiceInstance")
84 RepositoryService mockRepositoryService = mock(RepositoryService.class)
85 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
86 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("DoCreateVFCNetworkServiceInstance")
87 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
88 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
89 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
90 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
91 when(mockExecution.getId()).thenReturn("100")
92 when(mockExecution.getProcessDefinitionId()).thenReturn("DoCreateVFCNetworkServiceInstance")
93 when(mockExecution.getProcessInstanceId()).thenReturn("DoCreateVFCNetworkServiceInstance")
94 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
95 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)
99 public static void MockPutServiceInstance(String globalCustId, String subscriptionType, String serviceInstanceId) {
100 stubFor(put(urlMatching("/aai/v[0-9]+/business/customers/customer/" + globalCustId + "/service-subscriptions/service-subscription/" + subscriptionType + "/service-instances/service-instance/" + serviceInstanceId+"/relationship-list/relationship"))
101 .willReturn(aResponse()
103 .withHeader("Content-Type", "text/xml").withBody("")