diff options
Diffstat (limited to 'components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicConfigPollingServiceTest.java')
-rw-r--r-- | components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicConfigPollingServiceTest.java | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicConfigPollingServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicConfigPollingServiceTest.java index a341d2a6..bd26519b 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicConfigPollingServiceTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicConfigPollingServiceTest.java @@ -20,8 +20,7 @@ package org.onap.datalake.feeder.service; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; @@ -29,14 +28,20 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; -import java.util.List; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.datalake.feeder.config.ApplicationConfiguration; +import org.onap.datalake.feeder.domain.Kafka; +import org.onap.datalake.feeder.util.TestUtil; /** * Test TopicConfigPollingService @@ -55,22 +60,31 @@ public class TopicConfigPollingServiceTest { @InjectMocks private TopicConfigPollingService topicConfigPollingService = new TopicConfigPollingService(); - public void testInit() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException { + static String KAFKA_NAME = "kafka1"; + + @Before + public void init() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException { Method init = topicConfigPollingService.getClass().getDeclaredMethod("init"); init.setAccessible(true); init.invoke(topicConfigPollingService); - List<String> activeTopics = Arrays.asList("test"); - Field activeTopicsField = topicConfigPollingService.getClass().getDeclaredField("activeTopics"); + Set<String> activeTopics = new HashSet<>(Arrays.asList("test")); + Map<Integer, Set<String>> activeTopicMap = new HashMap<>(); + activeTopicMap.put(1, activeTopics); + + Field activeTopicsField = TopicConfigPollingService.class.getDeclaredField("activeTopicMap"); activeTopicsField.setAccessible(true); - activeTopicsField.set(topicConfigPollingService, activeTopics); + activeTopicsField.set(topicConfigPollingService, activeTopicMap); + + Method initMethod = TopicConfigPollingService.class.getDeclaredMethod("init"); + initMethod.setAccessible(true); + initMethod.invoke(topicConfigPollingService); } @Test - public void testRun() throws InterruptedException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException { - testInit(); + public void testRun() throws InterruptedException { - when(config.getDmaapCheckNewTopicInterval()).thenReturn(1); + when(config.getCheckTopicInterval()).thenReturn(1L); Thread thread = new Thread(topicConfigPollingService); thread.start(); @@ -79,13 +93,13 @@ public class TopicConfigPollingServiceTest { topicConfigPollingService.shutdown(); thread.join(); - assertTrue(topicConfigPollingService.isActiveTopicsChanged(true)); + assertTrue(topicConfigPollingService.isActiveTopicsChanged(new Kafka())); } @Test public void testRunNoChange() throws InterruptedException { - - when(config.getDmaapCheckNewTopicInterval()).thenReturn(1); + + when(config.getCheckTopicInterval()).thenReturn(1L); Thread thread = new Thread(topicConfigPollingService); thread.start(); @@ -94,13 +108,16 @@ public class TopicConfigPollingServiceTest { topicConfigPollingService.shutdown(); thread.join(); - assertFalse(topicConfigPollingService.isActiveTopicsChanged(false)); + assertTrue(topicConfigPollingService.isActiveTopicsChanged(new Kafka())); } @Test public void testGet() { - assertNull(topicConfigPollingService.getEffectiveTopicConfig("test")); - assertNull(topicConfigPollingService.getActiveTopics()); + Kafka kafka = TestUtil.newKafka(KAFKA_NAME); + kafka.setId(1); + //assertNull(topicConfigPollingService.getEffectiveTopic (kafka, "test")); + assertNotNull(topicConfigPollingService.getActiveTopics(kafka)); } + }
\ No newline at end of file |