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.runners.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) {
61 @RunWith(MockitoJUnitRunner.class)
62 public class AbstractServiceTaskProcessorTest extends MsoGroovyTest {
65 ArgumentCaptor<ExecutionEntity> captor= ArgumentCaptor.forClass(ExecutionEntity.class);
68 public void testCreateCallbackURL_Success() {
69 ExecutionEntity mockExecution = setupMock()
70 when(mockExecution.getVariable("mso.workflow.message.endpoint")).thenReturn('http://localhost:18080/mso/WorkflowMessage/')
71 AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl();
72 def endpoint = serviceTaskProcessor.createCallbackURL(mockExecution, 'testMessageType', 'testCorrelator')
73 assertEquals('http://localhost:18080/mso/WorkflowMessage/testMessageType/testCorrelator', endpoint)
77 public void testCreateCallbackURL_NullEndpoint() {
79 ExecutionEntity mockExecution = setupMock()
82 when(mockExecution.getVariable("mso.workflow.message.endpoint")).thenReturn("")
83 AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl();
84 def endpoint = serviceTaskProcessor.createCallbackURL(mockExecution, 'testMessageType', 'testCorrelator')
88 Mockito.verify(mockExecution,times(1)).setVariable(captor.capture(),captor.capture())
89 WorkflowException workflowException = captor.getValue()
90 Assert.assertEquals("mso:workflow:message:endpoint URN mapping is not set",workflowException.getErrorMessage())
91 Assert.assertEquals(2000,workflowException.getErrorCode())
95 public void testCreateWorkflowMessageAdapterCallbackURL_Success() {
96 ExecutionEntity mockExecution = setupMock()
97 when(mockExecution.getVariable("mso.adapters.workflow.message.endpoint")).thenReturn('http://localhost:18080/workflows/messages/message/')
99 AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl();
100 def endpoint = serviceTaskProcessor.createWorkflowMessageAdapterCallbackURL(mockExecution, 'testMessageType', 'testCorrelator')
101 assertEquals('http://localhost:18080/workflows/messages/message/testMessageType/testCorrelator', endpoint)
105 public void testCreateWorkflowMessageAdapterCallbackURL_NullEndpoint() {
107 ExecutionEntity mockExecution = setupMock()
110 when(mockExecution.getVariable("mso.adapters.workflow.message.endpoint")).thenReturn("")
112 AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl();
113 def endpoint = serviceTaskProcessor.createWorkflowMessageAdapterCallbackURL(mockExecution, 'testMessageType', 'testCorrelator')
117 Mockito.verify(mockExecution,times(1)).setVariable(captor.capture(),captor.capture())
118 WorkflowException workflowException = captor.getValue()
119 Assert.assertEquals("mso:adapters:workflow:message:endpoint URN mapping is not set",workflowException.getErrorMessage())
120 Assert.assertEquals(2000,workflowException.getErrorCode())
124 public void testSetRollbackEnabledNullOrEmptyDisableRollback() {
125 ExecutionEntity mockExecution = setupMock()
126 when(mockExecution.getVariable("prefix")).thenReturn('TEST_PREFIX')
127 when(mockExecution.getVariable("disableRollback")).thenReturn(null)
128 when(mockExecution.getVariable("mso.rollback")).thenReturn("")
130 AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl();
131 serviceTaskProcessor.setRollbackEnabled(mockExecution, "true")
132 assertEquals(null, mockExecution.getVariable('TEST_PREFIXbackoutOnFailure'))
136 public void testSetRollbackEnabledDisableRollback() {
137 ExecutionEntity mockExecution = setupMock()
138 when(mockExecution.getVariable("prefix")).thenReturn('TEST_PREFIX')
139 when(mockExecution.getVariable("disableRollback")).thenReturn(true)
140 when(mockExecution.getVariable("mso.rollback")).thenReturn("true")
142 AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl();
143 serviceTaskProcessor.setRollbackEnabled(mockExecution, "true")
144 verify(mockExecution).setVariable("TEST_PREFIXbackoutOnFailure",false)
148 public void testSetRollbackEnabledRollback() {
149 ExecutionEntity mockExecution = setupMock()
150 when(mockExecution.getVariable("prefix")).thenReturn('TEST_PREFIX')
151 when(mockExecution.getVariable("disableRollback")).thenReturn(false)
152 when(mockExecution.getVariable("mso.rollback")).thenReturn("true")
154 AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl();
155 serviceTaskProcessor.setRollbackEnabled(mockExecution, "true")
156 verify(mockExecution).setVariable("TEST_PREFIXbackoutOnFailure",true)
160 public void testSetRollbackEnabledDefaultRollback() {
161 ExecutionEntity mockExecution = setupMock()
162 when(mockExecution.getVariable("prefix")).thenReturn('TEST_PREFIX')
163 when(mockExecution.getVariable("disableRollback")).thenReturn("test")
164 when(mockExecution.getVariable("mso.rollback")).thenReturn("true")
166 AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl();
167 serviceTaskProcessor.setRollbackEnabled(mockExecution, "true")
168 verify(mockExecution).setVariable("TEST_PREFIXbackoutOnFailure",true)
172 public void testSetBasicDBAuthHeader_Success() {
173 ExecutionEntity mockExecution = setupMock()
174 when(mockExecution.getVariable("mso.adapters.db.auth")).thenReturn('9B2278E8B8E95F256A560719055F4DF3')
175 when(mockExecution.getVariable("mso.msoKey")).thenReturn('aa3871669d893c7fb8abbcda31b88b4f')
177 AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl();
178 serviceTaskProcessor.setBasicDBAuthHeader(mockExecution, "true")
179 verify(mockExecution).setVariable("BasicAuthHeaderValueDB",'Basic dXAyMTE4OnVwMjExOA==')