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 org.camunda.bpm.engine.delegate.DelegateExecution
24 import org.junit.Assert
25 import org.mockito.ArgumentCaptor
26 import org.mockito.Captor
27 import org.mockito.Mockito
28 import org.onap.so.bpmn.core.WorkflowException;
30 import static org.junit.Assert.*;
31 import static org.mockito.Mockito.*
33 import org.onap.so.rest.HttpHeader
34 import org.mockito.MockitoAnnotations
35 import org.mockito.junit.MockitoJUnitRunner;
36 import org.mockito.internal.debugging.MockitoDebuggerImpl
37 import org.junit.Before
38 import org.onap.so.bpmn.common.scripts.AaiUtil;
39 import org.junit.Rule;
41 import org.junit.Ignore
42 import org.junit.runner.RunWith
43 import org.junit.Before;
44 import org.junit.Test;
45 import org.camunda.bpm.engine.ProcessEngineServices
46 import org.camunda.bpm.engine.RepositoryService
47 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
48 import org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl
49 import org.camunda.bpm.engine.repository.ProcessDefinition
53 class AbstractServiceTaskProcessorImpl extends AbstractServiceTaskProcessor{
56 void preProcessRequest(DelegateExecution execution) {
62 @RunWith(MockitoJUnitRunner.Silent.class)
63 public class AbstractServiceTaskProcessorTest extends MsoGroovyTest {
66 ArgumentCaptor<ExecutionEntity> captor= ArgumentCaptor.forClass(ExecutionEntity.class);
69 public void testCreateCallbackURL_Success() {
70 ExecutionEntity mockExecution = setupMock()
71 when(mockExecution.getVariable("mso.workflow.message.endpoint")).thenReturn('http://localhost:18080/mso/WorkflowMessage/')
72 AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl();
73 def endpoint = serviceTaskProcessor.createCallbackURL(mockExecution, 'testMessageType', 'testCorrelator')
74 assertEquals('http://localhost:18080/mso/WorkflowMessage/testMessageType/testCorrelator', endpoint)
78 public void testCreateCallbackURL_NullEndpoint() {
80 ExecutionEntity mockExecution = setupMock()
83 when(mockExecution.getVariable("mso.workflow.message.endpoint")).thenReturn("")
84 AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl();
85 def endpoint = serviceTaskProcessor.createCallbackURL(mockExecution, 'testMessageType', 'testCorrelator')
89 Mockito.verify(mockExecution,times(1)).setVariable(captor.capture(),captor.capture())
90 WorkflowException workflowException = captor.getValue()
91 Assert.assertEquals("mso:workflow:message:endpoint URN mapping is not set",workflowException.getErrorMessage())
92 Assert.assertEquals(2000,workflowException.getErrorCode())
96 public void testCreateWorkflowMessageAdapterCallbackURL_Success() {
97 ExecutionEntity mockExecution = setupMock()
98 when(mockExecution.getVariable("mso.adapters.workflow.message.endpoint")).thenReturn('http://localhost:18080/workflows/messages/message/')
100 AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl();
101 def endpoint = serviceTaskProcessor.createWorkflowMessageAdapterCallbackURL(mockExecution, 'testMessageType', 'testCorrelator')
102 assertEquals('http://localhost:18080/workflows/messages/message/testMessageType/testCorrelator', endpoint)
106 public void testCreateWorkflowMessageAdapterCallbackURL_NullEndpoint() {
108 ExecutionEntity mockExecution = setupMock()
111 when(mockExecution.getVariable("mso.adapters.workflow.message.endpoint")).thenReturn("")
113 AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl();
114 def endpoint = serviceTaskProcessor.createWorkflowMessageAdapterCallbackURL(mockExecution, 'testMessageType', 'testCorrelator')
118 Mockito.verify(mockExecution,times(1)).setVariable(captor.capture(),captor.capture())
119 WorkflowException workflowException = captor.getValue()
120 Assert.assertEquals("mso:adapters:workflow:message:endpoint URN mapping is not set",workflowException.getErrorMessage())
121 Assert.assertEquals(2000,workflowException.getErrorCode())
125 public void testSetRollbackEnabledNullOrEmptyDisableRollback() {
126 ExecutionEntity mockExecution = setupMock()
127 when(mockExecution.getVariable("prefix")).thenReturn('TEST_PREFIX')
128 when(mockExecution.getVariable("disableRollback")).thenReturn(null)
129 when(mockExecution.getVariable("mso.rollback")).thenReturn("")
131 AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl();
132 serviceTaskProcessor.setRollbackEnabled(mockExecution, "true")
133 assertEquals(null, mockExecution.getVariable('TEST_PREFIXbackoutOnFailure'))
137 public void testSetRollbackEnabledDisableRollback() {
138 ExecutionEntity mockExecution = setupMock()
139 when(mockExecution.getVariable("prefix")).thenReturn('TEST_PREFIX')
140 when(mockExecution.getVariable("disableRollback")).thenReturn(true)
141 when(mockExecution.getVariable("mso.rollback")).thenReturn("true")
143 AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl();
144 serviceTaskProcessor.setRollbackEnabled(mockExecution, "true")
145 verify(mockExecution).setVariable("TEST_PREFIXbackoutOnFailure",false)
149 public void testSetRollbackEnabledRollback() {
150 ExecutionEntity mockExecution = setupMock()
151 when(mockExecution.getVariable("prefix")).thenReturn('TEST_PREFIX')
152 when(mockExecution.getVariable("disableRollback")).thenReturn(false)
153 when(mockExecution.getVariable("mso.rollback")).thenReturn("true")
155 AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl();
156 serviceTaskProcessor.setRollbackEnabled(mockExecution, "true")
157 verify(mockExecution).setVariable("TEST_PREFIXbackoutOnFailure",true)
161 public void testSetRollbackEnabledDefaultRollback() {
162 ExecutionEntity mockExecution = setupMock()
163 when(mockExecution.getVariable("prefix")).thenReturn('TEST_PREFIX')
164 when(mockExecution.getVariable("disableRollback")).thenReturn("test")
165 when(mockExecution.getVariable("mso.rollback")).thenReturn("true")
167 AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl();
168 serviceTaskProcessor.setRollbackEnabled(mockExecution, "true")
169 verify(mockExecution).setVariable("TEST_PREFIXbackoutOnFailure",true)
173 public void testSetBasicDBAuthHeader_Success() {
174 ExecutionEntity mockExecution = setupMock()
175 when(mockExecution.getVariable("mso.adapters.db.auth")).thenReturn('5E12ACACBD552A415E081E29F2C4772F9835792A51C766CCFDD7433DB5220B59969CB2798C')
176 when(mockExecution.getVariable("mso.msoKey")).thenReturn('07a7159d3bf51a0e53be7a8f89699be7')
178 AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl();
179 serviceTaskProcessor.setBasicDBAuthHeader(mockExecution, "true")
180 verify(mockExecution).setVariable("BasicAuthHeaderValueDB",'Basic dGVzdDp0ZXN0')