939dd2a31494763c6a7882b415b8075d2391927d
[dcaegen2/services/prh.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * PNF-REGISTRATION-HANDLER
4  * ================================================================================
5  * Copyright (C) 2019 NOKIA 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.dcaegen2.services.prh.integration;
22
23 import java.util.concurrent.CountDownLatch;
24 import java.util.concurrent.TimeUnit;
25 import org.junit.jupiter.api.Test;
26 import org.mockito.stubbing.Answer;
27 import org.onap.dcaegen2.services.prh.tasks.ScheduledTasks;
28 import org.springframework.boot.test.context.SpringBootTest;
29 import org.springframework.boot.test.mock.mockito.MockBean;
30 import org.springframework.test.context.TestPropertySource;
31
32 import static org.junit.jupiter.api.Assertions.assertEquals;
33 import static org.mockito.Mockito.doAnswer;
34
35
36 @SpringBootTest
37 @TestPropertySource (properties = {"prh.workflow-scheduling-interval=20ms"})
38 class PrhWorkflowSchedulingIntegrationTest {
39
40     private static final int EXPECTED_INVOCATIONS_NUMBER = 1;
41     private static final int REMAINING_INVOCATIONS_NUMBER = 0;
42     @MockBean
43     private ScheduledTasks scheduledTasks;
44     private CountDownLatch invocationLatch;
45
46     @Test
47     void prhWorkflowShouldBeExecutedRightAfterApplicationStart() throws InterruptedException {
48         invocationLatch = new CountDownLatch(EXPECTED_INVOCATIONS_NUMBER);
49         doAnswer(registerInvocation(invocationLatch)).when(scheduledTasks).scheduleMainPrhEventTask();
50         assertThatMethodWasInvokedOnce();
51     }
52
53     private void assertThatMethodWasInvokedOnce() throws InterruptedException {
54         invocationLatch.await(1, TimeUnit.SECONDS);
55         assertEquals(REMAINING_INVOCATIONS_NUMBER, invocationLatch.getCount());
56     }
57
58     private static Answer registerInvocation(CountDownLatch invocationLatch) {
59         return invocation -> {
60             invocationLatch.countDown();
61             return null;
62         };
63     }
64 }