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;
40 import org.onap.datalake.feeder.domain.Kafka;
43 * Test TopicConfigPollingService
48 @RunWith(MockitoJUnitRunner.class)
49 public class TopicConfigPollingServiceTest {
51 private ApplicationConfiguration config;
54 private DmaapService dmaapService;
57 private TopicConfigPollingService topicConfigPollingService = new TopicConfigPollingService();
59 public void testInit() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException {
60 Method init = topicConfigPollingService.getClass().getDeclaredMethod("init");
61 init.setAccessible(true);
62 init.invoke(topicConfigPollingService);
64 List<String> activeTopics = Arrays.asList("test");
65 Field activeTopicsField = topicConfigPollingService.getClass().getDeclaredField("activeTopics");
66 activeTopicsField.setAccessible(true);
67 activeTopicsField.set(topicConfigPollingService, activeTopics);
71 public void testRun() throws InterruptedException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException {
74 when(config.getDmaapCheckNewTopicInterval()).thenReturn(1);
76 Thread thread = new Thread(topicConfigPollingService);
80 topicConfigPollingService.shutdown();
83 assertTrue(topicConfigPollingService.isActiveTopicsChanged(true));
87 public void testRunNoChange() throws InterruptedException {
89 when(config.getDmaapCheckNewTopicInterval()).thenReturn(1);
91 Thread thread = new Thread(topicConfigPollingService);
95 topicConfigPollingService.shutdown();
98 assertFalse(topicConfigPollingService.isActiveTopicsChanged(false));
102 public void testGet() {
104 assertNull(topicConfigPollingService.getEffectiveTopicConfig("test"));
105 assertNull(topicConfigPollingService.getActiveTopics(kafka));