diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AbstractControllerIntegrationTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AbstractControllerIntegrationTests.java index 21fcb4ad8..da93e4b9e 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AbstractControllerIntegrationTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AbstractControllerIntegrationTests.java @@ -24,7 +24,6 @@ import org.springframework.data.rest.core.invoke.RepositoryInvokerFactory; import org.springframework.data.rest.core.mapping.ResourceMappings; import org.springframework.data.rest.core.mapping.ResourceMetadata; import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration; -import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -39,8 +38,8 @@ import org.springframework.web.context.request.ServletWebRequest; * @author Oliver Gierke */ @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { RepositoryRestMvcConfiguration.class, JpaRepositoryConfig.class }) -public class AbstractControllerIntegrationTests { +@ContextConfiguration(classes = { RepositoryRestMvcConfiguration.class }) +public abstract class AbstractControllerIntegrationTests { public static final Path BASE = new Path("http://localhost"); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositorySearchControllerIntegrationTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositorySearchControllerIntegrationTests.java index d2784929f..a7b7f9b4b 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositorySearchControllerIntegrationTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositorySearchControllerIntegrationTests.java @@ -18,27 +18,40 @@ package org.springframework.data.rest.webmvc; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; +import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.rest.core.mapping.ResourceMetadata; import org.springframework.data.rest.webmvc.ResourceTester.HasSelfLink; import org.springframework.data.rest.webmvc.jpa.CreditCard; +import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig; import org.springframework.data.rest.webmvc.jpa.Order; import org.springframework.data.rest.webmvc.jpa.Person; +import org.springframework.data.rest.webmvc.jpa.PersonLoader; import org.springframework.hateoas.PagedResources; import org.springframework.hateoas.Resource; import org.springframework.hateoas.Resources; import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.transaction.annotation.Transactional; /** * Integration tests for the {@link RepositorySearchController}. * * @author Oliver Gierke */ +@ContextConfiguration(classes = JpaRepositoryConfig.class) +@Transactional public class RepositorySearchControllerIntegrationTests extends AbstractControllerIntegrationTests { + @Autowired PersonLoader loader; @Autowired RepositorySearchController controller; + @Before + public void setUp() { + loader.populateRepository(); + } + @Test public void rendersCorrectSearchLinksForPersons() { diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaWebTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaWebTests.java index d653d268f..bbca18dfa 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaWebTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaWebTests.java @@ -20,6 +20,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import java.util.Arrays; +import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.rest.core.mapping.ResourceMappings; @@ -34,12 +35,24 @@ import org.springframework.transaction.annotation.Transactional; * * @author Oliver Gierke */ -@ContextConfiguration(classes = JpaRepositoryConfig.class) @Transactional +@ContextConfiguration(classes = JpaRepositoryConfig.class) public class JpaWebTests extends AbstractWebIntegrationTests { + @Autowired PersonLoader loader; @Autowired ResourceMappings mappings; + /* + * (non-Javadoc) + * @see org.springframework.data.rest.webmvc.AbstractWebIntegrationTests#setUp() + */ + @Override + @Before + public void setUp() { + loader.populateRepository(); + super.setUp(); + } + /* * (non-Javadoc) * @see org.springframework.data.rest.webmvc.AbstractWebIntegrationTests#expectedRootLinkRels() diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/PersonLoader.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/PersonLoader.java index 941be0298..956ce6599 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/PersonLoader.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/PersonLoader.java @@ -2,7 +2,6 @@ package org.springframework.data.rest.webmvc.jpa; import java.util.Arrays; -import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -10,12 +9,21 @@ import org.springframework.stereotype.Component; * @author Jon Brisbin */ @Component -public class PersonLoader implements InitializingBean { +public class PersonLoader { - @Autowired PersonRepository people; + private final PersonRepository people; + + @Autowired + public PersonLoader(PersonRepository people) { + this.people = people; + } + + public void populateRepository() { + + if (people.count() != 0) { + return; + } - @Override - public void afterPropertiesSet() throws Exception { Person billyBob = people.save(new Person("Billy Bob", "Thornton")); Person john = new Person("John", "Doe"); @@ -27,5 +35,4 @@ public class PersonLoader implements InitializingBean { people.save(Arrays.asList(john, jane)); } - }