DATAREST-1410 - Migrate remaining tests to AssertJ.
This commit is contained in:
@@ -40,7 +40,7 @@ import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguratio
|
||||
import org.springframework.data.rest.webmvc.support.Projector;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
@@ -52,7 +52,7 @@ import org.springframework.web.context.request.WebRequest;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
public abstract class AbstractControllerIntegrationTests {
|
||||
|
||||
|
||||
@@ -28,16 +28,17 @@ import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.client.LinkDiscoverers;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.client.LinkDiscoverers;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
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.ResultMatcher;
|
||||
@@ -61,7 +62,7 @@ import com.jayway.jsonpath.JsonPath;
|
||||
* @author Greg Turnquist
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebAppConfiguration
|
||||
@ContextConfiguration(classes = { RepositoryRestMvcConfiguration.class, DelegatingWebMvcConfiguration.class })
|
||||
public abstract class AbstractWebIntegrationTests {
|
||||
|
||||
@@ -15,17 +15,15 @@
|
||||
*/
|
||||
package org.springframework.data.rest.tests;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.hamcrest.Matcher;
|
||||
import org.springframework.data.rest.core.Path;
|
||||
import org.springframework.hateoas.CollectionModel;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.PagedModel;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
import org.springframework.hateoas.CollectionModel;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.util.UriTemplate;
|
||||
|
||||
@@ -39,7 +37,7 @@ public class ResourceTester {
|
||||
private final RepresentationModel resource;
|
||||
|
||||
public static ResourceTester of(Object object) {
|
||||
assertThat(object, is(instanceOf(RepresentationModel.class)));
|
||||
assertThat(object).isInstanceOf(RepresentationModel.class);
|
||||
return new ResourceTester((RepresentationModel) object);
|
||||
}
|
||||
|
||||
@@ -69,7 +67,12 @@ public class ResourceTester {
|
||||
* @param href can be {@literal null}, if so, only the presence of a {@link Link} with the given rel is checked.
|
||||
*/
|
||||
public Link assertHasLink(String rel, String href) {
|
||||
return assertHasLinkMatching(rel, href == null ? null : is(href));
|
||||
return assertHasLinkMatching(rel, it -> {
|
||||
if (href == null) {
|
||||
return;
|
||||
}
|
||||
assertThat(it).isEqualTo(href);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,17 +82,22 @@ public class ResourceTester {
|
||||
* @param href can be {@literal null}, if so, only the presence of a {@link Link} with the given rel is checked.
|
||||
*/
|
||||
public Link assertHasLinkEndingWith(String rel, String hrefEnd) {
|
||||
return assertHasLinkMatching(rel, hrefEnd == null ? null : endsWith(hrefEnd));
|
||||
return assertHasLinkMatching(rel, it -> {
|
||||
if (hrefEnd == null) {
|
||||
return;
|
||||
}
|
||||
assertThat(it).endsWith(hrefEnd);
|
||||
});
|
||||
}
|
||||
|
||||
private final Link assertHasLinkMatching(String rel, Matcher<String> hrefMatcher) {
|
||||
private Link assertHasLinkMatching(String rel, Consumer<String> hrefMatcher) {
|
||||
|
||||
Link link = resource.getRequiredLink(rel);
|
||||
assertThat("Expected link with rel '" + rel + "' but didn't find it in " + resource.getLinks(), link,
|
||||
is(notNullValue()));
|
||||
assertThat(link).as("Expected link with rel '" + rel + "' but didn't find it in " + resource.getLinks())
|
||||
.isNotNull();
|
||||
|
||||
if (hrefMatcher != null) {
|
||||
assertThat(link.getHref(), is(hrefMatcher));
|
||||
assertThat(link.getHref()).satisfies(hrefMatcher);
|
||||
}
|
||||
|
||||
return link;
|
||||
@@ -98,25 +106,25 @@ public class ResourceTester {
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> PagedModel<T> assertIsPage() {
|
||||
|
||||
assertThat(resource, is(instanceOf(PagedModel.class)));
|
||||
assertThat(resource).isInstanceOf(PagedModel.class);
|
||||
return (PagedModel<T>) resource;
|
||||
}
|
||||
|
||||
public ResourceTester getContentResource() {
|
||||
|
||||
assertThat(resource, is(instanceOf(CollectionModel.class)));
|
||||
assertThat(resource).isInstanceOf(CollectionModel.class);
|
||||
Object next = ((CollectionModel<?>) resource).getContent().iterator().next();
|
||||
|
||||
assertThat(next, is(instanceOf(RepresentationModel.class)));
|
||||
assertThat(next).isInstanceOf(RepresentationModel.class);
|
||||
return new ResourceTester((RepresentationModel) next);
|
||||
}
|
||||
|
||||
public void withContentResource(ContentResourceHandler handler) {
|
||||
|
||||
assertThat(resource, is(instanceOf(CollectionModel.class)));
|
||||
assertThat(resource).isInstanceOf(CollectionModel.class);
|
||||
|
||||
for (Object element : ((CollectionModel<?>) resource).getContent()) {
|
||||
assertThat(element, is(instanceOf(RepresentationModel.class)));
|
||||
assertThat(element).isInstanceOf(RepresentationModel.class);
|
||||
handler.doWith(of(element));
|
||||
}
|
||||
}
|
||||
@@ -144,8 +152,8 @@ public class ResourceTester {
|
||||
String href = content.assertHasLink("self", null).getHref();
|
||||
|
||||
UriTemplate uriTemplate = new UriTemplate(template.toString());
|
||||
assertThat(String.format("Expected %s to match %s!", href, uriTemplate.toString()), uriTemplate.matches(href),
|
||||
is(true));
|
||||
assertThat(uriTemplate.matches(href)).as(String.format("Expected %s to match %s!", href, uriTemplate.toString()))
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
package org.springframework.data.rest.webmvc;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.data.rest.tests.TestMvcClient.*;
|
||||
import static org.springframework.http.HttpMethod.*;
|
||||
@@ -27,9 +23,9 @@ import static org.springframework.http.HttpMethod.*;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -114,7 +110,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
||||
ResponseEntity<?> entity = controller.putItemResource(information, persistentEntityResource, 1L, assembler,
|
||||
ETag.NO_ETAG, MediaType.APPLICATION_JSON_VALUE);
|
||||
|
||||
assertThat(entity.getHeaders().getLocation().toString(), not(Matchers.endsWith("{?projection}")));
|
||||
assertThat(entity.getHeaders().getLocation().toString()).doesNotEndWith("{?projection}");
|
||||
}
|
||||
|
||||
@Test // DATAREST-330
|
||||
@@ -174,10 +170,8 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
||||
List<String> value = entity.getHeaders().get("Accept-Patch");
|
||||
|
||||
assertThat(value).hasSize(3);
|
||||
assertThat(value, hasItems(//
|
||||
RestMediaTypes.JSON_PATCH_JSON.toString(), //
|
||||
RestMediaTypes.MERGE_PATCH_JSON.toString(), //
|
||||
MediaType.APPLICATION_JSON_VALUE));
|
||||
assertThat(value).contains(RestMediaTypes.JSON_PATCH_JSON.toString(), RestMediaTypes.MERGE_PATCH_JSON.toString(),
|
||||
MediaType.APPLICATION_JSON_VALUE);
|
||||
}
|
||||
|
||||
@Test // DATAREST-34
|
||||
@@ -190,7 +184,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
||||
.build(new Order(new Person()), entities.getRequiredPersistentEntity(Order.class)).build();
|
||||
|
||||
assertThat(controller.putItemResource(request, persistentEntityResource, order.getId(), assembler, ETag.NO_ETAG,
|
||||
MediaType.APPLICATION_JSON_VALUE).hasBody(), is(true));
|
||||
MediaType.APPLICATION_JSON_VALUE).hasBody()).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATAREST-34
|
||||
@@ -201,7 +195,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
||||
.build(new Order(new Person()), entities.getRequiredPersistentEntity(Order.class)).forCreation();
|
||||
|
||||
assertThat(controller.putItemResource(request, persistentEntityResource, 1L, assembler, ETag.NO_ETAG,
|
||||
MediaType.APPLICATION_JSON_VALUE).hasBody(), is(true));
|
||||
MediaType.APPLICATION_JSON_VALUE).hasBody()).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATAREST-34
|
||||
@@ -213,7 +207,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
||||
|
||||
assertThat(controller
|
||||
.postCollectionResource(request, persistentEntityResource, assembler, MediaType.APPLICATION_JSON_VALUE)
|
||||
.hasBody(), is(true));
|
||||
.hasBody()).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATAREST-34
|
||||
@@ -223,10 +217,9 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
||||
PersistentEntityResource persistentEntityResource = PersistentEntityResource
|
||||
.build(new Order(new Person()), entities.getRequiredPersistentEntity(Order.class)).build();
|
||||
|
||||
assertThat(controller.postCollectionResource(request, persistentEntityResource, assembler, null).hasBody(),
|
||||
is(false));
|
||||
assertThat(controller.postCollectionResource(request, persistentEntityResource, assembler, "").hasBody(),
|
||||
is(false));
|
||||
assertThat(controller.postCollectionResource(request, persistentEntityResource, assembler, null).hasBody())
|
||||
.isFalse();
|
||||
assertThat(controller.postCollectionResource(request, persistentEntityResource, assembler, "").hasBody()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAREST-581
|
||||
@@ -243,8 +236,8 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
||||
|
||||
Mockito.when(assembler.toFullResource(Mockito.any(Object.class))).thenReturn(resource);
|
||||
|
||||
ResponseEntity<EntityModel<?>> entity = controller.getItemResource(getResourceInformation(Address.class), address.id,
|
||||
assembler, new HttpHeaders());
|
||||
ResponseEntity<EntityModel<?>> entity = controller.getItemResource(getResourceInformation(Address.class),
|
||||
address.id, assembler, new HttpHeaders());
|
||||
|
||||
assertThat(entity.getHeaders().getETag()).isNotNull();
|
||||
}
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.rest.tests.AbstractControllerIntegrationTests;
|
||||
import org.springframework.data.rest.webmvc.jpa.Book;
|
||||
@@ -58,8 +58,8 @@ public class RepositoryPropertyReferenceControllerIntegrationTests extends Abstr
|
||||
|
||||
Book book = books.findAll().iterator().next();
|
||||
|
||||
assertThat(controller.followPropertyReference(information, book.id, "creators", assembler).getStatusCode(),
|
||||
is(HttpStatus.OK));
|
||||
assertThat(controller.followPropertyReference(information, book.id, "creators", assembler).getStatusCode())
|
||||
.isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test(expected = ResourceNotFoundException.class)
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.data.rest.tests.AbstractControllerIntegrationTests;
|
||||
import org.springframework.data.rest.webmvc.jpa.Address;
|
||||
import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
@@ -34,7 +34,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
||||
@Transactional
|
||||
public class RootResourceInformationIntegrationTests extends AbstractControllerIntegrationTests {
|
||||
|
||||
@@ -28,6 +28,7 @@ import javax.validation.constraints.NotNull;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -38,14 +39,14 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.rest.webmvc.PersistentEntityResource;
|
||||
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
@@ -60,7 +61,7 @@ import com.jayway.jsonpath.JsonPath;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
public class DataRest262Tests {
|
||||
|
||||
|
||||
@@ -22,18 +22,19 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.rest.tests.TestMvcClient;
|
||||
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer;
|
||||
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
|
||||
import org.springframework.hateoas.client.JsonPathLinkDiscoverer;
|
||||
import org.springframework.hateoas.client.LinkDiscoverer;
|
||||
import org.springframework.hateoas.client.LinkDiscoverers;
|
||||
import org.springframework.hateoas.client.JsonPathLinkDiscoverer;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
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.ResultActions;
|
||||
@@ -46,7 +47,7 @@ import org.springframework.web.context.WebApplicationContext;
|
||||
* @author Greg Turnquist
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebAppConfiguration
|
||||
@ContextConfiguration(
|
||||
classes = { JpaRepositoryConfig.class, RepositoryRestMvcConfiguration.class, DataRest363Tests.Config.class })
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.springframework.hateoas.IanaLinkRelations;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
@@ -52,7 +52,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebAppConfiguration
|
||||
@ContextConfiguration(classes = JpaDefaultPageableWebTests.Config.class)
|
||||
public class JpaDefaultPageableWebTests extends AbstractWebIntegrationTests {
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.springframework.data.rest.webmvc.jpa.Person;
|
||||
import org.springframework.data.rest.webmvc.jpa.PersonRepository;
|
||||
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -46,7 +46,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = { JpaRepositoryConfig.class, RepositoryRestMvcConfiguration.class })
|
||||
@Transactional
|
||||
public class Jackson2DatatypeHelperIntegrationTests {
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc.json;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
@@ -27,6 +25,7 @@ import java.util.Collections;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -40,18 +39,18 @@ import org.springframework.data.repository.support.Repositories;
|
||||
import org.springframework.data.rest.webmvc.PersistentEntityResource;
|
||||
import org.springframework.data.rest.webmvc.jpa.*;
|
||||
import org.springframework.data.rest.webmvc.util.TestUtils;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.client.LinkDiscoverer;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.PagedModel;
|
||||
import org.springframework.hateoas.PagedModel.PageMetadata;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.hateoas.client.LinkDiscoverer;
|
||||
import org.springframework.hateoas.mediatype.hal.HalLinkDiscoverer;
|
||||
import org.springframework.hateoas.server.core.EmbeddedWrapper;
|
||||
import org.springframework.hateoas.server.core.EmbeddedWrappers;
|
||||
import org.springframework.hateoas.mediatype.hal.HalLinkDiscoverer;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletWebRequest;
|
||||
@@ -68,7 +67,7 @@ import com.jayway.jsonpath.JsonPath;
|
||||
* @author Oliver Gierke
|
||||
* @author Alex Leigh
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = { JpaRepositoryConfig.class, PersistentEntitySerializationTests.TestConfig.class })
|
||||
@Transactional
|
||||
public class PersistentEntitySerializationTests {
|
||||
@@ -128,8 +127,8 @@ public class PersistentEntitySerializationTests {
|
||||
+ " \"created\" : \"2014-01-31T21:07:45.574+0000\"\n" + "}\n";
|
||||
|
||||
Person p = mapper.readValue(bilbo, Person.class);
|
||||
assertThat(p.getFirstName(), equalTo("Bilbo"));
|
||||
assertThat(p.getLastName(), equalTo("Baggins"));
|
||||
assertThat(p.getFirstName()).isEqualTo("Bilbo");
|
||||
assertThat(p.getLastName()).isEqualTo("Baggins");
|
||||
}
|
||||
|
||||
@Test // DATAREST-238
|
||||
|
||||
@@ -15,12 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc.support;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
@@ -53,7 +51,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
||||
|
||||
Link link = entityLinks.linkToItemResource(Person.class, 1);
|
||||
|
||||
assertThat(link.getHref(), endsWith("/people/1{?projection}"));
|
||||
assertThat(link.getHref()).endsWith("/people/1{?projection}");
|
||||
assertThat(link.getRel()).isEqualTo(LinkRelation.of("person"));
|
||||
}
|
||||
|
||||
@@ -80,7 +78,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
||||
public void usesCustomGeneratedBackendId() {
|
||||
|
||||
Link link = entityLinks.linkToItemResource(Book.class, 7L);
|
||||
assertThat(link.expand().getHref(), endsWith("/7-7-7-7-7-7-7"));
|
||||
assertThat(link.expand().getHref()).endsWith("/7-7-7-7-7-7-7");
|
||||
}
|
||||
|
||||
@Test // DATAREST-317
|
||||
@@ -126,7 +124,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
||||
assertThat(link.getVariableNames()).doesNotContain("page", "size");
|
||||
|
||||
UriComponents components = UriComponentsBuilder.fromUriString(link.getHref()).build();
|
||||
assertThat(components.getQueryParams(), allOf(hasKey("page"), hasKey("size")));
|
||||
assertThat(components.getQueryParams()).containsKey("page").containsKey("size");
|
||||
}
|
||||
|
||||
@Test // DATAREST-467
|
||||
@@ -149,7 +147,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
||||
assertThat(link.getVariableNames()).doesNotContain("sort");
|
||||
|
||||
UriComponents components = UriComponentsBuilder.fromUriString(link.getHref()).build();
|
||||
assertThat(components.getQueryParams(), hasKey("sort"));
|
||||
assertThat(components.getQueryParams()).containsKey("sort");
|
||||
}
|
||||
|
||||
@Test // DATAREST-668, DATAREST-519, DATAREST-467
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.data.rest.webmvc.config;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
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;
|
||||
@@ -29,7 +29,7 @@ import org.springframework.web.context.WebApplicationContext;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebAppConfiguration
|
||||
public abstract class AbstractRepositoryRestMvcConfigurationIntegrationTests {
|
||||
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc.json;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -25,6 +23,7 @@ import java.util.HashMap;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -42,13 +41,13 @@ import org.springframework.data.rest.tests.mongodb.User.Nested;
|
||||
import org.springframework.data.rest.tests.mongodb.UserRepository;
|
||||
import org.springframework.data.rest.webmvc.PersistentEntityResource;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.client.LinkDiscoverer;
|
||||
import org.springframework.hateoas.PagedModel;
|
||||
import org.springframework.hateoas.PagedModel.PageMetadata;
|
||||
import org.springframework.hateoas.client.LinkDiscoverer;
|
||||
import org.springframework.hateoas.mediatype.hal.HalLinkDiscoverer;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletWebRequest;
|
||||
|
||||
@@ -62,7 +61,7 @@ import com.jayway.jsonpath.JsonPath;
|
||||
* @author Greg Turnquist
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = { MongoDbRepositoryConfig.class, RepositoryTestsConfig.class,
|
||||
PersistentEntitySerializationTests.TestConfig.class })
|
||||
public class PersistentEntitySerializationTests {
|
||||
@@ -133,6 +132,6 @@ public class PersistentEntitySerializationTests {
|
||||
.build(dave, repositories.getPersistentEntity(User.class)).build();
|
||||
|
||||
assertThat(JsonPath.parse(mapper.writeValueAsString(resource)).read("$.colleaguesMap.carter._links.user.href",
|
||||
String.class), is(notNullValue()));
|
||||
String.class)).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ import org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaCon
|
||||
import org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaConverterUnitTests.TestConfiguration;
|
||||
import org.springframework.data.rest.webmvc.mapping.Associations;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -59,7 +59,7 @@ import com.jayway.jsonpath.PathNotFoundException;
|
||||
* @author Oliver Gierke
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = { MongoDbRepositoryConfig.class, TestConfiguration.class })
|
||||
public class PersistentEntityToJsonSchemaConverterUnitTests {
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
@@ -48,7 +48,7 @@ import org.springframework.web.context.WebApplicationContext;
|
||||
* @author Greg Turnquist
|
||||
* @author Rob Winch
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = { SecurityIntegrationTests.Config.class, SecurityConfiguration.class,
|
||||
RepositoryRestMvcConfiguration.class })
|
||||
public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
||||
@@ -101,10 +101,8 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
||||
// Getting the collection is not tested here. This is to get the URI that will later be tested for DELETE
|
||||
final String people = client.discoverUnique("people").expand().getHref();
|
||||
|
||||
MockHttpServletResponse response = mvc
|
||||
.perform(get(people).//
|
||||
with(user("user").roles("USER")))
|
||||
.//
|
||||
MockHttpServletResponse response = mvc.perform(get(people).//
|
||||
with(user("user").roles("USER"))).//
|
||||
andReturn().getResponse();
|
||||
String href = assertHasJsonPathValue("$._embedded.people[0]._links.self.href", response);
|
||||
|
||||
@@ -117,10 +115,8 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
||||
@Test // DATAREST-327
|
||||
public void deletePersonAccessDeniedForUsers() throws Exception {
|
||||
|
||||
MockHttpServletResponse response = mvc
|
||||
.perform(get(client.discoverUnique("people").expand().getHref()).//
|
||||
with(user("user").roles("USER")))
|
||||
.//
|
||||
MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("people").expand().getHref()).//
|
||||
with(user("user").roles("USER"))).//
|
||||
andReturn().getResponse();
|
||||
String href = assertHasJsonPathValue("$._embedded.people[0]._links.self.href", response);
|
||||
|
||||
@@ -134,10 +130,8 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
||||
@Test // DATAREST-327
|
||||
public void deletePersonAccessGrantedForAdmins() throws Exception {
|
||||
|
||||
MockHttpServletResponse response = mvc
|
||||
.perform(get(client.discoverUnique("people").expand().getHref()).//
|
||||
with(user("user").roles("USER", "ADMIN")))
|
||||
.//
|
||||
MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("people").expand().getHref()).//
|
||||
with(user("user").roles("USER", "ADMIN"))).//
|
||||
andReturn().getResponse();
|
||||
String href = assertHasJsonPathValue("$._embedded.people[0]._links.self.href", response);
|
||||
|
||||
@@ -175,10 +169,8 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
||||
public void deleteOrderAccessDeniedForNoCredentials() throws Exception {
|
||||
|
||||
// Getting the collection is not tested here. This is to get the URI that will later be tested for DELETE
|
||||
MockHttpServletResponse response = mvc
|
||||
.perform(get(client.discoverUnique("orders").expand().getHref()).//
|
||||
with(user("user").roles("USER")))
|
||||
.//
|
||||
MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("orders").expand().getHref()).//
|
||||
with(user("user").roles("USER"))).//
|
||||
andReturn().getResponse();
|
||||
String href = assertHasJsonPathValue("$._embedded.orders[0]._links.self.href", response);
|
||||
|
||||
@@ -191,10 +183,8 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
||||
@Test // DATAREST-327
|
||||
public void deleteOrderAccessDeniedForUsers() throws Exception {
|
||||
|
||||
MockHttpServletResponse response = mvc
|
||||
.perform(get(client.discoverUnique("orders").expand().getHref()).//
|
||||
with(user("user").roles("USER")))
|
||||
.//
|
||||
MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("orders").expand().getHref()).//
|
||||
with(user("user").roles("USER"))).//
|
||||
andReturn().getResponse();
|
||||
String href = assertHasJsonPathValue("$._embedded.orders[0]._links.self.href", response);
|
||||
|
||||
@@ -205,10 +195,8 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
||||
@Test // DATAREST-327
|
||||
public void deleteOrderAccessGrantedForAdmins() throws Exception {
|
||||
|
||||
MockHttpServletResponse response = mvc
|
||||
.perform(get(client.discoverUnique("orders").expand().getHref()).//
|
||||
with(user("user").roles("USER")))
|
||||
.//
|
||||
MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("orders").expand().getHref()).//
|
||||
with(user("user").roles("USER"))).//
|
||||
andReturn().getResponse();
|
||||
String href = assertHasJsonPathValue("$._embedded.orders[0]._links.self.href", response);
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.data.rest.tests.AbstractWebIntegrationTests;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
@@ -37,7 +37,7 @@ import com.jayway.jsonpath.JsonPath;
|
||||
* @author Oliver Gierke
|
||||
* @author Craig Andrews
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = ShopConfiguration.class)
|
||||
public class ShopIntegrationTests extends AbstractWebIntegrationTests {
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.springframework.core.io.Resource;
|
||||
import org.springframework.data.solr.core.SolrTemplate;
|
||||
import org.springframework.data.solr.server.SolrClientFactory;
|
||||
import org.springframework.data.solr.server.support.EmbeddedSolrServerFactory;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.xml.sax.SAXException;
|
||||
@@ -106,9 +106,8 @@ public class SolrInfrastructureConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link SpringJUnit4ClassRunner} executes {@link ClassRule}s before the actual shutdown of the
|
||||
* {@link ApplicationContext}. This causes the {@link TemporaryFolder} to vanish before Solr can gracefully shutdown.
|
||||
* <br />
|
||||
* {@link SpringRunner} executes {@link ClassRule}s before the actual shutdown of the {@link ApplicationContext}. This
|
||||
* causes the {@link TemporaryFolder} to vanish before Solr can gracefully shutdown. <br />
|
||||
* To prevent error messages popping up we register a {@link CloseHook} re adding the index directory and removing it
|
||||
* after {@link SolrCore#close()}.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user