diff options
Diffstat (limited to 'appc-dispatcher/appc-workflow-management')
3 files changed, 149 insertions, 1 deletions
diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/activator/TransactionAbortedMarker.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/activator/TransactionAbortedMarker.java index 61a336b6c..a1b9dbc0c 100644 --- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/activator/TransactionAbortedMarker.java +++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/activator/TransactionAbortedMarker.java @@ -79,7 +79,7 @@ public class TransactionAbortedMarker implements Runnable { recorder.setAppcInstanceId(newAppcInstanceId); } catch (TransactionRecorderServiceNotFoundException e) { logger.warn("Transaction Recorder Service Not Found, Next attempt after 30 seconds"); - executor.schedule(this,30, TimeUnit.SECONDS); + executor.schedule(this, 30, TimeUnit.SECONDS); } catch (Exception e) { logger.error("Error on workflow manager bundle start-up" + e.getMessage(), e); throw new RuntimeException(e); diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/activator/TransactionAbortedMarkerTest.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/activator/TransactionAbortedMarkerTest.java new file mode 100644 index 000000000..91645a1f8 --- /dev/null +++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/activator/TransactionAbortedMarkerTest.java @@ -0,0 +1,97 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 Ericsson + * ================================================================================ + * 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.appc.workflow.activator; + +import static org.junit.Assert.assertTrue; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mockito; +import org.onap.appc.transactionrecorder.TransactionRecorder; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.FrameworkUtil; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(FrameworkUtil.class) +public class TransactionAbortedMarkerTest { + + private final BundleContext bundleContext = Mockito.mock(BundleContext.class); + private final Bundle bundleService = Mockito.mock(Bundle.class); + private final ServiceReference sref = Mockito.mock(ServiceReference.class); + private final TransactionRecorder transactionRecorder = Mockito.mock(TransactionRecorder.class); + + @Rule + public ExpectedException expectedEx = ExpectedException.none(); + + @Test + public void testRunTransactionRecorderServiceException() throws TransactionRecorderServiceNotFoundException { + ScheduledExecutorService executor = Mockito.mock(ScheduledExecutorService.class); + TransactionAbortedMarker tamt = Mockito.spy(new TransactionAbortedMarker(executor)); + Mockito.doThrow(new TransactionRecorderServiceNotFoundException(null)).when(tamt).lookupTransactionRecorder(); + tamt.run(); + Mockito.verify(executor).schedule(tamt, 30, TimeUnit.SECONDS); + } + + @Test + public void testRuntimeException() throws TransactionRecorderServiceNotFoundException { + ScheduledExecutorService executor = Mockito.mock(ScheduledExecutorService.class); + TransactionAbortedMarker tamt = Mockito.spy(new TransactionAbortedMarker(executor)); + Mockito.doThrow(new RuntimeException()).when(tamt).lookupTransactionRecorder(); + expectedEx.expect(RuntimeException.class); + tamt.run(); + } + + @Test + public void testLookupTransactionRecorder() throws TransactionRecorderServiceNotFoundException { + PowerMockito.mockStatic(FrameworkUtil.class); + PowerMockito.when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService); + PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext); + PowerMockito.when(bundleContext.getServiceReference(TransactionRecorder.class.getName())).thenReturn(sref); + PowerMockito.when(bundleContext.<TransactionRecorder>getService(sref)).thenReturn(transactionRecorder); + ScheduledExecutorService executor = Mockito.mock(ScheduledExecutorService.class); + TransactionAbortedMarker tamt = Mockito.spy(new TransactionAbortedMarker(executor)); + assertTrue(tamt.lookupTransactionRecorder() instanceof TransactionRecorder); + } + + @Test + public void testLookupTransactionRecorderExceptionFlow() throws TransactionRecorderServiceNotFoundException { + PowerMockito.mockStatic(FrameworkUtil.class); + PowerMockito.when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService); + PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext); + PowerMockito.when(bundleContext.getServiceReference(TransactionRecorder.class.getName())).thenReturn(sref); + PowerMockito.when(bundleContext.<TransactionRecorder>getService(sref)).thenReturn(null); + ScheduledExecutorService executor = Mockito.mock(ScheduledExecutorService.class); + TransactionAbortedMarker tamt = Mockito.spy(new TransactionAbortedMarker(executor)); + expectedEx.expect(TransactionRecorderServiceNotFoundException.class); + expectedEx.expectMessage("Cannot find service org.onap.appc.transactionrecorder.TransactionRecorder"); + tamt.lookupTransactionRecorder(); + } +} diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/activator/WorkflowManagerActivatorTest.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/activator/WorkflowManagerActivatorTest.java new file mode 100644 index 000000000..00d6e8910 --- /dev/null +++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/activator/WorkflowManagerActivatorTest.java @@ -0,0 +1,51 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 Ericsson + * ================================================================================ + * 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.appc.workflow.activator; + +import static org.junit.Assert.assertNotNull; +import java.util.concurrent.ScheduledExecutorService; +import org.junit.Test; +import org.mockito.Mockito; +import org.osgi.framework.BundleContext; +import org.powermock.reflect.Whitebox; + +public class WorkflowManagerActivatorTest { + + @Test + public void testStart() { + BundleContext bundleContext = Mockito.mock(BundleContext.class); + WorkflowManagerActivator activator = new WorkflowManagerActivator(); + activator.start(bundleContext); + assertNotNull(Whitebox.getInternalState(activator, "executor")); + } + + @Test + public void testStop() throws Exception { + BundleContext bundleContext = Mockito.mock(BundleContext.class); + WorkflowManagerActivator activator = new WorkflowManagerActivator(); + ScheduledExecutorService executor = Mockito.mock(ScheduledExecutorService.class); + Whitebox.setInternalState(activator, "executor", executor); + activator.stop(bundleContext); + Mockito.verify(executor).shutdown(); + } + +} |