Skip to content
Snippets Groups Projects
Commit 80269539 authored by Dave Syer's avatar Dave Syer
Browse files

Configure caching properly to avoid error in vets

parent 0f840cd5
No related branches found
No related tags found
No related merge requests found
......@@ -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 {
}
......@@ -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);
}
......
......@@ -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
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());
}
}
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
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment