From 8eb5074770eb8d943e0aee0bcdc28f62149e7344 Mon Sep 17 00:00:00 2001 From: Aiden-at-508687582768 Date: Sun, 27 May 2018 01:40:43 -0400 Subject: [PATCH 1/2] Fix content negotiation for /vets See gh-326 --- .../springframework/samples/petclinic/vet/VetController.java | 2 +- src/main/resources/templates/vets/vetList.html | 3 +-- .../samples/petclinic/vet/VetControllerTests.java | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/springframework/samples/petclinic/vet/VetController.java b/src/main/java/org/springframework/samples/petclinic/vet/VetController.java index 7ce8374..562bbfc 100644 --- a/src/main/java/org/springframework/samples/petclinic/vet/VetController.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/VetController.java @@ -48,7 +48,7 @@ class VetController { return "vets/vetList"; } - @GetMapping({ "/vets.json", "/vets.xml" }) + @GetMapping({ "/vets" }) public @ResponseBody Vets showResourcesVetList() { // Here we are returning an object of type 'Vets' rather than a collection of Vet // objects so it is simpler for JSon/Object mapping diff --git a/src/main/resources/templates/vets/vetList.html b/src/main/resources/templates/vets/vetList.html index 842411e..4c1c1c9 100644 --- a/src/main/resources/templates/vets/vetList.html +++ b/src/main/resources/templates/vets/vetList.html @@ -26,8 +26,7 @@ - - +
View as XMLView as JSONView as XML
diff --git a/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java b/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java index ce6adf8..bc3b6c0 100644 --- a/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java @@ -65,7 +65,7 @@ public class VetControllerTests { @Test public void testShowResourcesVetList() throws Exception { - ResultActions actions = mockMvc.perform(get("/vets.json").accept(MediaType.APPLICATION_JSON)) + ResultActions actions = mockMvc.perform(get("/vets").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); actions.andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath("$.vetList[0].id").value(1)); @@ -73,7 +73,7 @@ public class VetControllerTests { @Test public void testShowVetListXml() throws Exception { - mockMvc.perform(get("/vets.xml").accept(MediaType.APPLICATION_XML)) + mockMvc.perform(get("/vets").accept(MediaType.APPLICATION_XML)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_XML_VALUE)) .andExpect(content().node(hasXPath("/vets/vetList[id=1]/id"))); From eebca43df803aeb08754f43a86d6996630063500 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 4 Jun 2018 10:48:39 +0200 Subject: [PATCH 2/2] Polish "Fix content negotiation for /vets" Closes gh-326 --- .../samples/petclinic/vet/VetController.java | 2 +- src/main/resources/templates/vets/vetList.html | 7 ------- .../samples/petclinic/vet/VetControllerTests.java | 8 ++------ 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/springframework/samples/petclinic/vet/VetController.java b/src/main/java/org/springframework/samples/petclinic/vet/VetController.java index 562bbfc..1bc9e22 100644 --- a/src/main/java/org/springframework/samples/petclinic/vet/VetController.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/VetController.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/main/resources/templates/vets/vetList.html b/src/main/resources/templates/vets/vetList.html index 4c1c1c9..1961ad4 100644 --- a/src/main/resources/templates/vets/vetList.html +++ b/src/main/resources/templates/vets/vetList.html @@ -23,12 +23,5 @@ - - - - - -
View as XML
- diff --git a/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java b/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java index bc3b6c0..bd20ca7 100644 --- a/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java @@ -17,10 +17,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; -import org.springframework.samples.petclinic.vet.Specialty; -import org.springframework.samples.petclinic.vet.Vet; -import org.springframework.samples.petclinic.vet.VetController; -import org.springframework.samples.petclinic.vet.VetRepository; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; @@ -65,8 +61,8 @@ public class VetControllerTests { @Test public void testShowResourcesVetList() throws Exception { - ResultActions actions = mockMvc.perform(get("/vets").accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()); + ResultActions actions = mockMvc.perform(get("/vets") + .accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()); actions.andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath("$.vetList[0].id").value(1)); }