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