-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/TINF-XX-endpoint-tests
- Loading branch information
Showing
5 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
src/main/java/de/sakpaas/backend/service/LocationDetailsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
package de.sakpaas.backend.service; | ||
|
||
import de.sakpaas.backend.model.LocationDetails; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface LocationDetailsRepository extends JpaRepository<LocationDetails, Long> { | ||
|
||
Optional<LocationDetails> findById(Long id); | ||
|
||
@Query(value = "SELECT DISTINCT type FROM location_details", nativeQuery = true) | ||
List<String> getAllLocationTypes(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/test/java/de/sakpaas/backend/service/LocationDetailsRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package de.sakpaas.backend.service; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import de.sakpaas.backend.HappyHamsterTest; | ||
import de.sakpaas.backend.model.LocationDetails; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest | ||
class LocationDetailsRepositoryTest extends HappyHamsterTest { | ||
|
||
@Autowired | ||
LocationDetailsRepository locationDetailsRepository; | ||
|
||
@Test | ||
void getAllLocationTypes() { | ||
locationDetailsRepository.deleteAll(); | ||
|
||
assertThat(locationDetailsRepository.getAllLocationTypes().size()).isEqualTo(0); | ||
|
||
locationDetailsRepository | ||
.save(new LocationDetails("testType1", "testOpeningHours1", "testBrand1")); | ||
|
||
assertThat(locationDetailsRepository.getAllLocationTypes().size()).isEqualTo(1); | ||
assertThat(locationDetailsRepository.getAllLocationTypes().contains("testType1")); | ||
|
||
locationDetailsRepository | ||
.save(new LocationDetails("testType2", "testOpeningHours2", "testBrand2")); | ||
|
||
assertThat(locationDetailsRepository.getAllLocationTypes().size()).isEqualTo(2); | ||
assertThat(locationDetailsRepository.getAllLocationTypes().contains("testType1")); | ||
assertThat(locationDetailsRepository.getAllLocationTypes().contains("testType2")); | ||
|
||
locationDetailsRepository | ||
.save(new LocationDetails("testType1", "testOpeningHours3", "testBrand3")); | ||
|
||
assertThat(locationDetailsRepository.getAllLocationTypes().size()).isEqualTo(2); | ||
assertThat(locationDetailsRepository.getAllLocationTypes().contains("testType1")); | ||
assertThat(locationDetailsRepository.getAllLocationTypes().contains("testType2")); | ||
|
||
locationDetailsRepository.deleteAll(); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/test/java/de/sakpaas/backend/v2/controller/LocationControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package de.sakpaas.backend.v2.controller; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import de.sakpaas.backend.HappyHamsterTest; | ||
import de.sakpaas.backend.service.LocationService; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import lombok.SneakyThrows; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mockito; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
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.junit4.SpringRunner; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest | ||
@AutoConfigureMockMvc | ||
@EnableConfigurationProperties | ||
class LocationControllerTest extends HappyHamsterTest { | ||
|
||
@MockBean | ||
LocationService locationService; | ||
@Autowired | ||
private MockMvc mvc; | ||
|
||
@SneakyThrows | ||
@Test | ||
void getLocationTypesTest() { | ||
List<String> locationTypes = new ArrayList<>(); | ||
locationTypes.add("testType1"); | ||
locationTypes.add("testType2"); | ||
|
||
Mockito.when(locationService.getAllLocationTypes()).thenReturn(locationTypes); | ||
|
||
String resultJson = mvc.perform(get("/v2/locations/types") | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()) | ||
.andReturn() | ||
.getResponse() | ||
.getContentAsString(); | ||
|
||
String compareJson = new ObjectMapper().writeValueAsString(locationTypes); | ||
assertThat(compareJson, equalTo(resultJson)); | ||
} | ||
|
||
} |