2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.datalake.feeder.controller;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.mockito.InjectMocks;
26 import org.mockito.Mock;
27 import org.mockito.junit.MockitoJUnitRunner;
28 import org.onap.datalake.feeder.domain.Kafka;
29 import org.onap.datalake.feeder.dto.KafkaConfig;
30 import org.onap.datalake.feeder.repository.KafkaRepository;
31 import org.onap.datalake.feeder.service.KafkaService;
32 import org.springframework.validation.BindingResult;
34 import javax.servlet.http.HttpServletResponse;
36 import java.io.IOException;
38 import static org.junit.Assert.*;
39 import static org.mockito.Mockito.when;
41 @RunWith(MockitoJUnitRunner.class)
42 public class KafkaControllerTest {
45 private HttpServletResponse httpServletResponse;
48 private BindingResult mockBindingResult;
51 private KafkaService kafkaService;
54 private KafkaRepository kafkaRepository;
60 private KafkaController kafkaController;
62 public void createKafka() throws IOException {
64 KafkaConfig kafkaConfig = new KafkaConfig();
65 kafkaConfig.setId(id);
66 kafkaConfig.setName("123");
67 when(kafkaService.getKafkaById(kafkaConfig.getId())).thenReturn(null).thenReturn(kafka);
68 when(kafkaRepository.save(kafka)).thenReturn(null);
69 when(kafkaService.fillKafkaConfiguration(kafkaConfig)).thenReturn(kafka);
70 when(mockBindingResult.hasErrors()).thenReturn(false,true,false,true);
72 kafkaController.createKafka(kafkaConfig,mockBindingResult,httpServletResponse);
73 kafkaController.createKafka(kafkaConfig,mockBindingResult,httpServletResponse);
75 kafkaController.updateKafka(kafkaConfig,mockBindingResult,id,httpServletResponse);
76 kafkaController.updateKafka(kafkaConfig,mockBindingResult,id,httpServletResponse);
78 kafkaController.deleteKafka(id,httpServletResponse);
80 when(kafkaService.getAllKafka()).thenReturn(null);
81 kafkaController.queryAllKafka();