@@ -62,7 +62,7 @@ public class Customer {
|
||||
this.gender = null;
|
||||
}
|
||||
|
||||
static enum Gender {
|
||||
MALE, FEMALE;
|
||||
enum Gender {
|
||||
MALE, FEMALE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,14 +15,13 @@
|
||||
*/
|
||||
package example.springdata.rest.headers;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests to bootstrap the application.
|
||||
*
|
||||
@@ -37,9 +36,9 @@ public class ApplicationIntegrationTests {
|
||||
@Test
|
||||
public void initializesRepositoryWithSampleData() {
|
||||
|
||||
Iterable<Customer> result = repository.findAll();
|
||||
var result = repository.findAll();
|
||||
|
||||
assertThat(result, is(iterableWithSize(1)));
|
||||
assertThat(result.iterator().next().getLastModifiedDate(), is(notNullValue()));
|
||||
assertThat(result).hasSize(1);
|
||||
assertThat(result.iterator().next().getLastModifiedDate()).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class CrossOriginIntegrationTests {
|
||||
@Autowired WebApplicationContext context;
|
||||
@Autowired CustomerRepository customers;
|
||||
|
||||
MockMvc mvc;
|
||||
private MockMvc mvc;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
@@ -51,8 +51,8 @@ public class CrossOriginIntegrationTests {
|
||||
@Test
|
||||
public void executePreflightRequest() throws Exception {
|
||||
|
||||
String origin = "http://localhost:1234";
|
||||
URI uri = URI.create("/customers");
|
||||
var origin = "http://localhost:1234";
|
||||
var uri = URI.create("/customers");
|
||||
|
||||
mvc.perform(options(uri).header(ORIGIN, origin).header(ACCESS_CONTROL_REQUEST_METHOD, "POST")) //
|
||||
.andExpect(header().string(ACCESS_CONTROL_ALLOW_ORIGIN, is(origin))) //
|
||||
@@ -63,8 +63,8 @@ public class CrossOriginIntegrationTests {
|
||||
@Test
|
||||
public void executeCrossOriginRequest() throws Exception {
|
||||
|
||||
String origin = "http://localhost:1234";
|
||||
URI uri = URI.create("/customers");
|
||||
var origin = "http://localhost:1234";
|
||||
var uri = URI.create("/customers");
|
||||
|
||||
mvc.perform(get(uri).header(ORIGIN, origin)) //
|
||||
.andExpect(status().isOk()) //
|
||||
@@ -74,8 +74,8 @@ public class CrossOriginIntegrationTests {
|
||||
@Test
|
||||
public void rejectCrossOriginRequest() throws Exception {
|
||||
|
||||
String origin = "http://foo.bar";
|
||||
URI uri = URI.create("/customers");
|
||||
var origin = "http://foo.bar";
|
||||
var uri = URI.create("/customers");
|
||||
|
||||
mvc.perform(get(uri).header(ORIGIN, origin)) //
|
||||
.andExpect(status().isForbidden());
|
||||
|
||||
@@ -44,7 +44,7 @@ public class WebIntegrationTests {
|
||||
@Autowired WebApplicationContext context;
|
||||
@Autowired CustomerRepository customers;
|
||||
|
||||
MockMvc mvc;
|
||||
private MockMvc mvc;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
@@ -57,10 +57,10 @@ public class WebIntegrationTests {
|
||||
@Test
|
||||
public void executeConditionalGetRequests() throws Exception {
|
||||
|
||||
Customer customer = customers.findAll().iterator().next();
|
||||
URI uri = new UriTemplate("/customers/{id}").expand(customer.getId());
|
||||
var customer = customers.findAll().iterator().next();
|
||||
var uri = new UriTemplate("/customers/{id}").expand(customer.getId());
|
||||
|
||||
MockHttpServletResponse response = mvc.perform(get(uri)).//
|
||||
var response = mvc.perform(get(uri)).//
|
||||
andExpect(header().string(ETAG, is(notNullValue()))).//
|
||||
andExpect(header().string(LAST_MODIFIED, is(notNullValue()))).//
|
||||
andReturn().getResponse();
|
||||
|
||||
Reference in New Issue
Block a user