e2cca64c84753f171e291dc808357b22430551f6
[dcaegen2/services.git] / components / datalake-handler / feeder / src / test / java / org / onap / datalake / feeder / service / TopicServiceTest.java
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.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.assertTrue;
28 import static org.mockito.Mockito.doThrow;
29 import static org.mockito.Mockito.when;
30
31 import java.io.IOException;
32 import java.util.HashSet;
33 import java.util.Optional;
34 import java.util.Set;
35
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.mockito.InjectMocks;
39 import org.mockito.Mock;
40 import org.mockito.junit.MockitoJUnitRunner;
41 import org.onap.datalake.feeder.config.ApplicationConfiguration;
42 import org.onap.datalake.feeder.domain.Db;
43 import org.onap.datalake.feeder.domain.Topic;
44 import org.onap.datalake.feeder.repository.TopicRepository;
45 import org.onap.datalake.feeder.service.db.ElasticsearchService;
46
47 /**
48  * Test Service for Topic
49  * 
50  * @author Guobiao Mo
51  *
52  */
53 @RunWith(MockitoJUnitRunner.class)
54 public class TopicServiceTest {
55
56         static String DEFAULT_TOPIC_NAME = "_DL_DEFAULT_";
57
58         @Mock
59         private ApplicationConfiguration config;
60         
61         @Mock
62         private TopicRepository topicRepository;
63
64         @Mock
65         private ElasticsearchService elasticsearchService;
66
67         @InjectMocks
68         private TopicService topicService;
69
70         /*
71         @Test
72         public void testGetTopic() {
73                 String name = "a";
74                 when(topicRepository.findById(name)).thenReturn(Optional.of(new Topic(name)));
75                 assertEquals(topicService.getTopic(name), new Topic(name));
76                 
77                 assertFalse(topicService.istDefaultTopic(new Topic(name)));
78         }
79 */
80         @Test
81         public void testGetTopicNull() {
82                 String name = null;
83 //              when(topicRepository.findById(0)).thenReturn(null);
84                 assertNull(topicService.getTopic(0));
85         }
86
87 /*
88         @Test
89         public void testGetEffectiveTopic() throws IOException {
90                 String name = "a";
91                 Topic topic = new Topic(name);
92                 topic.setEnabled(true);
93                 Set<Db> dbSet = new HashSet<>();
94                 dbSet.add(new Db("Elasticsearch"));
95                 topic.setDbs(dbSet);
96
97                 when(config.getDefaultTopicName()).thenReturn(DEFAULT_TOPIC_NAME);
98                 when(topicRepository.findById(DEFAULT_TOPIC_NAME)).thenReturn(Optional.of(topic));
99                 when(topicRepository.findById(name)).thenReturn(Optional.of(topic));
100                 when(topicRepository.findById(null)).thenReturn(Optional.empty());
101
102                 assertEquals(topicService.getEffectiveTopic(name), topicService.getEffectiveTopic(name, false));
103
104                 assertNotNull(topicService.getEffectiveTopic(null));
105
106                 topicService.getEffectiveTopic(name, true);
107         }
108 */
109 }