b5f05a717334030b4e9f16b65979cc727bb28913
[dcaegen2/collectors/datafile.git] /
1 /*
2  * ============LICENSE_START======================================================================
3  * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. All rights reserved.
4  * ===============================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END========================================================================
17  */
18
19 package org.onap.dcaegen2.collectors.datafile.integration;
20
21 import static org.mockito.Mockito.atLeast;
22 import static org.mockito.Mockito.verify;
23
24 import java.util.concurrent.Executors;
25 import java.util.concurrent.ScheduledExecutorService;
26 import java.util.concurrent.TimeUnit;
27
28 import org.junit.jupiter.api.Test;
29 import org.junit.jupiter.api.extension.ExtendWith;
30 import org.onap.dcaegen2.collectors.datafile.integration.junit5.mockito.MockitoExtension;
31 import org.onap.dcaegen2.collectors.datafile.tasks.ScheduledTasks;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.context.annotation.ComponentScan;
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  * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
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 }