summaryrefslogtreecommitdiffstats
path: root/components/datalake-handler/feeder/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'components/datalake-handler/feeder/src/test')
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/KafkaControllerTest.java83
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/KafkaConfigTest.java33
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignTypeServiceTest.java59
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/KafkaServiceTest.java70
4 files changed, 245 insertions, 0 deletions
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/KafkaControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/KafkaControllerTest.java
new file mode 100644
index 00000000..1469e938
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/KafkaControllerTest.java
@@ -0,0 +1,83 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : DataLake
+ * ================================================================================
+ * Copyright 2019 China Mobile
+ *=================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.datalake.feeder.controller;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.datalake.feeder.domain.Kafka;
+import org.onap.datalake.feeder.dto.KafkaConfig;
+import org.onap.datalake.feeder.repository.KafkaRepository;
+import org.onap.datalake.feeder.service.KafkaService;
+import org.springframework.validation.BindingResult;
+
+import javax.servlet.http.HttpServletResponse;
+
+import java.io.IOException;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class KafkaControllerTest {
+
+ @Mock
+ private HttpServletResponse httpServletResponse;
+
+ @Mock
+ private BindingResult mockBindingResult;
+
+ @Mock
+ private KafkaService kafkaService;
+
+ @Mock
+ private KafkaRepository kafkaRepository;
+
+ @Mock
+ private Kafka kafka;
+
+ @InjectMocks
+ private KafkaController kafkaController;
+ @Test
+ public void createKafka() throws IOException {
+ String id = "123";
+ KafkaConfig kafkaConfig = new KafkaConfig();
+ kafkaConfig.setId(id);
+ kafkaConfig.setName("123");
+ when(kafkaService.getKafkaById(kafkaConfig.getId())).thenReturn(null).thenReturn(kafka);
+ when(kafkaRepository.save(kafka)).thenReturn(null);
+ when(kafkaService.fillKafkaConfiguration(kafkaConfig)).thenReturn(kafka);
+ when(mockBindingResult.hasErrors()).thenReturn(false,true,false,true);
+
+ kafkaController.createKafka(kafkaConfig,mockBindingResult,httpServletResponse);
+ kafkaController.createKafka(kafkaConfig,mockBindingResult,httpServletResponse);
+
+ kafkaController.updateKafka(kafkaConfig,mockBindingResult,id,httpServletResponse);
+ kafkaController.updateKafka(kafkaConfig,mockBindingResult,id,httpServletResponse);
+
+ kafkaController.deleteKafka(id,httpServletResponse);
+
+ when(kafkaService.getAllKafka()).thenReturn(null);
+ kafkaController.queryAllKafka();
+ }
+} \ No newline at end of file
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/KafkaConfigTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/KafkaConfigTest.java
new file mode 100644
index 00000000..7ab22733
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/KafkaConfigTest.java
@@ -0,0 +1,33 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : DataLake
+ * ================================================================================
+ * Copyright 2019 China Mobile
+ *=================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.datalake.feeder.dto;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class KafkaConfigTest {
+
+ @Test
+ public void testKafkaConfig(){
+ KafkaConfig kafkaConfig = new KafkaConfig();
+ }
+
+} \ No newline at end of file
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignTypeServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignTypeServiceTest.java
new file mode 100644
index 00000000..5879deb6
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignTypeServiceTest.java
@@ -0,0 +1,59 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : DataLake
+ * ================================================================================
+ * Copyright 2019 China Mobile
+ *=================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.datalake.feeder.service;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.datalake.feeder.domain.DesignType;
+import org.onap.datalake.feeder.dto.DesignTypeConfig;
+import org.onap.datalake.feeder.repository.DesignTypeRepository;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class DesignTypeServiceTest {
+
+ @Mock
+ private DesignTypeRepository designTypeRepository;
+
+ @InjectMocks
+ private DesignTypeService designTypeService;
+
+ @Test
+ public void testDesignTypeService(){
+ List<DesignType> designTypeList = new ArrayList<>();
+ DesignType designType = new DesignType();
+ designType.setName("test");
+ //DesignTypeConfig designTypeConfig = new DesignTypeConfig();
+ //designTypeConfig.setDesignType("test");
+ //designTypeConfig.setDisplay("test");
+ designTypeList.add(designType);
+ when(designTypeRepository.findAll()).thenReturn(designTypeList);
+ assertNotNull(designTypeService.getDesignTypes());
+ }
+
+} \ No newline at end of file
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/KafkaServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/KafkaServiceTest.java
new file mode 100644
index 00000000..3bdeb1a2
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/KafkaServiceTest.java
@@ -0,0 +1,70 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : DATALAKE
+ * ================================================================================
+ * Copyright 2019 China Mobile
+ *=================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.datalake.feeder.service;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.datalake.feeder.domain.Kafka;
+import org.onap.datalake.feeder.dto.KafkaConfig;
+import org.onap.datalake.feeder.repository.KafkaRepository;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class KafkaServiceTest {
+
+ @InjectMocks
+ private KafkaService kafkaService;
+
+ @Mock
+ private KafkaRepository kafkaRepository;
+
+ @Mock
+ private KafkaConfig kafkaConfig;
+
+ @Test
+ public void testKafkaServer(){
+ String kafkaId = "123";
+ Kafka kafka = new Kafka();
+ kafka.setId(kafkaId);
+
+ List<Kafka> kafkas = new ArrayList<>();
+ kafkas.add(kafka);
+
+ when(kafkaRepository.findById(kafkaId)).thenReturn(Optional.of(kafka));
+ Kafka kafkaById = kafkaService.getKafkaById(kafkaId);
+ assertEquals(kafka,kafkaById);
+
+ when(kafkaRepository.findAll()).thenReturn(kafkas);
+ assertNotNull(kafkaService.getAllKafka());
+
+ kafkaService.fillKafkaConfiguration(kafkaConfig);
+ }
+
+} \ No newline at end of file