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.Mockito
35 import org.mockito.MockitoAnnotations
36 import org.mockito.runners.MockitoJUnitRunner
37 import org.onap.so.bpmn.common.scripts.utils.XmlComparator
39 import static org.mockito.Mockito.*
42 * @since January 10, 2018
44 @RunWith(MockitoJUnitRunner.class)
45 class DoCreateE2EServiceInstanceTest {
48 public WireMockRule wireMockRule = new WireMockRule(28090);
51 public void init() throws IOException {
52 MockitoAnnotations.initMocks(this);
56 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
58 String expectedServiceInstanceData = """ <service-instance xmlns="http://org.openecomp.aai.inventory/v8">
59 <service-instance-id>1234</service-instance-id>
60 <service-instance-name>volte-service</service-instance-name>
61 <service-type>voLTE type</service-type>
62 <service-role>voLTE role</service-role>
63 <orchestration-status>Created</orchestration-status>
64 <model-invariant-id>c1d4305f-cdbd-4bbe-9069-a2f4978fd89e</model-invariant-id>
65 <model-version-id>d4df5c27-98a1-4812-a8aa-c17f055b7a3f</model-version-id>
66 </service-instance>"""
68 public void testPreProcessRequest(){
69 ExecutionEntity mockExecution = setupMock()
70 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
71 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("12345")
72 when(mockExecution.getVariable("serviceType")).thenReturn("TRANSPORT")
73 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("1234")
74 when(mockExecution.getVariable("serviceInstanceName")).thenReturn("volte-service")
75 when(mockExecution.getVariable("uuiRequest")).thenReturn("""{"service":{"serviceDefId":"c1d4305f-cdbd-4bbe-9069-a2f4978fd89e" , "templateId" : "d4df5c27-98a1-4812-a8aa-c17f055b7a3f"}}""")
76 when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("/mso/sdncadapter/")
77 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
78 when(mockExecution.getVariable("mso.workflow.default.aai.customer.version")).thenReturn("8")
79 DoCreateE2EServiceInstance obj = new DoCreateE2EServiceInstance()
80 obj.preProcessRequest(mockExecution)
81 Mockito.verify(mockExecution, times(7)).setVariable(captor.capture(), captor.capture())
82 XmlComparator.assertXMLEquals(expectedServiceInstanceData, captor.getValue())
85 private ExecutionEntity setupMock() {
86 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
87 when(mockProcessDefinition.getKey()).thenReturn("DoCreateE2EServiceInstance")
88 RepositoryService mockRepositoryService = mock(RepositoryService.class)
89 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
90 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("DoCreateE2EServiceInstance")
91 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
92 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
93 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
94 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
95 when(mockExecution.getId()).thenReturn("100")
96 when(mockExecution.getProcessDefinitionId()).thenReturn("DoCreateE2EServiceInstance")
97 when(mockExecution.getProcessInstanceId()).thenReturn("DoCreateE2EServiceInstance")
98 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
99 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)