diff options
author | Joss Armstrong <joss.armstrong@ericsson.com> | 2019-02-06 21:53:57 +0000 |
---|---|---|
committer | Takamune Cho <takamune.cho@att.com> | 2019-02-07 18:26:49 +0000 |
commit | cc99c1785390c6ca9f40bb0d6d2b42ee55f38941 (patch) | |
tree | d0e189116acdcef16bf6ee21b7eaea88307c771a /appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/test/java/org | |
parent | b6509fd1f339a8166c4b2c8a28f6dd7b6f867a60 (diff) |
New test class for QueueManager
Increase test coverage from 8% to 84%
Issue-ID: APPC-1396
Change-Id: I82fa20559e37fa387dbc7efa0bc24ba93139a973
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/test/java/org')
-rw-r--r-- | appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/test/java/org/onap/appc/executionqueue/impl/QueueManagerTest.java | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/test/java/org/onap/appc/executionqueue/impl/QueueManagerTest.java b/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/test/java/org/onap/appc/executionqueue/impl/QueueManagerTest.java new file mode 100644 index 000000000..5b2dec8c6 --- /dev/null +++ b/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/test/java/org/onap/appc/executionqueue/impl/QueueManagerTest.java @@ -0,0 +1,68 @@ +/* + * ============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.executionqueue.impl; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import java.util.ArrayList; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; +import org.mockito.Mockito; +import org.onap.appc.executionqueue.helper.Util; +import org.powermock.reflect.Whitebox; + +public class QueueManagerTest { + + @Test(expected = NullPointerException.class) + public void testInit() { + QueueManager qm = new QueueManager(); + Util util = Mockito.mock(Util.class); + Mockito.when(util.getExecutionQueueSize()).thenReturn(1); + Mockito.when(util.getThreadPoolSize()).thenReturn(1); + qm.setExecutionQueueUtil(util); + qm.init(); + assertEquals(Integer.valueOf(1), Whitebox.getInternalState(qm, "maxThreadSize")); + } + + @Test + public void testStop() throws InterruptedException { + QueueManager qm = Mockito.spy(new QueueManager()); + ExecutorService executor = Mockito.mock(ExecutorService.class); + Mockito.when(executor.shutdownNow()).thenReturn(new ArrayList<Runnable>()); + Mockito.when(executor.awaitTermination(100, TimeUnit.MILLISECONDS)).thenReturn(false).thenReturn(true); + Whitebox.setInternalState(qm, "messageExecutor", executor); + qm.stop(); + Mockito.verify(executor, Mockito.times(2)).awaitTermination(100, TimeUnit.MILLISECONDS); + } + + @Test + public void testEnqueueTask() throws InterruptedException { + QueueManager qm = Mockito.spy(new QueueManager()); + ExecutorService executor = Mockito.mock(ExecutorService.class); + Mockito.when(executor.shutdownNow()).thenReturn(new ArrayList<Runnable>()); + Mockito.when(executor.awaitTermination(100, TimeUnit.MILLISECONDS)).thenReturn(false).thenReturn(true); + Whitebox.setInternalState(qm, "messageExecutor", executor); + qm.enqueueTask(null); + Mockito.verify(executor).execute(Mockito.any(Runnable.class)); + } + +} |