84d7d0a91628659a1e171aaa445f620642bfed9c
[dcaegen2/services.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : DATALAKE
4  * ================================================================================
5  * Copyright (C) 2018-2019 Huawei. All rights reserved.
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 package org.onap.datalake.feeder.controller;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.mockito.Mockito.when;
24
25 import java.io.IOException;
26
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.mockito.InjectMocks;
30 import org.mockito.Mock;
31 import org.mockito.junit.MockitoJUnitRunner;
32 import org.onap.datalake.feeder.config.ApplicationConfiguration;
33 import org.onap.datalake.feeder.service.PullService;
34
35 @RunWith(MockitoJUnitRunner.class)
36 public class FeederControllerTest {
37         @Mock
38         private PullService pullService1;
39
40         @Mock
41         private ApplicationConfiguration config;
42
43         @InjectMocks
44         private FeederController feederController;
45
46         @Test
47         public void testStart() throws IOException {
48                 when(pullService1.isRunning()).thenReturn(true);
49                 String start = feederController.start();
50                 assertEquals("{\"running\": true}", start);
51
52                 when(pullService1.isRunning()).thenReturn(false);
53                 start = feederController.start();
54                 assertEquals("{\"running\": true}", start);
55         }
56
57         @Test
58         public void testStop() {
59                 when(pullService1.isRunning()).thenReturn(true);
60                 String stop = feederController.stop();
61                 assertEquals("{\"running\": false}", stop);
62
63                 when(pullService1.isRunning()).thenReturn(false);
64                 stop = feederController.stop();
65                 assertEquals("{\"running\": false}", stop);
66         }
67
68         @Test
69         public void testStatus() {
70                 when(pullService1.isRunning()).thenReturn(false);
71                 when(config.getDatalakeVersion()).thenReturn("0.0.1");
72
73                 String status = feederController.status();
74                 assertEquals("{\"version\": \"0.0.1\", \"running\": false}", status);
75         }
76 }