b5f55d0e36066ef651785d5d3720b243f96c2125
[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.Configuration;
35 import org.springframework.test.context.ContextConfiguration;
36 import org.springframework.test.context.junit.jupiter.SpringExtension;
37 import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
38
39 /**
40  * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/27/18
41  */
42 @Configuration
43 @ExtendWith({MockitoExtension.class, SpringExtension.class})
44 @ContextConfiguration(locations = "classpath:scheduled-context.xml")
45 class ScheduledXmlContextITest extends AbstractTestNGSpringContextTests {
46
47     private static final int WAIT_FOR_SCHEDULING = 1;
48
49     @Autowired
50     private ScheduledTasks scheduledTask;
51
52     @Test
53     void testScheduling() {
54         final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
55         executorService.scheduleWithFixedDelay(this::verifyDmaapConsumerTask, 0, WAIT_FOR_SCHEDULING, TimeUnit.SECONDS);
56     }
57
58     private void verifyDmaapConsumerTask() {
59         verify(scheduledTask, atLeast(1)).scheduleMainPrhEventTask();
60     }
61 }