From 84430dbbf3aab095066417c9a3293d3fd49c4e3b Mon Sep 17 00:00:00 2001 From: Joanna Jeremicz Date: Thu, 21 Nov 2019 11:18:09 +0100 Subject: Fix PrhWorkflowSchedulingIntegrationTest - Clean up scheduledTasksRunner after previous integration tests - Prevent race condition Change-Id: If3763cbc031ddca3a14568742265644b4472a448 Issue-ID: DCAEGEN2-1853 Signed-off-by: Joanna Jeremicz --- .../PrhWorkflowSchedulingIntegrationTest.java | 29 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/PrhWorkflowSchedulingIntegrationTest.java') diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/PrhWorkflowSchedulingIntegrationTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/PrhWorkflowSchedulingIntegrationTest.java index 44dcabfa..939dd2a3 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/PrhWorkflowSchedulingIntegrationTest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/PrhWorkflowSchedulingIntegrationTest.java @@ -20,22 +20,45 @@ package org.onap.dcaegen2.services.prh.integration; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Test; +import org.mockito.stubbing.Answer; import org.onap.dcaegen2.services.prh.tasks.ScheduledTasks; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.TestPropertySource; -import static org.mockito.Mockito.verify; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.doAnswer; @SpringBootTest +@TestPropertySource (properties = {"prh.workflow-scheduling-interval=20ms"}) class PrhWorkflowSchedulingIntegrationTest { + private static final int EXPECTED_INVOCATIONS_NUMBER = 1; + private static final int REMAINING_INVOCATIONS_NUMBER = 0; @MockBean private ScheduledTasks scheduledTasks; + private CountDownLatch invocationLatch; @Test - void prhWorkflowShouldBeExecutedRightAfterApplicationStart() { - verify(scheduledTasks).scheduleMainPrhEventTask(); + void prhWorkflowShouldBeExecutedRightAfterApplicationStart() throws InterruptedException { + invocationLatch = new CountDownLatch(EXPECTED_INVOCATIONS_NUMBER); + doAnswer(registerInvocation(invocationLatch)).when(scheduledTasks).scheduleMainPrhEventTask(); + assertThatMethodWasInvokedOnce(); + } + + private void assertThatMethodWasInvokedOnce() throws InterruptedException { + invocationLatch.await(1, TimeUnit.SECONDS); + assertEquals(REMAINING_INVOCATIONS_NUMBER, invocationLatch.getCount()); + } + + private static Answer registerInvocation(CountDownLatch invocationLatch) { + return invocation -> { + invocationLatch.countDown(); + return null; + }; } } \ No newline at end of file -- cgit 1.2.3-korg