DATAREST-1410 - Migrate remaining tests to AssertJ.

This commit is contained in:
Mark Paluch
2019-07-31 10:06:03 +02:00
parent 314e0bb6f4
commit 19c261d7d0
33 changed files with 164 additions and 254 deletions

View File

@@ -21,7 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.rest.core.domain.Person;
import org.springframework.data.rest.core.domain.PersonRepository;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Base class for integration tests loading {@link RepositoryTestsConfig} and populating the {@link PersonRepository}
@@ -29,7 +29,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
*
* @author Oliver Gierke
*/
@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = RepositoryTestsConfig.class)
public abstract class AbstractIntegrationTests {

View File

@@ -18,6 +18,7 @@ package org.springframework.data.rest.core.context;
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.Bean;
@@ -29,19 +30,9 @@ import org.springframework.data.rest.core.domain.EventHandlerInvokedException;
import org.springframework.data.rest.core.domain.Person;
import org.springframework.data.rest.core.domain.PersonBeforeSaveHandler;
import org.springframework.data.rest.core.domain.PersonRepository;
import org.springframework.data.rest.core.event.AfterCreateEvent;
import org.springframework.data.rest.core.event.AfterDeleteEvent;
import org.springframework.data.rest.core.event.AfterLinkDeleteEvent;
import org.springframework.data.rest.core.event.AfterLinkSaveEvent;
import org.springframework.data.rest.core.event.AfterSaveEvent;
import org.springframework.data.rest.core.event.AnnotatedEventHandlerInvoker;
import org.springframework.data.rest.core.event.BeforeCreateEvent;
import org.springframework.data.rest.core.event.BeforeDeleteEvent;
import org.springframework.data.rest.core.event.BeforeLinkDeleteEvent;
import org.springframework.data.rest.core.event.BeforeLinkSaveEvent;
import org.springframework.data.rest.core.event.BeforeSaveEvent;
import org.springframework.data.rest.core.event.*;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Tests around the {@link org.springframework.context.ApplicationEvent} handling abstractions.
@@ -49,7 +40,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Jon Brisbin
* @author Oliver Gierke
*/
@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(SpringRunner.class)
@ContextConfiguration
public class RepositoryEventIntegrationTests {

View File

@@ -33,7 +33,7 @@ import org.springframework.data.rest.core.domain.PersonNameValidator;
import org.springframework.data.rest.core.event.BeforeSaveEvent;
import org.springframework.data.rest.core.event.ValidatingRepositoryEventListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Tests to check the {@link org.springframework.validation.Validator} integration.
@@ -41,7 +41,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Jon Brisbin
* @author Oliver Gierke
*/
@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(SpringRunner.class)
@ContextConfiguration
public class ValidatorIntegrationTests {

View File

@@ -44,7 +44,7 @@ import org.springframework.data.rest.core.domain.Person;
import org.springframework.data.rest.core.domain.Profile;
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;
/**
* Integration tests for {@link RepositoryResourceMappings}.
@@ -52,7 +52,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Oliver Gierke
* @author Greg Turnquist
*/
@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = JpaRepositoryConfig.class)
public class RepositoryResourceMappingsIntegrationTests {

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.rest.core.support;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
@@ -23,14 +23,12 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
import org.springframework.data.mapping.context.PersistentEntities;
import org.springframework.data.rest.core.domain.Profile;
@@ -52,8 +50,6 @@ public class DefaultSelfLinkProviderUnitTests {
PersistentEntities entities;
List<EntityLookup<?>> lookups;
public @Rule ExpectedException exception = ExpectedException.none();
@Before
public void setUp() {
@@ -95,7 +91,7 @@ public class DefaultSelfLinkProviderUnitTests {
Profile profile = new Profile("Name", "Type");
Link link = provider.createSelfLinkFor(profile);
assertThat(link.getHref(), Matchers.endsWith(profile.getId().toString()));
assertThat(link.getHref()).endsWith(profile.getId().toString());
}
@Test // DATAREST-724
@@ -106,20 +102,18 @@ public class DefaultSelfLinkProviderUnitTests {
when(lookup.supports(Profile.class)).thenReturn(true);
when(lookup.getResourceIdentifier(any(Profile.class))).thenReturn("foo");
this.provider = new DefaultSelfLinkProvider(entities, entityLinks, Arrays.asList(lookup));
this.provider = new DefaultSelfLinkProvider(entities, entityLinks, Collections.singletonList(lookup));
Link link = provider.createSelfLinkFor(new Profile("Name", "Type"));
assertThat(link.getHref(), Matchers.endsWith("foo"));
assertThat(link.getHref()).endsWith("foo");
}
@Test // DATAREST-724
public void rejectsLinkCreationForUnknownEntity() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage(Object.class.getName());
exception.expectMessage("Couldn't find PersistentEntity for");
provider.createSelfLinkFor(new Object());
assertThatIllegalArgumentException().isThrownBy(() -> provider.createSelfLinkFor(new Object())) //
.withMessageContaining(Object.class.getName()) //
.withMessageContaining("Couldn't find PersistentEntity for");
}
}

View File

@@ -34,7 +34,7 @@ import org.springframework.hateoas.MediaTypes;
import org.springframework.http.HttpHeaders;
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.setup.MockMvcBuilders;
@@ -47,7 +47,7 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
* @author Oliver Gierke
* @soundtrack Miles Davis - Blue in green (Kind of blue)
*/
@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(SpringRunner.class)
@WebAppConfiguration
@ContextConfiguration
public class HalBrowserIntegrationTests {

View File

@@ -15,9 +15,7 @@
*/
package org.springframework.data.rest.webmvc.halbrowser;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.*;
import java.io.IOException;
import java.util.Collections;
@@ -26,6 +24,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import org.junit.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
@@ -61,7 +60,7 @@ public class HalBrowserUnitTests {
UriComponents components = UriComponentsBuilder.fromUriString(response.getHeader(HttpHeaders.LOCATION)).build();
assertThat(components.getPath(), startsWith("/context"));
assertThat(components.getPath()).startsWith("/context");
assertThat(components.getFragment()).isEqualTo("/context");
}
@@ -83,8 +82,7 @@ public class HalBrowserUnitTests {
String url = ((RedirectView) view).getUrl();
assertThat(url, startsWith("https://somehost:4711/prefix"));
assertThat(url, endsWith("/prefix"));
assertThat(url).startsWith("https://somehost:4711/prefix").endsWith("/prefix");
});
}
}

View File

@@ -34,7 +34,7 @@ import org.springframework.hateoas.MediaTypes;
import org.springframework.http.HttpHeaders;
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.setup.MockMvcBuilders;
@@ -47,7 +47,7 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
* @author Oliver Gierke
* @soundtrack Miles Davis - Blue in green (Kind of blue)
*/
@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(SpringRunner.class)
@WebAppConfiguration
@ContextConfiguration
public class HalExplorerIntegrationTests {

View File

@@ -15,9 +15,7 @@
*/
package org.springframework.data.rest.webmvc.halexplorer;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.*;
import java.io.IOException;
import java.util.Collections;
@@ -26,12 +24,12 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import org.junit.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.web.filter.ForwardedHeaderFilter;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.AbstractView;
import org.springframework.web.servlet.view.RedirectView;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
@@ -57,11 +55,11 @@ public class HalExplorerUnitTests {
assertThat(view).isInstanceOf(RedirectView.class);
((AbstractView) view).render(Collections.<String, Object> emptyMap(), request, response);
view.render(Collections.emptyMap(), request, response);
UriComponents components = UriComponentsBuilder.fromUriString(response.getHeader(HttpHeaders.LOCATION)).build();
assertThat(components.getPath(), startsWith("/context"));
assertThat(components.getPath()).startsWith("/context");
assertThat(components.getFragment()).isEqualTo("uri=/context");
}
@@ -83,8 +81,7 @@ public class HalExplorerUnitTests {
String url = ((RedirectView) view).getUrl();
assertThat(url, startsWith("https://somehost:4711/prefix"));
assertThat(url, endsWith("/prefix"));
assertThat(url).startsWith("https://somehost:4711/prefix").endsWith("/prefix");
});
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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()}.
*

