7f6b8c51d68cfe709ea9734fcb1389ef72c34486
[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.tasks.ScheduledTasks;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.context.annotation.ComponentScan;
31 import org.springframework.context.annotation.Configuration;
32 import org.springframework.test.context.ContextConfiguration;
33 import org.springframework.test.context.junit.jupiter.SpringExtension;
34 import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
35
36 /**
37  * Integration test for the ScheduledXmlContext.
38  *
39  * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/27/18
40  * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
41  */
42
43 @Configuration
44 @ComponentScan
45 @ExtendWith({ 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)).executeDatafileMainTask();
62     }
63 }