SI-1081 UnitTests
diff --git a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/config/TestConfiguration.java b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/config/TestConfiguration.java
index dd12970..f999e39 100644
--- a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/config/TestConfiguration.java
+++ b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/config/TestConfiguration.java
@@ -42,6 +42,12 @@
@TestPropertySource("spring.config.location=classpath:application.yml")
public class TestConfiguration {
@Bean
+ FESettingsMapper feSettingsMapper(){return new FESettingsMapperImpl();}
+
+ @Bean
+ SettingsService settingsService(){return new SettingsService();}
+
+ @Bean
FESettings fESettings(){return new FESettings();}
@Bean
diff --git a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/controller/SettingsControllerTest.java b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/controller/SettingsControllerTest.java
index 9dfd7d8..5daa3ef 100644
--- a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/controller/SettingsControllerTest.java
+++ b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/controller/SettingsControllerTest.java
@@ -15,22 +15,13 @@
package org.eclipse.openk.gridfailureinformation.controller;
import org.eclipse.openk.gridfailureinformation.GridFailureInformationApplication;
-import org.eclipse.openk.gridfailureinformation.service.AddressService;
-import org.eclipse.openk.gridfailureinformation.support.MockDataHelper;
-import org.eclipse.openk.gridfailureinformation.viewmodel.HousenumberUuidDto;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
-
-import java.util.List;
-import java.util.Optional;
-
-import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@@ -40,191 +31,16 @@
@ActiveProfiles("test")
public class SettingsControllerTest {
- @MockBean
- private AddressService addressService;
-
@Autowired
private MockMvc mockMvc;
-
@Test
public void shouldReturnPostCodes() throws Exception {
- Optional<String> branchOptional = Optional.empty();
- List<String> postcodes = MockDataHelper.mockPostCodes();
- when(addressService.getPostcodes(branchOptional)).thenReturn(postcodes);
- mockMvc.perform(get("/addresses/postcodes"))
+ mockMvc.perform(get("/settings"))
.andExpect(status().is2xxSuccessful())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
-
- verify(addressService, times(1)).getPostcodes(branchOptional);
}
- @Test
- public void shouldReturnPostCodesForBranch() throws Exception {
- String branch = "B";
- Optional<String> branchOptional = Optional.of(branch);
- List<String> postcodes = MockDataHelper.mockPostCodes();
- when(addressService.getPostcodes(branchOptional)).thenReturn(postcodes);
- mockMvc.perform(get("/addresses/postcodes?branch=" + branch))
- .andExpect(status().is2xxSuccessful())
- .andExpect(content().contentType(MediaType.APPLICATION_JSON));
-
- verify(addressService, times(1)).getPostcodes(branchOptional);
- }
-
- @Test
- public void shouldReturnCommunities() throws Exception {
- String postcode = "71111";
- Optional<String> branchOptional = Optional.empty();
- List<String> strings = MockDataHelper.mockStringList();
- when(addressService.getCommunities(postcode, branchOptional)).thenReturn(strings);
-
- mockMvc.perform(get("/addresses/communities/" + postcode))
- .andExpect(status().is2xxSuccessful())
- .andExpect(content().contentType(MediaType.APPLICATION_JSON));
-
- verify(addressService, times(1)).getCommunities(postcode, branchOptional);
- }
-
- @Test
- public void shouldReturnCommunitiesForBranch() throws Exception {
- String branch = "B";
- String postcode = "71111";
- Optional<String> branchOptional = Optional.of(branch);
- List<String> strings = MockDataHelper.mockStringList();
- when(addressService.getCommunities(postcode, branchOptional)).thenReturn(strings);
-
- mockMvc.perform(get("/addresses/communities/" + postcode + "?branch=" + branch))
- .andExpect(status().is2xxSuccessful())
- .andExpect(content().contentType(MediaType.APPLICATION_JSON));
-
- verify(addressService, times(1)).getCommunities(postcode, branchOptional);
- }
-
- @Test
- public void shouldReturnDistricts() throws Exception {
- String postcode = "71111";
- String community = "com1";
- Optional<String> branchOptional = Optional.empty();
- List<String> strings = MockDataHelper.mockStringList();
- when(addressService.getDistricts(postcode, community, branchOptional)).thenReturn(strings);
-
- mockMvc.perform(
- get("/addresses/districts")
- .param("postcode", postcode)
- .param("community", community)
- )
- .andExpect(status().is2xxSuccessful())
- .andExpect(content().contentType(MediaType.APPLICATION_JSON));
-
- verify(addressService, times(1)).getDistricts(postcode, community, branchOptional);
- }
-
- @Test
- public void shouldReturnDistrictsForBranch() throws Exception {
- String postcode = "71111";
- String community = "com1";
- String branch = "B";
- Optional<String> branchOptional = Optional.of(branch);
- List<String> strings = MockDataHelper.mockStringList();
- when(addressService.getDistricts(postcode, community, branchOptional)).thenReturn(strings);
-
- mockMvc.perform(
- get("/addresses/districts?branch=" + branch)
- .param("postcode", postcode)
- .param("community", community)
- )
- .andExpect(status().is2xxSuccessful())
- .andExpect(content().contentType(MediaType.APPLICATION_JSON));
-
- verify(addressService, times(1)).getDistricts(postcode, community, branchOptional);
- }
-
- @Test
- public void shouldReturnStreets() throws Exception {
- String postcode = "71111";
- String community = "com1";
- Optional<String> district = Optional.of("district1");
- Optional<String> branchOptional = Optional.empty();
- List<String> strings = MockDataHelper.mockStringList();
- when(addressService.getStreets(postcode, community, district, branchOptional)).thenReturn(strings);
-
- mockMvc.perform(
- get("/addresses/streets")
- .param("postcode", postcode)
- .param("community", community)
- .param("district", "district1")
- )
- .andExpect(status().is2xxSuccessful())
- .andExpect(content().contentType(MediaType.APPLICATION_JSON));
-
- verify(addressService, times(1)).getStreets(postcode, community, district, branchOptional);
- }
-
- @Test
- public void shouldReturnStreetsForBranch() throws Exception {
- String postcode = "71111";
- String community = "com1";
- String branch = "B";
- Optional<String> district = Optional.of("district1");
- Optional<String> branchOptional = Optional.of(branch);
- List<String> strings = MockDataHelper.mockStringList();
- when(addressService.getStreets(postcode, community, district, branchOptional)).thenReturn(strings);
-
- mockMvc.perform(
- get("/addresses/streets?branch=" + branch)
- .param("postcode", postcode)
- .param("community", community)
- .param("district", "district1")
- )
- .andExpect(status().is2xxSuccessful())
- .andExpect(content().contentType(MediaType.APPLICATION_JSON));
-
- verify(addressService, times(1)).getStreets(postcode, community, district, branchOptional);
- }
-
- @Test
- public void shouldReturnHousenumbers() throws Exception {
- String postcode = "71111";
- String community = "com1";
- String street = "street1";
- Optional<String> branchOptional = Optional.empty();
- List<HousenumberUuidDto> housenumberUuidDtos = MockDataHelper.mockHousnumberUuidList();
- when(addressService.getHousenumbers(postcode, community, street, branchOptional)).thenReturn(housenumberUuidDtos);
-
- mockMvc.perform(
- get("/addresses/housenumbers")
- .param("postcode", postcode)
- .param("community", community)
- .param("street", street)
- )
- .andExpect(status().is2xxSuccessful())
- .andExpect(content().contentType(MediaType.APPLICATION_JSON));
-
- verify(addressService, times(1)).getHousenumbers(postcode, community, street, branchOptional);
- }
-
- @Test
- public void shouldReturnHousenumbersForBranch() throws Exception {
- String postcode = "71111";
- String community = "com1";
- String street = "street1";
- String branch = "B";
- Optional<String> branchOptional = Optional.of(branch);
- List<HousenumberUuidDto> housenumberUuidDtos = MockDataHelper.mockHousnumberUuidList();
- when(addressService.getHousenumbers(postcode, community, street, branchOptional)).thenReturn(housenumberUuidDtos);
-
- mockMvc.perform(
- get("/addresses/housenumbers?branch=" + branch)
- .param("postcode", postcode)
- .param("community", community)
- .param("street", street)
- )
- .andExpect(status().is2xxSuccessful())
- .andExpect(content().contentType(MediaType.APPLICATION_JSON));
-
- verify(addressService, times(1)).getHousenumbers(postcode, community, street, branchOptional);
- }
}
\ No newline at end of file
diff --git a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/SettingsServiceTest.java b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/SettingsServiceTest.java
new file mode 100644
index 0000000..f85d4d4
--- /dev/null
+++ b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/SettingsServiceTest.java
@@ -0,0 +1,51 @@
+/*
+ *******************************************************************************
+ * Copyright (c) 2019 Contributors to the Eclipse Foundation
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************
+ */
+package org.eclipse.openk.gridfailureinformation.service;
+
+import org.eclipse.openk.gridfailureinformation.config.TestConfiguration;
+import org.eclipse.openk.gridfailureinformation.model.TblAddress;
+import org.eclipse.openk.gridfailureinformation.repository.AddressRepository;
+import org.eclipse.openk.gridfailureinformation.support.MockDataHelper;
+import org.eclipse.openk.gridfailureinformation.viewmodel.AddressDto;
+import org.eclipse.openk.gridfailureinformation.viewmodel.FESettingsDto;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.test.context.ContextConfiguration;
+import java.util.List;
+import java.util.Optional;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.mockito.Mockito.when;
+
+@DataJpaTest
+@ContextConfiguration(classes = {TestConfiguration.class})
+
+public class SettingsServiceTest {
+
+ @Autowired
+ private SettingsService settingsService;
+
+ @Test
+ public void shouldGetFESettings() {
+
+ FESettingsDto feSettingsDto = settingsService.getFESettings();
+
+ assertFalse(feSettingsDto.getDetailMapInitialZoom() == null);
+ assertFalse(feSettingsDto.getOverviewMapInitialZoom()== null);
+ assertFalse(feSettingsDto.getExportChannels() == null);
+ }
+}