Added ConverterFactory test

This commit is contained in:
Victor Mosin 2017-01-07 17:31:53 +01:00 committed by Victor Mosin
parent 89f9f8c6bf
commit 753b309c3c
3 changed files with 22 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package org.baeldung.controller; package org.baeldung.controller;
import org.baeldung.domain.GenericEntity; import org.baeldung.domain.GenericEntity;
import org.baeldung.domain.Modes;
import org.baeldung.web.resolver.Version; import org.baeldung.web.resolver.Version;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -45,6 +46,11 @@ public class GenericEntityController {
return entityList.stream().findFirst().get(); return entityList.stream().findFirst().get();
} }
@RequestMapping("/entity/findbymode/{mode}")
public GenericEntity findByEnum(@PathVariable("mode") Modes mode) {
return entityList.stream().findFirst().get();
}
@RequestMapping("/entity/findbyversion") @RequestMapping("/entity/findbyversion")
public ResponseEntity findByVersion(@Version String version) { public ResponseEntity findByVersion(@Version String version) {
return version != null return version != null

View File

@ -0,0 +1,6 @@
package org.baeldung.domain;
public enum Modes {
Alpha, Beta;
}

View File

@ -50,6 +50,16 @@ public class SpringBootApplicationIntegrationTest {
.andExpect(jsonPath("$.id", equalTo(1))); .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 @Test
public void givenRequestHasBeenMade_whenMeetsFindByVersionOfGivenConditions_thenCorrect() throws Exception { public void givenRequestHasBeenMade_whenMeetsFindByVersionOfGivenConditions_thenCorrect() throws Exception {
MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8")); MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));