8aa60abc80e6952135f1f42ae91ff19fe07608b3
[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.assertEquals;
24 import static org.junit.Assert.assertNull;
25 import static org.mockito.Mockito.when;
26
27 import java.util.Optional;
28
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.InjectMocks;
32 import org.mockito.Mock;
33 import org.mockito.junit.MockitoJUnitRunner;
34 import org.onap.datalake.feeder.domain.Db;
35 import org.onap.datalake.feeder.repository.DbRepository;
36
37 /**
38  * Test Service for Dbs 
39  * 
40  * @author Guobiao Mo
41  *
42  */
43 @RunWith(MockitoJUnitRunner.class)
44 public class DbServiceTest {
45
46         @Mock
47         private DbRepository dbRepository;
48         
49         @InjectMocks
50         private DbService dbService;
51
52         @Test
53         public void testGetDb() {
54                 String name = "a";
55                 when(dbRepository.findById(name)).thenReturn(Optional.of(new Db(name)));
56                 assertEquals(dbService.getDb(name), new Db(name));
57         }
58
59         @Test
60         public void testGetDbNull() {
61                 String name = null;
62                 when(dbRepository.findById(name)).thenReturn(Optional.empty());
63                 assertNull(dbService.getDb(name));
64         }
65
66         @Test
67         public void testGetCouchbase() {
68                 String name = "Couchbase";
69                 when(dbRepository.findById(name)).thenReturn(Optional.of(new Db(name)));
70                 assertEquals(dbService.getCouchbase(), new Db(name));
71         }
72
73         @Test
74         public void testGetElasticsearch() {
75                 String name = "Elasticsearch";
76                 when(dbRepository.findById(name)).thenReturn(Optional.of(new Db(name)));
77                 assertEquals(dbService.getElasticsearch(), new Db(name));
78         }
79
80         @Test
81         public void testGetMongoDB() {
82                 String name = "MongoDB";
83                 when(dbRepository.findById(name)).thenReturn(Optional.of(new Db(name)));
84                 assertEquals(dbService.getMongoDB(), new Db(name));
85         }
86
87         @Test
88         public void testGetDruid() {
89                 String name = "Druid";
90                 when(dbRepository.findById(name)).thenReturn(Optional.of(new Db(name)));
91                 assertEquals(dbService.getDruid(), new Db(name));
92         }
93
94         @Test
95         public void testGetHdfs() {
96                 String name = "HDFS";
97                 when(dbRepository.findById(name)).thenReturn(Optional.of(new Db(name)));
98                 assertEquals(dbService.getHdfs(), new Db(name));
99         }
100
101 }