b9aa2f78ce6dc3604af1f065e4a1d1d7610b6efe
[dcaegen2/collectors/datafile.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.collectors.datafile.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.collectors.datafile.integration.junit5.mockito.MockitoExtension;
32 import org.onap.dcaegen2.collectors.datafile.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
44 @Configuration
45 @ComponentScan
46 @ExtendWith({MockitoExtension.class, SpringExtension.class})
47 @ContextConfiguration(locations = {"classpath:scheduled-context.xml"})
48 class ScheduledXmlContextITest extends AbstractTestNGSpringContextTests {
49
50     private static final int WAIT_FOR_SCHEDULING = 1;
51
52     @Autowired
53     private ScheduledTasks scheduledTask;
54
55     @Test
56     void testScheduling() {
57         final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
58         executorService.scheduleWithFixedDelay(this::verifyDmaapConsumerTask, 0, WAIT_FOR_SCHEDULING, TimeUnit.SECONDS);
59     }
60
61     private void verifyDmaapConsumerTask() {
62         verify(scheduledTask, atLeast(1)).scheduleMainDatafileEventTask();
63     }
64 }
65
66