DATAREST-93 - Fixed test setup.

This commit is contained in:
Oliver Gierke
2013-07-24 14:08:51 +02:00
parent d2c2ec8262
commit 8ac0d2c222
4 changed files with 42 additions and 10 deletions

View File

@@ -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");

View File

@@ -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() {

View File

@@ -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()

View File

@@ -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));
}
}