efb762a81c662dc0257e0d21046829687ee05d64
[dcaegen2/collectors/datafile.git] /
1 /*
2  * ============LICENSE_START======================================================================
3  * Copyright (C) 2018 NOKIA Intellectual Property, 2018-2019 Nordix Foundation. All rights reserved.
4  * ===============================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6  * in compliance with the License. You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software distributed under the License
11  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12  * or implied. See the License for the specific language governing permissions and limitations under
13  * the License.
14  * ============LICENSE_END========================================================================
15  */
16
17 package org.onap.dcaegen2.collectors.datafile.integration;
18
19 import static org.mockito.Mockito.atLeast;
20 import static org.mockito.Mockito.verify;
21
22 import java.util.concurrent.Executors;
23 import java.util.concurrent.ScheduledExecutorService;
24 import java.util.concurrent.TimeUnit;
25
26 import org.junit.jupiter.api.Test;
27 import org.junit.jupiter.api.extension.ExtendWith;
28 import org.onap.dcaegen2.collectors.datafile.integration.junit5.mockito.MockitoExtension;
29 import org.onap.dcaegen2.collectors.datafile.tasks.ScheduledTasks;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.context.annotation.ComponentScan;
32 import org.springframework.context.annotation.Configuration;
33 import org.springframework.test.context.ContextConfiguration;
34 import org.springframework.test.context.junit.jupiter.SpringExtension;
35 import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
36
37 /**
38  * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/27/18
39  * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
40  */
41
42 @Configuration
43 @ComponentScan
44 @ExtendWith({MockitoExtension.class, SpringExtension.class})
45 @ContextConfiguration(locations = {"classpath:scheduled-context.xml"})
46 class ScheduledXmlContextITest extends AbstractTestNGSpringContextTests {
47
48     private static final int WAIT_FOR_SCHEDULING = 1;
49
50     @Autowired
51     private ScheduledTasks scheduledTask;
52
53     @Test
54     void testScheduling() {
55         final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
56         executorService.scheduleWithFixedDelay(this::verifyDmaapConsumerTask, 0, WAIT_FOR_SCHEDULING, TimeUnit.SECONDS);
57     }
58
59     private void verifyDmaapConsumerTask() {
60         verify(scheduledTask, atLeast(1)).scheduleMainDatafileEventTask();
61     }
62 }