diff --git a/src/main/java/org/springframework/samples/petclinic/vet/Specialty.java b/src/main/java/org/springframework/samples/petclinic/vet/Specialty.java index 826e04afce906e10d9f95bb7f9e0f227cd2790a9..5691c24348938cde1dada6c859d2deac6ef11469 100644 --- a/src/main/java/org/springframework/samples/petclinic/vet/Specialty.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/Specialty.java @@ -15,6 +15,8 @@ */ package org.springframework.samples.petclinic.vet; +import java.io.Serializable; + import javax.persistence.Entity; import javax.persistence.Table; @@ -27,6 +29,6 @@ import org.springframework.samples.petclinic.model.NamedEntity; */ @Entity @Table(name = "specialties") -public class Specialty extends NamedEntity { +public class Specialty extends NamedEntity implements Serializable { } diff --git a/src/main/java/org/springframework/samples/petclinic/vet/Vet.java b/src/main/java/org/springframework/samples/petclinic/vet/Vet.java index 829423782baa3e4ddbe81accc779fcb11d003b6c..3cde3d1bffcf87fd12fabcbb2abb32140c1c363d 100644 --- a/src/main/java/org/springframework/samples/petclinic/vet/Vet.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/Vet.java @@ -15,6 +15,7 @@ */ package org.springframework.samples.petclinic.vet; +import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -43,11 +44,10 @@ import org.springframework.samples.petclinic.model.Person; */ @Entity @Table(name = "vets") -public class Vet extends Person { +public class Vet extends Person implements Serializable { @ManyToMany(fetch = FetchType.EAGER) - @JoinTable(name = "vet_specialties", joinColumns = @JoinColumn(name = "vet_id"), - inverseJoinColumns = @JoinColumn(name = "specialty_id")) + @JoinTable(name = "vet_specialties", joinColumns = @JoinColumn(name = "vet_id"), inverseJoinColumns = @JoinColumn(name = "specialty_id")) private Set<Specialty> specialties; protected Set<Specialty> getSpecialtiesInternal() { @@ -64,7 +64,8 @@ public class Vet extends Person { @XmlElement public List<Specialty> getSpecialties() { List<Specialty> sortedSpecs = new ArrayList<>(getSpecialtiesInternal()); - PropertyComparator.sort(sortedSpecs, new MutableSortDefinition("name", true, true)); + PropertyComparator.sort(sortedSpecs, + new MutableSortDefinition("name", true, true)); return Collections.unmodifiableList(sortedSpecs); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 3562d7d0320e9a73b1e98255f64c94a8d9f5095b..cd1aea2cdcb73930b31ffca382aaca8e4b5b4ea8 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -22,3 +22,4 @@ logging.level.org.springframework=INFO # Active Spring profiles spring.profiles.active=production +spring.cache.cache-names=vets \ No newline at end of file diff --git a/src/test/java/org/springframework/samples/petclinic/system/CrashControllerTests.java b/src/test/java/org/springframework/samples/petclinic/system/CrashControllerTests.java index 1617692542bd9bd0aa4bf465d9b0eb3f013bfcc6..3f108bfe9d4d42353b9f17a5af49328974f48e6d 100644 --- a/src/test/java/org/springframework/samples/petclinic/system/CrashControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/system/CrashControllerTests.java @@ -1,20 +1,19 @@ package org.springframework.samples.petclinic.system; -import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.samples.petclinic.PetClinicApplication; -import org.springframework.samples.petclinic.system.CrashController; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.forwardedUrl; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; /** * Test class for {@link CrashController} @@ -22,31 +21,18 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * @author Colin But */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = PetClinicApplication.class) -@WebAppConfiguration // Waiting https://github.com/spring-projects/spring-boot/issues/5574 @Ignore +@WebMvcTest(controllers = CrashController.class) public class CrashControllerTests { @Autowired - private CrashController crashController; - private MockMvc mockMvc; - @Before - public void setup() { - this.mockMvc = MockMvcBuilders - .standaloneSetup(crashController) - //.setHandlerExceptionResolvers(new SimpleMappingExceptionResolver()) - .build(); - } - @Test public void testTriggerException() throws Exception { - mockMvc.perform(get("/oups")) - .andExpect(view().name("exception")) - .andExpect(model().attributeExists("exception")) - .andExpect(forwardedUrl("exception")) - .andExpect(status().isOk()); + mockMvc.perform(get("/oups")).andExpect(view().name("exception")) + .andExpect(model().attributeExists("exception")) + .andExpect(forwardedUrl("exception")).andExpect(status().isOk()); } } diff --git a/src/test/java/org/springframework/samples/petclinic/system/ProductionConfigurationTests.java b/src/test/java/org/springframework/samples/petclinic/system/ProductionConfigurationTests.java new file mode 100644 index 0000000000000000000000000000000000000000..9636e36233ab8c339ecd69ead571a253670f51ca --- /dev/null +++ b/src/test/java/org/springframework/samples/petclinic/system/ProductionConfigurationTests.java @@ -0,0 +1,23 @@ +package org.springframework.samples.petclinic.system; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.samples.petclinic.vet.VetRepository; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ProductionConfigurationTests { + + @Autowired + private VetRepository vets; + + @Test + public void testFindAll() throws Exception { + vets.findAll(); + vets.findAll(); // served from cache + } +}