From 753b309c3ccf576e7b8821fa5cce318a41dc821e Mon Sep 17 00:00:00 2001 From: Victor Mosin Date: Sat, 7 Jan 2017 17:31:53 +0100 Subject: [PATCH] Added ConverterFactory test --- .../baeldung/controller/GenericEntityController.java | 6 ++++++ .../src/main/java/org/baeldung/domain/Modes.java | 6 ++++++ .../baeldung/SpringBootApplicationIntegrationTest.java | 10 ++++++++++ 3 files changed, 22 insertions(+) create mode 100644 spring-boot/src/main/java/org/baeldung/domain/Modes.java diff --git a/spring-boot/src/main/java/org/baeldung/controller/GenericEntityController.java b/spring-boot/src/main/java/org/baeldung/controller/GenericEntityController.java index 9af08f7b28..c8649e0d3e 100644 --- a/spring-boot/src/main/java/org/baeldung/controller/GenericEntityController.java +++ b/spring-boot/src/main/java/org/baeldung/controller/GenericEntityController.java @@ -1,6 +1,7 @@ package org.baeldung.controller; import org.baeldung.domain.GenericEntity; +import org.baeldung.domain.Modes; import org.baeldung.web.resolver.Version; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -45,6 +46,11 @@ public class GenericEntityController { return entityList.stream().findFirst().get(); } + @RequestMapping("/entity/findbymode/{mode}") + public GenericEntity findByEnum(@PathVariable("mode") Modes mode) { + return entityList.stream().findFirst().get(); + } + @RequestMapping("/entity/findbyversion") public ResponseEntity findByVersion(@Version String version) { return version != null diff --git a/spring-boot/src/main/java/org/baeldung/domain/Modes.java b/spring-boot/src/main/java/org/baeldung/domain/Modes.java new file mode 100644 index 0000000000..41b1fa0d4e --- /dev/null +++ b/spring-boot/src/main/java/org/baeldung/domain/Modes.java @@ -0,0 +1,6 @@ +package org.baeldung.domain; + +public enum Modes { + + Alpha, Beta; +} diff --git a/spring-boot/src/test/java/org/baeldung/SpringBootApplicationIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/SpringBootApplicationIntegrationTest.java index 7410166f0c..94623d3cdd 100644 --- a/spring-boot/src/test/java/org/baeldung/SpringBootApplicationIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/SpringBootApplicationIntegrationTest.java @@ -50,6 +50,16 @@ public class SpringBootApplicationIntegrationTest { .andExpect(jsonPath("$.id", equalTo(1))); } + @Test + public void givenRequestHasBeenMade_whenMeetsFindByModeOfGivenConditions_thenCorrect() throws Exception { + MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8")); + + mockMvc.perform(MockMvcRequestBuilders.get("/entity/findbymode/{mode}", "Alpha")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentType(contentType)) + .andExpect(jsonPath("$.id", equalTo(1))); + } + @Test public void givenRequestHasBeenMade_whenMeetsFindByVersionOfGivenConditions_thenCorrect() throws Exception { MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));