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.Assert
29 import org.junit.Before
32 import org.junit.runner.RunWith
33 import org.mockito.ArgumentCaptor
34 import org.mockito.Captor
35 import org.mockito.Mockito
36 import org.mockito.MockitoAnnotations
37 import org.mockito.runners.MockitoJUnitRunner
38 import org.onap.so.bpmn.core.WorkflowException
39 import org.onap.so.bpmn.core.domain.ModelInfo
40 import org.onap.so.bpmn.core.domain.ServiceDecomposition
41 import org.onap.so.bpmn.core.domain.ServiceInstance
42 import org.onap.so.bpmn.mock.StubResponseAAI
44 import static org.mockito.Mockito.*
46 @RunWith(MockitoJUnitRunner.class)
47 class DoCreateServiceInstanceTest {
48 def prefix = "DCRESI_"
51 public WireMockRule wireMockRule = new WireMockRule(28090)
54 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
57 void init() throws IOException {
58 MockitoAnnotations.initMocks(this);
62 void testPreProcessRequest() {
63 ExecutionEntity mockExecution = setupMock()
64 when(mockExecution.getVariable("prefix")).thenReturn(prefix)
65 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
66 when(mockExecution.getVariable("msoRequestId")).thenReturn("12345")
67 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("MIS/1604/0026/SW_INTERNET")
68 when(mockExecution.getVariable("lcpCloudRegionId")).thenReturn("MDTWNJ21")
69 when(mockExecution.getVariable("mso-request-id")).thenReturn("testRequestId-1503410089303")
70 when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://localhost:28080/mso/SDNCAdapterCallbackService")
71 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("MSO_dev")
72 when(mockExecution.getVariable("subscriptionServiceType")).thenReturn("MSO-dev-service-type")
73 when(mockExecution.getVariable("productFamilyId")).thenReturn("RDM2WAGPLCP")
74 when(mockExecution.getVariable("sdnc.si.svc.types")).thenReturn("PORT-MIRROR,PPROBES")
76 ServiceDecomposition decomposition = new ServiceDecomposition()
77 ModelInfo modelInfo = new ModelInfo()
78 ServiceInstance instance = new ServiceInstance()
79 instance.instanceId = "12345"
80 decomposition.modelInfo = modelInfo
81 decomposition.serviceInstance = instance
83 when(mockExecution.getVariable("serviceDecomposition")).thenReturn(decomposition)
84 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
85 when(mockExecution.getVariable("mso.workflow.default.aai.customer.version")).thenReturn("8")
86 when(mockExecution.getVariable("mso.workflow.default.aai.v8.customer.uri")).thenReturn('/aai/v8/business/customers/customer')
89 DoCreateServiceInstance obj = new DoCreateServiceInstance()
90 obj.preProcessRequest(mockExecution)
92 verify(mockExecution).setVariable("prefix", prefix)
93 verify(mockExecution).setVariable("sdncCallbackUrl", "http://localhost:28080/mso/SDNCAdapterCallbackService")
99 void testGetAAICustomerById() {
100 ExecutionEntity mockExecution = setupMock()
101 when(mockExecution.getVariable("prefix")).thenReturn(prefix)
102 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
103 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("12345")
104 when(mockExecution.getVariable("mso.workflow.default.aai.v8.customer.uri")).thenReturn("/aai/v9/business/customers/customer")
105 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
106 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
107 when(mockExecution.getVariable("mso.workflow.custom.DoCreateServiceInstance.aai.version")).thenReturn('8')
108 StubResponseAAI.MockGetCustomer("12345", "")
109 DoCreateServiceInstance obj = new DoCreateServiceInstance()
110 obj.getAAICustomerById(mockExecution)
112 verify(mockExecution, times(1)).getVariable("aai.endpoint")
115 private static ExecutionEntity setupMock() {
116 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
117 when(mockProcessDefinition.getKey()).thenReturn("DoCreateServiceInstance")
118 RepositoryService mockRepositoryService = mock(RepositoryService.class)
119 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
120 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("DoCreateServiceInstance")
121 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
122 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
123 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
125 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
126 // Initialize prerequisite variables
127 when(mockExecution.getId()).thenReturn("100")
128 when(mockExecution.getProcessDefinitionId()).thenReturn("DoCreateServiceInstance")
129 when(mockExecution.getProcessInstanceId()).thenReturn("DoCreateServiceInstance")
130 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
131 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)