View File

@@ -15,9 +15,7 @@
*/
package org.springframework.data.rest.webmvc;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.*;
import java.net.URI;
@@ -42,7 +40,7 @@ public class BaseUriUnitTests {
BaseUri uri = new BaseUri(URI.create("foo"));
assertThat(uri.getRepositoryLookupPath("/foo"), isEmptyString());
assertThat(uri.getRepositoryLookupPath("/foo")).isEmpty();
}
@Test // DATAREST-276
@@ -50,8 +48,8 @@ public class BaseUriUnitTests {
BaseUri uri = new BaseUri(URI.create("foo/"));
assertThat(uri.getRepositoryLookupPath("/foo"), isEmptyString());
assertThat(uri.getRepositoryLookupPath("/foo/"), isEmptyString());
assertThat(uri.getRepositoryLookupPath("/foo")).isEmpty();
assertThat(uri.getRepositoryLookupPath("/foo/")).isEmpty();
}
@Test // DATAREST-276
@@ -59,8 +57,8 @@ public class BaseUriUnitTests {
BaseUri uri = new BaseUri(URI.create("/foo"));
assertThat(uri.getRepositoryLookupPath("/foo"), isEmptyString());
assertThat(uri.getRepositoryLookupPath("/foo/"), isEmptyString());
assertThat(uri.getRepositoryLookupPath("/foo")).isEmpty();
assertThat(uri.getRepositoryLookupPath("/foo/")).isEmpty();
}
@Test // DATAREST-276
@@ -68,8 +66,8 @@ public class BaseUriUnitTests {
BaseUri uri = new BaseUri(URI.create("http://localhost:8080/foo/"));
assertThat(uri.getRepositoryLookupPath("/foo"), isEmptyString());
assertThat(uri.getRepositoryLookupPath("/foo/"), isEmptyString());
assertThat(uri.getRepositoryLookupPath("/foo")).isEmpty();
assertThat(uri.getRepositoryLookupPath("/foo/")).isEmpty();
assertThat(uri.getRepositoryLookupPath("/foo/people")).isEqualTo("/people");
assertThat(uri.getRepositoryLookupPath("/foo/people/")).isEqualTo("/people");
}

