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.common.scripts
23 import com.github.tomakehurst.wiremock.junit.WireMockRule
24 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
25 import org.junit.Assert
26 import org.junit.Before
27 import org.junit.Ignore
30 import org.junit.runner.RunWith
31 import org.mockito.ArgumentCaptor
32 import org.mockito.Captor
33 import org.mockito.Mockito
34 import org.mockito.runners.MockitoJUnitRunner
36 import static org.mockito.Mockito.times
37 import static org.mockito.Mockito.when
38 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetServiceInstance
39 import static org.onap.so.bpmn.mock.StubResponseAAI.MockNodeQueryServiceInstanceById
40 import static org.onap.so.bpmn.mock.StubResponseAAI.MockNodeQueryServiceInstanceByName
44 * @since January 10, 2018
46 @RunWith(MockitoJUnitRunner.class)
48 class CustomE2EGetServiceTest extends MsoGroovyTest {
51 public WireMockRule wireMockRule = new WireMockRule(28090)
54 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
57 public void testObtainServiceInstanceUrlById (){
58 ExecutionEntity mockExecution = setupMockWithPrefix('CustomE2EGetService','GENGS_')
59 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
60 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
61 when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8')
62 when(mockExecution.getVariable("mso.workflow.default.aai.v8.nodes-query.uri")).thenReturn('/aai/v8/search/nodes-query')
63 when(mockExecution.getVariable("GENGS_type")).thenReturn('service-instance')
64 when(mockExecution.getVariable("GENGS_serviceInstanceId")).thenReturn("MIS%2F1604%2F0026%2FSW_INTERNET")
65 MockNodeQueryServiceInstanceById("MIS%2F1604%2F0026%2FSW_INTERNET", "GenericFlows/getSIUrlById.xml");
66 CustomE2EGetService customE2EGetService = new CustomE2EGetService();
67 customE2EGetService.obtainServiceInstanceUrlById(mockExecution)
68 Mockito.verify(mockExecution, times(9)).setVariable(captor.capture(), captor.capture())
69 Assert.assertEquals(200, captor.getAllValues().get(5))
73 public void testObtainServiceInstanceUrlByName (){
74 ExecutionEntity mockExecution = setupMockWithPrefix('CustomE2EGetService','GENGS_')
75 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
76 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
77 when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8')
78 when(mockExecution.getVariable("mso.workflow.default.aai.v8.nodes-query.uri")).thenReturn('/aai/v8/search/nodes-query')
79 when(mockExecution.getVariable("GENGS_type")).thenReturn('service-instance')
80 when(mockExecution.getVariable("GENGS_serviceInstanceName")).thenReturn("1604-MVM-26")
81 MockNodeQueryServiceInstanceByName("1604-MVM-26", "GenericFlows/getSIUrlByName.xml");
82 CustomE2EGetService customE2EGetService = new CustomE2EGetService();
83 customE2EGetService.obtainServiceInstanceUrlByName(mockExecution)
84 Mockito.verify(mockExecution, times(8)).setVariable(captor.capture(), captor.capture())
85 Assert.assertEquals(200, captor.getAllValues().get(5))
89 public void testServiceObject (){
90 ExecutionEntity mockExecution = setupMockWithPrefix('CustomE2EGetService','GENGS_')
91 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
92 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
93 when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8')
94 when(mockExecution.getVariable("mso.workflow.default.aai.v8.nodes-query.uri")).thenReturn('/aai/v8/search/nodes-query')
95 when(mockExecution.getVariable("GENGS_type")).thenReturn('service-instance')
96 when(mockExecution.getVariable("GENGS_serviceInstanceId")).thenReturn("MIS%2F1604%2F0026%2FSW_INTERNET")
97 when(mockExecution.getVariable("GENGS_resourceLink")).thenReturn("/aai/v8/business/customers/customer/MSO_1610_dev/service-subscriptions/service-subscription/MSO-dev-service-type/service-instances/service-instance/1234453")
98 MockGetServiceInstance("MSO_1610_dev", "MSO-dev-service-type", "1234453", "GenericFlows/getServiceInstance.xml");
99 CustomE2EGetService customE2EGetService = new CustomE2EGetService();
100 customE2EGetService.getServiceObject(mockExecution)
101 Mockito.verify(mockExecution, times(7)).setVariable(captor.capture(), captor.capture())
102 Assert.assertEquals(200, captor.getAllValues().get(5))