731b9a29cce07cd030a09d10924b704cfbbb961e
[dcaegen2/services.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : DATALAKE
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
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.datalake.feeder.service;
22
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;
27
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;
33
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;
41
42 /**
43  * Test TopicConfigPollingService
44  * 
45  * @author Guobiao Mo
46  *
47  */
48 @RunWith(MockitoJUnitRunner.class)
49 public class TopicConfigPollingServiceTest {
50         @Mock
51         private ApplicationConfiguration config;
52
53         @Mock
54         private DmaapService dmaapService;
55
56         @InjectMocks
57         private TopicConfigPollingService topicConfigPollingService = new TopicConfigPollingService();
58
59         @Test
60         public void testRun() {
61                 
62         }
63         
64         /*
65         public void testInit() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException {
66                 Method init = topicConfigPollingService.getClass().getDeclaredMethod("init");
67                 init.setAccessible(true);
68                 init.invoke(topicConfigPollingService);
69
70                 List<String> activeTopics = Arrays.asList("test");
71                 Field activeTopicsField = topicConfigPollingService.getClass().getDeclaredField("activeTopics");
72                 activeTopicsField.setAccessible(true);
73                 activeTopicsField.set(topicConfigPollingService, activeTopics);
74         }
75
76         @Test
77         public void testRun() throws InterruptedException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException {
78                 testInit();
79
80                 //when(config.getDmaapCheckNewTopicInterval()).thenReturn(1);
81
82                 Thread thread = new Thread(topicConfigPollingService);
83                 thread.start();
84
85                 Thread.sleep(50);
86                 topicConfigPollingService.shutdown();
87                 thread.join();
88
89                 assertTrue(topicConfigPollingService.isActiveTopicsChanged(new Kafka()));
90         }
91
92         @Test
93         public void testRunNoChange() throws InterruptedException {
94         
95 //              when(config.getDmaapCheckNewTopicInterval()).thenReturn(1);
96
97                 Thread thread = new Thread(topicConfigPollingService);
98                 thread.start();
99
100                 Thread.sleep(50);
101                 topicConfigPollingService.shutdown();
102                 thread.join();
103
104                 assertFalse(topicConfigPollingService.isActiveTopicsChanged(new Kafka()));
105         }
106
107         @Test
108         public void testGet() {
109                 Kafka kafka=null;
110                 assertNull(topicConfigPollingService.getEffectiveTopic (new Kafka(), "test"));
111                 assertNull(topicConfigPollingService.getActiveTopics(kafka));
112
113         }
114         */
115 }