View File

@@ -15,9 +15,7 @@
*/
package org.springframework.data.rest.webmvc;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import java.util.Collections;
@@ -26,6 +24,7 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.junit.Test;
import org.springframework.data.rest.webmvc.BasePathAwareHandlerMapping.CustomAcceptHeaderHttpServletRequest;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
@@ -48,8 +47,8 @@ public class CustomAcceptHeaderHttpServletRequestUnitTests {
List<MediaType> mediaTypes = Arrays.asList(MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_ATOM_XML);
HttpServletRequest servletRequest = new CustomAcceptHeaderHttpServletRequest(request, mediaTypes);
assertThat(servletRequest.getHeader(HttpHeaders.ACCEPT),
is(StringUtils.collectionToCommaDelimitedString(mediaTypes)));
assertThat(servletRequest.getHeader(HttpHeaders.ACCEPT))
.isEqualTo(StringUtils.collectionToCommaDelimitedString(mediaTypes));
List<String> expected = Collections.list(servletRequest.getHeaders(HttpHeaders.ACCEPT));

View File

@@ -1,51 +0,0 @@
package org.springframework.data.rest.webmvc;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.springframework.http.HttpEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
/**
* @author Jon Brisbin
*/
class HttpEntityMatcher<T> extends BaseMatcher<HttpEntity<T>> {
private final HttpEntity<T> expected;
public HttpEntityMatcher(HttpEntity<T> expected) {
Assert.notNull(expected, "HttpEntity cannot be null");
this.expected = expected;
}
public static <T> HttpEntityMatcher<T> httpEntity(HttpEntity<T> httpEntity) {
return new HttpEntityMatcher<T>(httpEntity);
}
@Override
public boolean matches(Object item) {
if (!(item instanceof HttpEntity)) {
return false;
}
if (item instanceof ResponseEntity && expected instanceof ResponseEntity) {
ResponseEntity<?> left = (ResponseEntity<?>) expected;
ResponseEntity<?> right = (ResponseEntity<?>) item;
if (!left.getStatusCode().equals(right.getStatusCode())) {
return false;
}
}
HttpEntity<?> left = expected;
HttpEntity<?> right = (HttpEntity<?>) item;
return left.getBody().equals(right.getBody()) && left.getHeaders().equals(right.getHeaders());
}
@Override
public void describeTo(Description description) {
description.appendText(expected.toString());
}
}

View File

@@ -15,9 +15,7 @@
*/
package org.springframework.data.rest.webmvc;
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 static org.mockito.Mockito.*;
import java.util.Optional;
@@ -27,6 +25,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.repository.support.Repositories;
import org.springframework.data.rest.core.mapping.ResourceMappings;
import org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.NoOpStringValueResolver;
@@ -66,8 +65,8 @@ public class RepositoryCorsConfigurationAccessorUnitTests {
assertThat(configuration.getAllowCredentials()).isFalse();
assertThat(configuration.getAllowedHeaders()).contains("*");
assertThat(configuration.getAllowedOrigins()).contains("*");
assertThat(configuration.getAllowedMethods(),
hasItems("OPTIONS", "HEAD", "GET", "PATCH", "POST", "PUT", "DELETE", "TRACE"));
assertThat(configuration.getAllowedMethods()).contains("OPTIONS", "HEAD", "GET", "PATCH", "POST", "PUT", "DELETE",
"TRACE");
assertThat(configuration.getMaxAge()).isEqualTo(1800L);
}

View File

@@ -16,9 +16,7 @@
package org.springframework.data.rest.webmvc.json;
import static com.fasterxml.jackson.annotation.JsonProperty.Access.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import lombok.AllArgsConstructor;
@@ -38,6 +36,7 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Immutable;
@@ -210,9 +209,9 @@ public class DomainObjectReaderUnitTests {
SampleUser result = reader.readPut(node, sampleUser, mapper);
assertThat(result.name, is("another"));
assertThat(result.password, notNullValue());
assertThat(result.lastLogin, notNullValue());
assertThat(result.name).isEqualTo("another");
assertThat(result.password).isNotNull();
assertThat(result.lastLogin).isNotNull();
}
@Test // DATAREST-873
@@ -487,7 +486,7 @@ public class DomainObjectReaderUnitTests {
CollectionOfEnumWithMethods result = reader.merge((ObjectNode) node, sample, mapper);
assertThat(result.enums, contains(SampleEnum.SECOND, SampleEnum.FIRST));
assertThat(result.enums).containsExactly(SampleEnum.SECOND, SampleEnum.FIRST);
}
@Test // DATAREST-944

View File

@@ -15,9 +15,7 @@
*/
package org.springframework.data.rest.webmvc.json;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.util.Collection;
@@ -25,6 +23,7 @@ import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.rest.webmvc.json.JacksonSerializersUnitTests.Sample.SampleEnum;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -70,7 +69,7 @@ public class JacksonSerializersUnitTests {
Sample result = mapper.readValue("{ \"array\" : [ \"value\" ] }", Sample.class);
assertThat(result.array, hasItemInArray(SampleEnum.VALUE));
assertThat(result.array).contains(SampleEnum.VALUE);
}
@Test // DATAREST-929