934f572fb7005b621c71f8458993b46a88cef4c2
[dcaegen2/services/prh.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * PROJECT
4  * ================================================================================
5  * Copyright (C) 2018 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 static org.mockito.Mockito.atLeast;
24 import static org.mockito.Mockito.verify;
25
26 import java.util.concurrent.Executors;
27 import java.util.concurrent.ScheduledExecutorService;
28 import java.util.concurrent.TimeUnit;
29 import org.junit.jupiter.api.Test;
30 import org.junit.jupiter.api.extension.ExtendWith;
31 import org.onap.dcaegen2.services.prh.integration.junit5.mockito.MockitoExtension;
32 import org.onap.dcaegen2.services.prh.tasks.ScheduledTasks;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.context.annotation.ComponentScan;
35 import org.springframework.context.annotation.Configuration;
36 import org.springframework.test.context.ContextConfiguration;
37 import org.springframework.test.context.junit.jupiter.SpringExtension;
38 import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
39
40 /**
41  * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/27/18
42  */
43 @Configuration
44 @ComponentScan("org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers")
45 @ExtendWith({MockitoExtension.class, SpringExtension.class})
46 @ContextConfiguration(locations = "classpath:scheduled-context.xml")
47 class ScheduledXmlContextITest extends AbstractTestNGSpringContextTests {
48
49     private static final int WAIT_FOR_SCHEDULING = 1;
50
51     @Autowired
52     private ScheduledTasks scheduledTask;
53
54     @Test
55     void testScheduling() {
56         final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
57         executorService.scheduleWithFixedDelay(this::verifyDmaapConsumerTask, 0, WAIT_FOR_SCHEDULING, TimeUnit.SECONDS);
58     }
59
60     private void verifyDmaapConsumerTask() {
61         verify(scheduledTask, atLeast(1)).scheduleMainPrhEventTask();
62     }
63 }