aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukasz Muszkieta <lukasz.muszkieta@nokia.com>2019-03-04 15:22:54 +0100
committerMarcus Williams <marcus.williams@intel.com>2019-03-06 15:59:14 +0000
commit1cf6f020bcf890d4cdfb7b6bf94410462cbe2d9f (patch)
treedaa2d9a53993628374d339c34e7fd4018e00618c
parent91426ec9f221e288ea3f54fa62030e6f17420b90 (diff)
Add junit tests for CallbackHandlerService
Change-Id: I2f136c2241bdcbfa41a609023c7b3c8eb72eb106 Issue-ID: SO-1576 Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com>
-rw-r--r--bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/CallbackHandlerService.java10
-rw-r--r--bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/CallbackHandlerServiceTest.java103
2 files changed, 110 insertions, 3 deletions
diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/CallbackHandlerService.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/CallbackHandlerService.java
index 920cb11e4c..f4617f9978 100644
--- a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/CallbackHandlerService.java
+++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/CallbackHandlerService.java
@@ -50,12 +50,16 @@ public class CallbackHandlerService {
public static final long FAST_POLL_DUR_SECONDS = 5;
public static final long FAST_POLL_INT_MS = 100;
public static final long SLOW_POLL_INT_MS = 1000;
-
+
private static final Logger logger = LoggerFactory.getLogger(CallbackHandlerService.class);
+ private RuntimeService runtimeService;
+
@Autowired
- RuntimeService runtimeService;
-
+ public CallbackHandlerService(RuntimeService runtimeService) {
+ this.runtimeService = runtimeService;
+ }
+
/**
* Parameterized callback handler.
*/
diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/CallbackHandlerServiceTest.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/CallbackHandlerServiceTest.java
new file mode 100644
index 0000000000..051107bb13
--- /dev/null
+++ b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/CallbackHandlerServiceTest.java
@@ -0,0 +1,103 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Nokia.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.common.workflow.service;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import org.camunda.bpm.engine.RuntimeService;
+import org.camunda.bpm.engine.impl.ExecutionQueryImpl;
+import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity;
+import org.camunda.bpm.engine.runtime.Execution;
+import org.camunda.bpm.engine.runtime.ExecutionQuery;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.so.bpmn.common.workflow.service.CallbackHandlerService.CallbackError;
+import org.onap.so.bpmn.common.workflow.service.CallbackHandlerService.CallbackResult;
+import org.onap.so.bpmn.common.workflow.service.CallbackHandlerService.CallbackSuccess;
+import org.onap.so.bpmn.core.UrnPropertiesReader;
+import org.springframework.core.env.Environment;
+
+public class CallbackHandlerServiceTest {
+
+ private static final String METHOD_NAME = "testMethod";
+ private static final String MESSAGE = "testMessage";
+ private static final String EVENT_NAME = "eventNameTest";
+ private static final String MESSAGE_VARIABLE = "messageVarTest";
+ private static final String CORRELATION_VARIABLE = "corrVarTest";
+ private static final String CORRELATION_VALUE = "corrValueTest";
+ private static final String LOG_MARKER = "markerTest";
+
+ private RuntimeService runtimeServiceMock;
+ private CallbackHandlerService testedObject;
+
+ @Before
+ public void setup() {
+ runtimeServiceMock = mock(RuntimeService.class);
+ testedObject = new CallbackHandlerService(runtimeServiceMock);
+ mockEnvironment();
+ }
+
+ @Test
+ public void callbackSuccessful() {
+ // given
+ mockRuntimeService(new ArrayList<>(Arrays.asList(new ExecutionEntity())));
+ // when
+ CallbackResult callbackResult = testedObject.handleCallback(METHOD_NAME, MESSAGE, EVENT_NAME, MESSAGE_VARIABLE,
+ CORRELATION_VARIABLE, CORRELATION_VALUE, LOG_MARKER, new HashMap<>());
+ // then
+ assertThat(callbackResult).isExactlyInstanceOf(CallbackSuccess.class);
+ }
+
+ @Test
+ public void callbackNotSuccessful_noWaitingProcesses() {
+ // given
+ mockRuntimeService(Collections.emptyList());
+ // when
+ CallbackResult callbackResult = testedObject.handleCallback(METHOD_NAME, MESSAGE, EVENT_NAME, MESSAGE_VARIABLE,
+ CORRELATION_VARIABLE, CORRELATION_VALUE, LOG_MARKER, new HashMap<>());
+ // then
+ assertThat(callbackResult).isExactlyInstanceOf(CallbackError.class);
+ }
+
+ private void mockRuntimeService(List<Execution> waitingProcesses) {
+ ExecutionQuery executionQueryMock = mock(ExecutionQueryImpl.class);
+ when(runtimeServiceMock.createExecutionQuery()).thenReturn(executionQueryMock);
+ when(executionQueryMock.messageEventSubscriptionName("eventNameTest")).thenReturn(executionQueryMock);
+ when(executionQueryMock.processVariableValueEquals("corrVarTest", "corrValueTest"))
+ .thenReturn(executionQueryMock);
+ when(executionQueryMock.list()).thenReturn(waitingProcesses);
+ }
+
+ private Environment mockEnvironment() {
+ Environment mockEnvironment = mock(Environment.class);
+ UrnPropertiesReader urnPropertiesReader = new UrnPropertiesReader();
+ urnPropertiesReader.setEnvironment(mockEnvironment);
+ when(mockEnvironment.getProperty("mso.correlation.timeout")).thenReturn("1");
+ return mockEnvironment;
+ }
+}