Applied latest changes
This commit is contained in:
parent
55113dd8fd
commit
02826096e9
|
@ -5,6 +5,7 @@ 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;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
@ -41,17 +42,17 @@ public class GenericEntityController {
|
||||||
return entityList.stream().filter(entity -> entity.getId().equals(id)).findFirst().get();
|
return entityList.stream().filter(entity -> entity.getId().equals(id)).findFirst().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/entity/findbydate/{date}")
|
@GetMapping("/entity/findbydate/{date}")
|
||||||
public GenericEntity findByDate(@PathVariable("date") LocalDateTime date) {
|
public GenericEntity findByDate(@PathVariable("date") LocalDateTime date) {
|
||||||
return entityList.stream().findFirst().get();
|
return entityList.stream().findFirst().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/entity/findbymode/{mode}")
|
@GetMapping("/entity/findbymode/{mode}")
|
||||||
public GenericEntity findByEnum(@PathVariable("mode") Modes mode) {
|
public GenericEntity findByEnum(@PathVariable("mode") Modes mode) {
|
||||||
return entityList.stream().findFirst().get();
|
return entityList.stream().findFirst().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/entity/findbyversion")
|
@GetMapping("/entity/findbyversion")
|
||||||
public ResponseEntity findByVersion(@Version String version) {
|
public ResponseEntity findByVersion(@Version String version) {
|
||||||
return version != null
|
return version != null
|
||||||
? new ResponseEntity(entityList.stream().findFirst().get(), HttpStatus.OK)
|
? new ResponseEntity(entityList.stream().findFirst().get(), HttpStatus.OK)
|
||||||
|
|
|
@ -5,17 +5,12 @@ import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.format.DateTimeParseException;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class StringToLocalDateTimeConverter implements Converter<String, LocalDateTime> {
|
public class StringToLocalDateTimeConverter implements Converter<String, LocalDateTime> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LocalDateTime convert(final String source) {
|
public LocalDateTime convert(final String source) {
|
||||||
try {
|
return LocalDateTime.parse(source, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
|
||||||
return LocalDateTime.parse(source, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
|
|
||||||
} catch (DateTimeParseException e) {
|
|
||||||
throw new IllegalArgumentException("Couldn't parse value");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,5 +2,5 @@ package org.baeldung.domain;
|
||||||
|
|
||||||
public enum Modes {
|
public enum Modes {
|
||||||
|
|
||||||
Alpha, Beta;
|
ALPHA, BETA;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.hasSize;
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
|
|
||||||
|
import org.baeldung.domain.Modes;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -54,7 +55,7 @@ public class SpringBootApplicationIntegrationTest {
|
||||||
public void givenRequestHasBeenMade_whenMeetsFindByModeOfGivenConditions_thenCorrect() throws Exception {
|
public void givenRequestHasBeenMade_whenMeetsFindByModeOfGivenConditions_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"));
|
||||||
|
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/entity/findbymode/{mode}", "Alpha"))
|
mockMvc.perform(MockMvcRequestBuilders.get("/entity/findbymode/{mode}", Modes.ALPHA.name()))
|
||||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||||
.andExpect(MockMvcResultMatchers.content().contentType(contentType))
|
.andExpect(MockMvcResultMatchers.content().contentType(contentType))
|
||||||
.andExpect(jsonPath("$.id", equalTo(1)));
|
.andExpect(jsonPath("$.id", equalTo(1)));
|
||||||
|
|
Loading…
Reference in New Issue