2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright 2019 China Mobile
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.datalake.feeder.service;
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.assertTrue;
26 import static org.mockito.Mockito.when;
28 import java.lang.reflect.Field;
29 import java.lang.reflect.InvocationTargetException;
30 import java.lang.reflect.Method;
31 import java.util.Arrays;
32 import java.util.List;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.InjectMocks;
37 import org.mockito.Mock;
38 import org.mockito.junit.MockitoJUnitRunner;
39 import org.onap.datalake.feeder.config.ApplicationConfiguration;
42 * Test TopicConfigPollingService
47 @RunWith(MockitoJUnitRunner.class)
48 public class TopicConfigPollingServiceTest {
50 private ApplicationConfiguration config;
53 private DmaapService dmaapService;
56 private TopicConfigPollingService topicConfigPollingService = new TopicConfigPollingService();
58 public void testInit() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException {
59 Method init = topicConfigPollingService.getClass().getDeclaredMethod("init");
60 init.setAccessible(true);
61 init.invoke(topicConfigPollingService);
63 List<String> activeTopics = Arrays.asList("test");
64 Field activeTopicsField = topicConfigPollingService.getClass().getDeclaredField("activeTopics");
65 activeTopicsField.setAccessible(true);
66 activeTopicsField.set(topicConfigPollingService, activeTopics);
70 public void testRun() throws InterruptedException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException {
73 when(config.getDmaapCheckNewTopicInterval()).thenReturn(1);
75 Thread thread = new Thread(topicConfigPollingService);
79 topicConfigPollingService.shutdown();
82 assertTrue(topicConfigPollingService.isActiveTopicsChanged(true));
86 public void testRunNoChange() throws InterruptedException {
88 when(config.getDmaapCheckNewTopicInterval()).thenReturn(1);
90 Thread thread = new Thread(topicConfigPollingService);
94 topicConfigPollingService.shutdown();
97 assertFalse(topicConfigPollingService.isActiveTopicsChanged(false));
101 public void testGet() {
102 assertNull(topicConfigPollingService.getEffectiveTopicConfig("test"));
103 assertNull(topicConfigPollingService.getActiveTopics());