Fix lines over 120 characters
https://github.com/spring-projects/spring-framework/wiki/Spring-Framework-Code-Style#line-wrapping
This commit is contained in:
@@ -81,21 +81,24 @@ public class ContentDispositionTests {
|
||||
@Test
|
||||
public void parseDates() {
|
||||
ContentDisposition disposition = ContentDisposition
|
||||
.parse("attachment; creation-date=\"Mon, 12 Feb 2007 10:15:30 -0500\"; modification-date=\"Tue, 13 Feb 2007 10:15:30 -0500\"; read-date=\"Wed, 14 Feb 2007 10:15:30 -0500\"");
|
||||
.parse("attachment; creation-date=\"Mon, 12 Feb 2007 10:15:30 -0500\"; " +
|
||||
"modification-date=\"Tue, 13 Feb 2007 10:15:30 -0500\"; " +
|
||||
"read-date=\"Wed, 14 Feb 2007 10:15:30 -0500\"");
|
||||
DateTimeFormatter formatter = DateTimeFormatter.RFC_1123_DATE_TIME;
|
||||
assertEquals(ContentDisposition.builder("attachment")
|
||||
.creationDate(ZonedDateTime.parse("Mon, 12 Feb 2007 10:15:30 -0500", DateTimeFormatter.RFC_1123_DATE_TIME))
|
||||
.modificationDate(ZonedDateTime.parse("Tue, 13 Feb 2007 10:15:30 -0500", DateTimeFormatter.RFC_1123_DATE_TIME))
|
||||
.readDate(ZonedDateTime.parse("Wed, 14 Feb 2007 10:15:30 -0500", DateTimeFormatter.RFC_1123_DATE_TIME))
|
||||
.build(), disposition);
|
||||
.creationDate(ZonedDateTime.parse("Mon, 12 Feb 2007 10:15:30 -0500", formatter))
|
||||
.modificationDate(ZonedDateTime.parse("Tue, 13 Feb 2007 10:15:30 -0500", formatter))
|
||||
.readDate(ZonedDateTime.parse("Wed, 14 Feb 2007 10:15:30 -0500", formatter)).build(), disposition);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseInvalidDates() {
|
||||
ContentDisposition disposition = ContentDisposition
|
||||
.parse("attachment; creation-date=\"-1\"; modification-date=\"-1\"; read-date=\"Wed, 14 Feb 2007 10:15:30 -0500\"");
|
||||
.parse("attachment; creation-date=\"-1\"; modification-date=\"-1\"; " +
|
||||
"read-date=\"Wed, 14 Feb 2007 10:15:30 -0500\"");
|
||||
DateTimeFormatter formatter = DateTimeFormatter.RFC_1123_DATE_TIME;
|
||||
assertEquals(ContentDisposition.builder("attachment")
|
||||
.readDate(ZonedDateTime.parse("Wed, 14 Feb 2007 10:15:30 -0500", DateTimeFormatter.RFC_1123_DATE_TIME))
|
||||
.build(), disposition);
|
||||
.readDate(ZonedDateTime.parse("Wed, 14 Feb 2007 10:15:30 -0500", formatter)).build(), disposition);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -240,7 +240,8 @@ public class ResponseEntityTests {
|
||||
assertTrue(responseEntity.getHeaders().containsKey(HttpHeaders.CACHE_CONTROL));
|
||||
assertEquals(entity, responseEntity.getBody());
|
||||
String cacheControlHeader = responseEntity.getHeaders().getCacheControl();
|
||||
assertThat(cacheControlHeader, Matchers.equalTo("max-age=3600, must-revalidate, private, proxy-revalidate, s-maxage=1800"));
|
||||
assertThat(cacheControlHeader,
|
||||
Matchers.equalTo("max-age=3600, must-revalidate, private, proxy-revalidate, s-maxage=1800"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -102,7 +102,10 @@ public class Jackson2JsonEncoderTests extends AbstractDataBufferAllocatingTestCa
|
||||
Flux<DataBuffer> output = this.encoder.encode(source, this.bufferFactory, type, null, emptyMap());
|
||||
|
||||
StepVerifier.create(output)
|
||||
.consumeNextWith(stringConsumer("[{\"foo\":\"foo\",\"bar\":\"bar\"},{\"foo\":\"foofoo\",\"bar\":\"barbar\"},{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}]"))
|
||||
.consumeNextWith(stringConsumer("[" +
|
||||
"{\"foo\":\"foo\",\"bar\":\"bar\"}," +
|
||||
"{\"foo\":\"foofoo\",\"bar\":\"barbar\"}," +
|
||||
"{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}]"))
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,8 @@ public class FormHttpMessageConverterTests {
|
||||
public void readForm() throws Exception {
|
||||
String body = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3";
|
||||
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.ISO_8859_1));
|
||||
inputMessage.getHeaders().setContentType(new MediaType("application", "x-www-form-urlencoded", StandardCharsets.ISO_8859_1));
|
||||
inputMessage.getHeaders().setContentType(
|
||||
new MediaType("application", "x-www-form-urlencoded", StandardCharsets.ISO_8859_1));
|
||||
MultiValueMap<String, String> result = this.converter.read(null, inputMessage);
|
||||
|
||||
assertEquals("Invalid result", 3, result.size());
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.http.converter.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
@@ -156,7 +157,8 @@ public class GsonHttpMessageConverterTests {
|
||||
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8));
|
||||
inputMessage.getHeaders().setContentType(new MediaType("application", "json"));
|
||||
|
||||
List<MyBean> results = (List<MyBean>) converter.read(beansList.getGenericType(), MyBeanListHolder.class, inputMessage);
|
||||
Type genericType = beansList.getGenericType();
|
||||
List<MyBean> results = (List<MyBean>) converter.read(genericType, MyBeanListHolder.class, inputMessage);
|
||||
assertEquals(1, results.size());
|
||||
MyBean result = results.get(0);
|
||||
assertEquals("Foo", result.getString());
|
||||
|
||||
@@ -73,8 +73,15 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.FatalBeanException;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Test class for {@link Jackson2ObjectMapperBuilder}.
|
||||
@@ -225,16 +232,22 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void modulesToInstallByClass() {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modulesToInstall(CustomIntegerModule.class).build();
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.modulesToInstall(CustomIntegerModule.class)
|
||||
.build();
|
||||
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
|
||||
assertSame(CustomIntegerSerializer.class, serializers.findSerializer(null, SimpleType.construct(Integer.class), null).getClass());
|
||||
assertSame(CustomIntegerSerializer.class,
|
||||
serializers.findSerializer(null, SimpleType.construct(Integer.class), null).getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void modulesToInstallByInstance() {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modulesToInstall(new CustomIntegerModule()).build();
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.modulesToInstall(new CustomIntegerModule())
|
||||
.build();
|
||||
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
|
||||
assertSame(CustomIntegerSerializer.class, serializers.findSerializer(null, SimpleType.construct(Integer.class), null).getClass());
|
||||
assertSame(CustomIntegerSerializer.class,
|
||||
serializers.findSerializer(null, SimpleType.construct(Integer.class), null).getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -257,9 +270,12 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test // SPR-12634
|
||||
public void customizeWellKnownModulesWithModule() throws JsonProcessingException, UnsupportedEncodingException {
|
||||
public void customizeWellKnownModulesWithModule()
|
||||
throws JsonProcessingException, UnsupportedEncodingException {
|
||||
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.modulesToInstall(new CustomIntegerModule()).build();
|
||||
.modulesToInstall(new CustomIntegerModule())
|
||||
.build();
|
||||
DateTime dateTime = new DateTime(1322903730000L, DateTimeZone.UTC);
|
||||
assertEquals("1322903730000", new String(objectMapper.writeValueAsBytes(dateTime), "UTF-8"));
|
||||
assertThat(new String(objectMapper.writeValueAsBytes(new Integer(4)), "UTF-8"), containsString("customid"));
|
||||
@@ -267,15 +283,21 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
|
||||
@Test // SPR-12634
|
||||
@SuppressWarnings("unchecked")
|
||||
public void customizeWellKnownModulesWithModuleClass() throws JsonProcessingException, UnsupportedEncodingException {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modulesToInstall(CustomIntegerModule.class).build();
|
||||
public void customizeWellKnownModulesWithModuleClass()
|
||||
throws JsonProcessingException, UnsupportedEncodingException {
|
||||
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.modulesToInstall(CustomIntegerModule.class)
|
||||
.build();
|
||||
DateTime dateTime = new DateTime(1322903730000L, DateTimeZone.UTC);
|
||||
assertEquals("1322903730000", new String(objectMapper.writeValueAsBytes(dateTime), "UTF-8"));
|
||||
assertThat(new String(objectMapper.writeValueAsBytes(new Integer(4)), "UTF-8"), containsString("customid"));
|
||||
}
|
||||
|
||||
@Test // SPR-12634
|
||||
public void customizeWellKnownModulesWithSerializer() throws JsonProcessingException, UnsupportedEncodingException {
|
||||
public void customizeWellKnownModulesWithSerializer()
|
||||
throws JsonProcessingException, UnsupportedEncodingException {
|
||||
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.serializerByType(Integer.class, new CustomIntegerSerializer()).build();
|
||||
DateTime dateTime = new DateTime(1322903730000L, DateTimeZone.UTC);
|
||||
@@ -305,7 +327,8 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
JsonSerializer<Number> serializer = new NumberSerializer(Integer.class);
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.modules(new ArrayList<>()) // Disable well-known modules detection
|
||||
.serializerByType(Boolean.class, serializer).build();
|
||||
.serializerByType(Boolean.class, serializer)
|
||||
.build();
|
||||
assertTrue(getSerializerFactoryConfig(objectMapper).hasSerializers());
|
||||
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
|
||||
assertSame(serializer, serializers.findSerializer(null, SimpleType.construct(Boolean.class), null));
|
||||
@@ -316,7 +339,8 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
JsonDeserializer<Date> deserializer = new DateDeserializers.DateDeserializer();
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.modules(new ArrayList<>()) // Disable well-known modules detection
|
||||
.deserializerByType(Date.class, deserializer).build();
|
||||
.deserializerByType(Date.class, deserializer)
|
||||
.build();
|
||||
assertTrue(getDeserializerFactoryConfig(objectMapper).hasDeserializers());
|
||||
Deserializers deserializers = getDeserializerFactoryConfig(objectMapper).deserializers().iterator().next();
|
||||
assertSame(deserializer, deserializers.findBeanDeserializer(SimpleType.construct(Date.class), null, null));
|
||||
@@ -327,8 +351,9 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
Class<?> target = String.class;
|
||||
Class<?> mixInSource = Object.class;
|
||||
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modules()
|
||||
.mixIn(target, mixInSource).build();
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.modules().mixIn(target, mixInSource)
|
||||
.build();
|
||||
|
||||
assertEquals(1, objectMapper.mixInCount());
|
||||
assertSame(mixInSource, objectMapper.findMixInClassFor(target));
|
||||
@@ -341,8 +366,9 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
Map<Class<?>, Class<?>> mixIns = new HashMap<>();
|
||||
mixIns.put(target, mixInSource);
|
||||
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modules()
|
||||
.mixIns(mixIns).build();
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.modules().mixIns(mixIns)
|
||||
.build();
|
||||
|
||||
assertEquals(1, objectMapper.mixInCount());
|
||||
assertSame(mixInSource, objectMapper.findMixInClassFor(target));
|
||||
@@ -357,8 +383,10 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
assertThat(output, containsString("value1"));
|
||||
assertThat(output, containsString("value2"));
|
||||
|
||||
objectMapper = Jackson2ObjectMapperBuilder.json().filters((new SimpleFilterProvider().setFailOnUnknownId(false)
|
||||
.setDefaultFilter(SimpleBeanPropertyFilter.serializeAllExcept("property2")))).build();
|
||||
SimpleFilterProvider provider = new SimpleFilterProvider()
|
||||
.setFailOnUnknownId(false)
|
||||
.setDefaultFilter(SimpleBeanPropertyFilter.serializeAllExcept("property2"));
|
||||
objectMapper = Jackson2ObjectMapperBuilder.json().filters(provider).build();
|
||||
output = objectMapper.writeValueAsString(bean);
|
||||
assertThat(output, containsString("value1"));
|
||||
assertThat(output, not(containsString("value2")));
|
||||
@@ -378,7 +406,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.json()
|
||||
.modules(new ArrayList<>()) // Disable well-known modules detection
|
||||
.serializers(serializer1)
|
||||
.serializersByType(Collections.<Class<?>, JsonSerializer<?>>singletonMap(Boolean.class, serializer2))
|
||||
.serializersByType(Collections.singletonMap(Boolean.class, serializer2))
|
||||
.deserializersByType(deserializerMap)
|
||||
.annotationIntrospector(annotationIntrospector)
|
||||
.featuresToEnable(SerializationFeature.FAIL_ON_EMPTY_BEANS,
|
||||
@@ -391,35 +419,35 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
JsonGenerator.Feature.QUOTE_FIELD_NAMES)
|
||||
.serializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
builder.configure(objectMapper);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
builder.configure(mapper);
|
||||
|
||||
assertTrue(getSerializerFactoryConfig(objectMapper).hasSerializers());
|
||||
assertTrue(getDeserializerFactoryConfig(objectMapper).hasDeserializers());
|
||||
assertTrue(getSerializerFactoryConfig(mapper).hasSerializers());
|
||||
assertTrue(getDeserializerFactoryConfig(mapper).hasDeserializers());
|
||||
|
||||
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
|
||||
Serializers serializers = getSerializerFactoryConfig(mapper).serializers().iterator().next();
|
||||
assertSame(serializer1, serializers.findSerializer(null, SimpleType.construct(Class.class), null));
|
||||
assertSame(serializer2, serializers.findSerializer(null, SimpleType.construct(Boolean.class), null));
|
||||
assertNull(serializers.findSerializer(null, SimpleType.construct(Number.class), null));
|
||||
|
||||
Deserializers deserializers = getDeserializerFactoryConfig(objectMapper).deserializers().iterator().next();
|
||||
Deserializers deserializers = getDeserializerFactoryConfig(mapper).deserializers().iterator().next();
|
||||
assertSame(deserializer, deserializers.findBeanDeserializer(SimpleType.construct(Date.class), null, null));
|
||||
|
||||
assertSame(annotationIntrospector, objectMapper.getSerializationConfig().getAnnotationIntrospector());
|
||||
assertSame(annotationIntrospector, objectMapper.getDeserializationConfig().getAnnotationIntrospector());
|
||||
assertSame(annotationIntrospector, mapper.getSerializationConfig().getAnnotationIntrospector());
|
||||
assertSame(annotationIntrospector, mapper.getDeserializationConfig().getAnnotationIntrospector());
|
||||
|
||||
assertTrue(objectMapper.getSerializationConfig().isEnabled(SerializationFeature.FAIL_ON_EMPTY_BEANS));
|
||||
assertTrue(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.UNWRAP_ROOT_VALUE));
|
||||
assertTrue(objectMapper.getFactory().isEnabled(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER));
|
||||
assertTrue(objectMapper.getFactory().isEnabled(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS));
|
||||
assertTrue(mapper.getSerializationConfig().isEnabled(SerializationFeature.FAIL_ON_EMPTY_BEANS));
|
||||
assertTrue(mapper.getDeserializationConfig().isEnabled(DeserializationFeature.UNWRAP_ROOT_VALUE));
|
||||
assertTrue(mapper.getFactory().isEnabled(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER));
|
||||
assertTrue(mapper.getFactory().isEnabled(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS));
|
||||
|
||||
assertFalse(objectMapper.getSerializationConfig().isEnabled(MapperFeature.AUTO_DETECT_GETTERS));
|
||||
assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
|
||||
assertFalse(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
|
||||
assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.AUTO_DETECT_FIELDS));
|
||||
assertFalse(objectMapper.getFactory().isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE));
|
||||
assertFalse(objectMapper.getFactory().isEnabled(JsonGenerator.Feature.QUOTE_FIELD_NAMES));
|
||||
assertSame(JsonInclude.Include.NON_NULL, objectMapper.getSerializationConfig().getSerializationInclusion());
|
||||
assertFalse(mapper.getSerializationConfig().isEnabled(MapperFeature.AUTO_DETECT_GETTERS));
|
||||
assertFalse(mapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
|
||||
assertFalse(mapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
|
||||
assertFalse(mapper.getDeserializationConfig().isEnabled(MapperFeature.AUTO_DETECT_FIELDS));
|
||||
assertFalse(mapper.getFactory().isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE));
|
||||
assertFalse(mapper.getFactory().isEnabled(JsonGenerator.Feature.QUOTE_FIELD_NAMES));
|
||||
assertSame(JsonInclude.Include.NON_NULL, mapper.getSerializationConfig().getSerializationInclusion());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -495,7 +523,9 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
public static class CustomIntegerSerializer extends JsonSerializer<Integer> {
|
||||
|
||||
@Override
|
||||
public void serialize(Integer value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
public void serialize(Integer value, JsonGenerator gen, SerializerProvider serializers)
|
||||
throws IOException {
|
||||
|
||||
gen.writeStartObject();
|
||||
gen.writeNumberField("customid", value);
|
||||
gen.writeEndObject();
|
||||
|
||||
@@ -84,8 +84,13 @@ public class MappingJackson2HttpMessageConverterTests {
|
||||
|
||||
@Test
|
||||
public void readTyped() throws IOException {
|
||||
String body =
|
||||
"{\"bytes\":\"AQI=\",\"array\":[\"Foo\",\"Bar\"],\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}";
|
||||
String body = "{" +
|
||||
"\"bytes\":\"AQI=\"," +
|
||||
"\"array\":[\"Foo\",\"Bar\"]," +
|
||||
"\"number\":42," +
|
||||
"\"string\":\"Foo\"," +
|
||||
"\"bool\":true," +
|
||||
"\"fraction\":42.0}";
|
||||
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
|
||||
inputMessage.getHeaders().setContentType(new MediaType("application", "json"));
|
||||
MyBean result = (MyBean) converter.read(MyBean.class, inputMessage);
|
||||
@@ -100,8 +105,13 @@ public class MappingJackson2HttpMessageConverterTests {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void readUntyped() throws IOException {
|
||||
String body =
|
||||
"{\"bytes\":\"AQI=\",\"array\":[\"Foo\",\"Bar\"],\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}";
|
||||
String body = "{" +
|
||||
"\"bytes\":\"AQI=\"," +
|
||||
"\"array\":[\"Foo\",\"Bar\"]," +
|
||||
"\"number\":42," +
|
||||
"\"string\":\"Foo\"," +
|
||||
"\"bool\":true," +
|
||||
"\"fraction\":42.0}";
|
||||
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
|
||||
inputMessage.getHeaders().setContentType(new MediaType("application", "json"));
|
||||
HashMap<String, Object> result = (HashMap<String, Object>) converter.read(HashMap.class, inputMessage);
|
||||
@@ -179,8 +189,13 @@ public class MappingJackson2HttpMessageConverterTests {
|
||||
}
|
||||
}
|
||||
};
|
||||
String body =
|
||||
"[{\"bytes\":\"AQI=\",\"array\":[\"Foo\",\"Bar\"],\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}]";
|
||||
String body = "[{" +
|
||||
"\"bytes\":\"AQI=\"," +
|
||||
"\"array\":[\"Foo\",\"Bar\"]," +
|
||||
"\"number\":42," +
|
||||
"\"string\":\"Foo\"," +
|
||||
"\"bool\":true," +
|
||||
"\"fraction\":42.0}]";
|
||||
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
|
||||
inputMessage.getHeaders().setContentType(new MediaType("application", "json"));
|
||||
|
||||
@@ -200,8 +215,13 @@ public class MappingJackson2HttpMessageConverterTests {
|
||||
public void readParameterizedType() throws IOException {
|
||||
ParameterizedTypeReference<List<MyBean>> beansList = new ParameterizedTypeReference<List<MyBean>>() {};
|
||||
|
||||
String body =
|
||||
"[{\"bytes\":\"AQI=\",\"array\":[\"Foo\",\"Bar\"],\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}]";
|
||||
String body = "[{" +
|
||||
"\"bytes\":\"AQI=\"," +
|
||||
"\"array\":[\"Foo\",\"Bar\"]," +
|
||||
"\"number\":42," +
|
||||
"\"string\":\"Foo\"," +
|
||||
"\"bool\":true," +
|
||||
"\"fraction\":42.0}]";
|
||||
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
|
||||
inputMessage.getHeaders().setContentType(new MediaType("application", "json"));
|
||||
|
||||
@@ -228,7 +248,8 @@ public class MappingJackson2HttpMessageConverterTests {
|
||||
this.converter.writeInternal(bean, null, outputMessage);
|
||||
String result = outputMessage.getBodyAsString(StandardCharsets.UTF_8);
|
||||
|
||||
assertEquals("{" + NEWLINE_SYSTEM_PROPERTY + " \"name\" : \"Jason\"" + NEWLINE_SYSTEM_PROPERTY + "}", result);
|
||||
assertEquals("{" + NEWLINE_SYSTEM_PROPERTY +
|
||||
" \"name\" : \"Jason\"" + NEWLINE_SYSTEM_PROPERTY + "}", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -136,7 +136,9 @@ public class SpringHandlerInstantiatorTests {
|
||||
private Capitalizer capitalizer;
|
||||
|
||||
@Override
|
||||
public void serialize(User user, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
|
||||
public void serialize(User user, JsonGenerator jsonGenerator,
|
||||
SerializerProvider serializerProvider) throws IOException {
|
||||
|
||||
jsonGenerator.writeStartObject();
|
||||
jsonGenerator.writeStringField("username", this.capitalizer.capitalize(user.getUsername()));
|
||||
jsonGenerator.writeEndObject();
|
||||
@@ -150,7 +152,7 @@ public class SpringHandlerInstantiatorTests {
|
||||
private Capitalizer capitalizer;
|
||||
|
||||
@Override
|
||||
public Object deserializeKey(String key, DeserializationContext context) throws IOException, JsonProcessingException {
|
||||
public Object deserializeKey(String key, DeserializationContext context) throws IOException {
|
||||
return this.capitalizer.capitalize(key);
|
||||
}
|
||||
}
|
||||
@@ -164,13 +166,17 @@ public class SpringHandlerInstantiatorTests {
|
||||
public static boolean isAutowiredFiledInitialized = false;
|
||||
|
||||
@Override
|
||||
public TypeSerializer buildTypeSerializer(SerializationConfig config, JavaType baseType, Collection<NamedType> subtypes) {
|
||||
public TypeSerializer buildTypeSerializer(SerializationConfig config, JavaType baseType,
|
||||
Collection<NamedType> subtypes) {
|
||||
|
||||
isAutowiredFiledInitialized = (this.capitalizer != null);
|
||||
return super.buildTypeSerializer(config, baseType, subtypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDeserializer buildTypeDeserializer(DeserializationConfig config, JavaType baseType, Collection<NamedType> subtypes) {
|
||||
public TypeDeserializer buildTypeDeserializer(DeserializationConfig config,
|
||||
JavaType baseType, Collection<NamedType> subtypes) {
|
||||
|
||||
return super.buildTypeDeserializer(config, baseType, subtypes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,15 +82,20 @@ public class Jaxb2RootElementHttpMessageConverterTests {
|
||||
|
||||
@Test
|
||||
public void canRead() throws Exception {
|
||||
assertTrue("Converter does not support reading @XmlRootElement", converter.canRead(RootElement.class, null));
|
||||
assertTrue("Converter does not support reading @XmlType", converter.canRead(Type.class, null));
|
||||
assertTrue("Converter does not support reading @XmlRootElement",
|
||||
converter.canRead(RootElement.class, null));
|
||||
assertTrue("Converter does not support reading @XmlType",
|
||||
converter.canRead(Type.class, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canWrite() throws Exception {
|
||||
assertTrue("Converter does not support writing @XmlRootElement", converter.canWrite(RootElement.class, null));
|
||||
assertTrue("Converter does not support writing @XmlRootElement subclass", converter.canWrite(RootElementSubclass.class, null));
|
||||
assertTrue("Converter does not support writing @XmlRootElement subclass", converter.canWrite(rootElementCglib.getClass(), null));
|
||||
assertTrue("Converter does not support writing @XmlRootElement",
|
||||
converter.canWrite(RootElement.class, null));
|
||||
assertTrue("Converter does not support writing @XmlRootElement subclass",
|
||||
converter.canWrite(RootElementSubclass.class, null));
|
||||
assertTrue("Converter does not support writing @XmlRootElement subclass",
|
||||
converter.canWrite(rootElementCglib.getClass(), null));
|
||||
assertFalse("Converter supports writing @XmlType", converter.canWrite(Type.class, null));
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,14 @@ public class MappingJackson2XmlHttpMessageConverterTests {
|
||||
|
||||
@Test
|
||||
public void read() throws IOException {
|
||||
String body = "<MyBean><string>Foo</string><number>42</number><fraction>42.0</fraction><array><array>Foo</array><array>Bar</array></array><bool>true</bool><bytes>AQI=</bytes></MyBean>";
|
||||
String body = "<MyBean>" +
|
||||
"<string>Foo</string>" +
|
||||
"<number>42</number>" +
|
||||
"<fraction>42.0</fraction>" +
|
||||
"<array><array>Foo</array>" +
|
||||
"<array>Bar</array></array>" +
|
||||
"<bool>true</bool>" +
|
||||
"<bytes>AQI=</bytes></MyBean>";
|
||||
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
|
||||
inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
|
||||
MyBean result = (MyBean) converter.read(MyBean.class, inputMessage);
|
||||
|
||||
@@ -57,7 +57,9 @@ public class MockExpressionEvaluator extends javax.servlet.jsp.el.ExpressionEval
|
||||
|
||||
return new javax.servlet.jsp.el.Expression() {
|
||||
@Override
|
||||
public Object evaluate(javax.servlet.jsp.el.VariableResolver variableResolver) throws javax.servlet.jsp.el.ELException {
|
||||
public Object evaluate(javax.servlet.jsp.el.VariableResolver variableResolver)
|
||||
throws javax.servlet.jsp.el.ELException {
|
||||
|
||||
return doEvaluate(expression, expectedType, functionMapper);
|
||||
}
|
||||
};
|
||||
@@ -65,7 +67,8 @@ public class MockExpressionEvaluator extends javax.servlet.jsp.el.ExpressionEval
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Object evaluate(String expression, Class expectedType, javax.servlet.jsp.el.VariableResolver variableResolver,
|
||||
public Object evaluate(String expression, Class expectedType,
|
||||
javax.servlet.jsp.el.VariableResolver variableResolver,
|
||||
javax.servlet.jsp.el.FunctionMapper functionMapper) throws javax.servlet.jsp.el.ELException {
|
||||
|
||||
Assert.isNull(variableResolver, "Custom VariableResolver not supported");
|
||||
@@ -73,15 +76,17 @@ public class MockExpressionEvaluator extends javax.servlet.jsp.el.ExpressionEval
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected Object doEvaluate(String expression, Class expectedType, javax.servlet.jsp.el.FunctionMapper functionMapper)
|
||||
throws javax.servlet.jsp.el.ELException {
|
||||
protected Object doEvaluate(String expression, Class expectedType,
|
||||
javax.servlet.jsp.el.FunctionMapper functionMapper) throws javax.servlet.jsp.el.ELException {
|
||||
|
||||
Assert.isNull(functionMapper, "Custom FunctionMapper not supported");
|
||||
try {
|
||||
return ExpressionEvaluatorManager.evaluate("JSP EL expression", expression, expectedType, this.pageContext);
|
||||
return ExpressionEvaluatorManager.evaluate(
|
||||
"JSP EL expression", expression, expectedType, this.pageContext);
|
||||
}
|
||||
catch (JspException ex) {
|
||||
throw new javax.servlet.jsp.el.ELException("Parsing of JSP EL expression \"" + expression + "\" failed", ex);
|
||||
throw new javax.servlet.jsp.el.ELException(
|
||||
"Parsing of JSP EL expression \"" + expression + "\" failed", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -526,7 +526,8 @@ public final class Msg extends
|
||||
// optional .SecondMsg blah = 2;
|
||||
private org.springframework.protobuf.SecondMsg blah_ = org.springframework.protobuf.SecondMsg.getDefaultInstance();
|
||||
private com.google.protobuf.SingleFieldBuilder<
|
||||
org.springframework.protobuf.SecondMsg, org.springframework.protobuf.SecondMsg.Builder, org.springframework.protobuf.SecondMsgOrBuilder> blahBuilder_;
|
||||
org.springframework.protobuf.SecondMsg, org.springframework.protobuf.SecondMsg.Builder,
|
||||
org.springframework.protobuf.SecondMsgOrBuilder> blahBuilder_;
|
||||
/**
|
||||
* <code>optional .SecondMsg blah = 2;</code>
|
||||
*/
|
||||
@@ -627,7 +628,8 @@ public final class Msg extends
|
||||
* <code>optional .SecondMsg blah = 2;</code>
|
||||
*/
|
||||
private com.google.protobuf.SingleFieldBuilder<
|
||||
org.springframework.protobuf.SecondMsg, org.springframework.protobuf.SecondMsg.Builder, org.springframework.protobuf.SecondMsgOrBuilder>
|
||||
org.springframework.protobuf.SecondMsg, org.springframework.protobuf.SecondMsg.Builder,
|
||||
org.springframework.protobuf.SecondMsgOrBuilder>
|
||||
getBlahFieldBuilder() {
|
||||
if (blahBuilder_ == null) {
|
||||
blahBuilder_ = new com.google.protobuf.SingleFieldBuilder<>(
|
||||
|
||||
@@ -25,7 +25,8 @@ import org.springframework.util.Assert;
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
@WebService(serviceName="OrderService", portName="OrderService", endpointInterface = "org.springframework.remoting.jaxws.OrderService")
|
||||
@WebService(serviceName="OrderService", portName="OrderService",
|
||||
endpointInterface = "org.springframework.remoting.jaxws.OrderService")
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
|
||||
@Resource
|
||||
|
||||
@@ -50,12 +50,13 @@ public class EscapedErrorsTests {
|
||||
assertTrue("Correct global errors flag", errors.hasGlobalErrors());
|
||||
assertTrue("Correct number of global errors", errors.getGlobalErrorCount() == 1);
|
||||
ObjectError globalError = errors.getGlobalError();
|
||||
assertTrue("Global error message escaped", "message: " '".equals(globalError.getDefaultMessage()));
|
||||
String defaultMessage = globalError.getDefaultMessage();
|
||||
assertTrue("Global error message escaped", "message: " '".equals(defaultMessage));
|
||||
assertTrue("Global error code not escaped", "GENERAL_ERROR \" '".equals(globalError.getCode()));
|
||||
ObjectError globalErrorInList = errors.getGlobalErrors().get(0);
|
||||
assertTrue("Same global error in list", globalError.getDefaultMessage().equals(globalErrorInList.getDefaultMessage()));
|
||||
assertTrue("Same global error in list", defaultMessage.equals(globalErrorInList.getDefaultMessage()));
|
||||
ObjectError globalErrorInAllList = errors.getAllErrors().get(3);
|
||||
assertTrue("Same global error in list", globalError.getDefaultMessage().equals(globalErrorInAllList.getDefaultMessage()));
|
||||
assertTrue("Same global error in list", defaultMessage.equals(globalErrorInAllList.getDefaultMessage()));
|
||||
|
||||
assertTrue("Correct field errors flag", errors.hasFieldErrors());
|
||||
assertTrue("Correct number of field errors", errors.getFieldErrorCount() == 3);
|
||||
|
||||
@@ -58,6 +58,7 @@ import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.http.HttpMethod.POST;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -248,8 +249,8 @@ public class RestTemplateIntegrationTests extends AbstractMockWebServerTestCase
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
requestHeaders.set("MyHeader", "MyValue");
|
||||
requestHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||
HttpEntity<String> requestEntity = new HttpEntity<>(helloWorld, requestHeaders);
|
||||
HttpEntity<Void> result = template.exchange(baseUrl + "/{method}", HttpMethod.POST, requestEntity, Void.class, "post");
|
||||
HttpEntity<String> entity = new HttpEntity<>(helloWorld, requestHeaders);
|
||||
HttpEntity<Void> result = template.exchange(baseUrl + "/{method}", POST, entity, Void.class, "post");
|
||||
assertEquals("Invalid location", new URI(baseUrl + "/post/1"), result.getHeaders().getLocation());
|
||||
assertFalse(result.hasBody());
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ import org.springframework.web.util.DefaultUriBuilderFactory;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
import static org.springframework.http.HttpMethod.POST;
|
||||
import static org.springframework.http.MediaType.*;
|
||||
|
||||
/**
|
||||
@@ -326,7 +327,7 @@ public class RestTemplateTests {
|
||||
|
||||
@Test
|
||||
public void postForLocation() throws Exception {
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), HttpMethod.POST)).willReturn(request);
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), POST)).willReturn(request);
|
||||
String helloWorld = "Hello World";
|
||||
given(converter.canWrite(String.class, null)).willReturn(true);
|
||||
converter.write(helloWorld, null, request);
|
||||
@@ -348,7 +349,7 @@ public class RestTemplateTests {
|
||||
|
||||
@Test
|
||||
public void postForLocationEntityContentType() throws Exception {
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), HttpMethod.POST)).willReturn(request);
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), POST)).willReturn(request);
|
||||
String helloWorld = "Hello World";
|
||||
MediaType contentType = MediaType.TEXT_PLAIN;
|
||||
given(converter.canWrite(String.class, contentType)).willReturn(true);
|
||||
@@ -377,7 +378,7 @@ public class RestTemplateTests {
|
||||
|
||||
@Test
|
||||
public void postForLocationEntityCustomHeader() throws Exception {
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), HttpMethod.POST)).willReturn(request);
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), POST)).willReturn(request);
|
||||
String helloWorld = "Hello World";
|
||||
given(converter.canWrite(String.class, null)).willReturn(true);
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
@@ -406,7 +407,7 @@ public class RestTemplateTests {
|
||||
|
||||
@Test
|
||||
public void postForLocationNoLocation() throws Exception {
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), HttpMethod.POST)).willReturn(request);
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), POST)).willReturn(request);
|
||||
String helloWorld = "Hello World";
|
||||
given(converter.canWrite(String.class, null)).willReturn(true);
|
||||
converter.write(helloWorld, null, request);
|
||||
@@ -426,7 +427,7 @@ public class RestTemplateTests {
|
||||
|
||||
@Test
|
||||
public void postForLocationNull() throws Exception {
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), HttpMethod.POST)).willReturn(request);
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), POST)).willReturn(request);
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
given(request.getHeaders()).willReturn(requestHeaders);
|
||||
given(request.execute()).willReturn(response);
|
||||
@@ -448,7 +449,7 @@ public class RestTemplateTests {
|
||||
MediaType textPlain = new MediaType("text", "plain");
|
||||
given(converter.canRead(Integer.class, null)).willReturn(true);
|
||||
given(converter.getSupportedMediaTypes()).willReturn(Collections.singletonList(textPlain));
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), HttpMethod.POST)).willReturn(this.request);
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), POST)).willReturn(this.request);
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
given(this.request.getHeaders()).willReturn(requestHeaders);
|
||||
String request = "Hello World";
|
||||
@@ -481,7 +482,7 @@ public class RestTemplateTests {
|
||||
MediaType textPlain = new MediaType("text", "plain");
|
||||
given(converter.canRead(Integer.class, null)).willReturn(true);
|
||||
given(converter.getSupportedMediaTypes()).willReturn(Collections.singletonList(textPlain));
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), HttpMethod.POST)).willReturn(this.request);
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), POST)).willReturn(this.request);
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
given(this.request.getHeaders()).willReturn(requestHeaders);
|
||||
String request = "Hello World";
|
||||
@@ -514,7 +515,7 @@ public class RestTemplateTests {
|
||||
MediaType textPlain = new MediaType("text", "plain");
|
||||
given(converter.canRead(Integer.class, null)).willReturn(true);
|
||||
given(converter.getSupportedMediaTypes()).willReturn(Collections.singletonList(textPlain));
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), HttpMethod.POST)).willReturn(request);
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), POST)).willReturn(request);
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
given(request.getHeaders()).willReturn(requestHeaders);
|
||||
given(request.execute()).willReturn(response);
|
||||
@@ -543,7 +544,7 @@ public class RestTemplateTests {
|
||||
MediaType textPlain = new MediaType("text", "plain");
|
||||
given(converter.canRead(Integer.class, null)).willReturn(true);
|
||||
given(converter.getSupportedMediaTypes()).willReturn(Collections.singletonList(textPlain));
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), HttpMethod.POST)).willReturn(request);
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), POST)).willReturn(request);
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
given(request.getHeaders()).willReturn(requestHeaders);
|
||||
given(request.execute()).willReturn(response);
|
||||
@@ -685,7 +686,7 @@ public class RestTemplateTests {
|
||||
given(request.execute()).willReturn(response);
|
||||
given(errorHandler.hasError(response)).willReturn(false);
|
||||
HttpHeaders responseHeaders = new HttpHeaders();
|
||||
EnumSet<HttpMethod> expected = EnumSet.of(HttpMethod.GET, HttpMethod.POST);
|
||||
EnumSet<HttpMethod> expected = EnumSet.of(HttpMethod.GET, POST);
|
||||
responseHeaders.setAllow(expected);
|
||||
given(response.getHeaders()).willReturn(responseHeaders);
|
||||
HttpStatus status = HttpStatus.OK;
|
||||
@@ -747,7 +748,7 @@ public class RestTemplateTests {
|
||||
public void exchange() throws Exception {
|
||||
given(converter.canRead(Integer.class, null)).willReturn(true);
|
||||
given(converter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN));
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), HttpMethod.POST)).willReturn(this.request);
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), POST)).willReturn(this.request);
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
given(this.request.getHeaders()).willReturn(requestHeaders);
|
||||
given(converter.canWrite(String.class, null)).willReturn(true);
|
||||
@@ -769,8 +770,8 @@ public class RestTemplateTests {
|
||||
|
||||
HttpHeaders entityHeaders = new HttpHeaders();
|
||||
entityHeaders.set("MyHeader", "MyValue");
|
||||
HttpEntity<String> requestEntity = new HttpEntity<>(body, entityHeaders);
|
||||
ResponseEntity<Integer> result = template.exchange("http://example.com", HttpMethod.POST, requestEntity, Integer.class);
|
||||
HttpEntity<String> entity = new HttpEntity<>(body, entityHeaders);
|
||||
ResponseEntity<Integer> result = template.exchange("http://example.com", POST, entity, Integer.class);
|
||||
assertEquals("Invalid POST result", expected, result.getBody());
|
||||
assertEquals("Invalid Content-Type", MediaType.TEXT_PLAIN, result.getHeaders().getContentType());
|
||||
assertEquals("Invalid Accept header", MediaType.TEXT_PLAIN_VALUE, requestHeaders.getFirst("Accept"));
|
||||
@@ -789,7 +790,7 @@ public class RestTemplateTests {
|
||||
ParameterizedTypeReference<List<Integer>> intList = new ParameterizedTypeReference<List<Integer>>() {};
|
||||
given(converter.canRead(intList.getType(), null, null)).willReturn(true);
|
||||
given(converter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN));
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), HttpMethod.POST)).willReturn(this.request);
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), POST)).willReturn(this.request);
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
given(this.request.getHeaders()).willReturn(requestHeaders);
|
||||
given(converter.canWrite(String.class, String.class, null)).willReturn(true);
|
||||
@@ -811,7 +812,7 @@ public class RestTemplateTests {
|
||||
HttpHeaders entityHeaders = new HttpHeaders();
|
||||
entityHeaders.set("MyHeader", "MyValue");
|
||||
HttpEntity<String> requestEntity = new HttpEntity<>(requestBody, entityHeaders);
|
||||
ResponseEntity<List<Integer>> result = template.exchange("http://example.com", HttpMethod.POST, requestEntity, intList);
|
||||
ResponseEntity<List<Integer>> result = template.exchange("http://example.com", POST, requestEntity, intList);
|
||||
assertEquals("Invalid POST result", expected, result.getBody());
|
||||
assertEquals("Invalid Content-Type", MediaType.TEXT_PLAIN, result.getHeaders().getContentType());
|
||||
assertEquals("Invalid Accept header", MediaType.TEXT_PLAIN_VALUE, requestHeaders.getFirst("Accept"));
|
||||
|
||||
@@ -126,7 +126,8 @@ public class ServletWebRequestHttpMethodsTests {
|
||||
assertTrue(request.checkNotModified(epochTime));
|
||||
|
||||
assertEquals(304, servletResponse.getStatus());
|
||||
assertEquals(RFC_1123_DATE_TIME.format(Instant.ofEpochMilli(epochTime).atZone(GMT)), servletResponse.getHeader("Last-Modified"));
|
||||
assertEquals(RFC_1123_DATE_TIME.format(Instant.ofEpochMilli(epochTime).atZone(GMT)),
|
||||
servletResponse.getHeader("Last-Modified"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -137,7 +138,8 @@ public class ServletWebRequestHttpMethodsTests {
|
||||
assertFalse(request.checkNotModified(currentDate.getTime()));
|
||||
|
||||
assertEquals(200, servletResponse.getStatus());
|
||||
assertEquals(RFC_1123_DATE_TIME.format(currentDate.toInstant().atZone(GMT)), servletResponse.getHeader("Last-Modified"));
|
||||
assertEquals(RFC_1123_DATE_TIME.format(currentDate.toInstant().atZone(GMT)),
|
||||
servletResponse.getHeader("Last-Modified"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -220,7 +222,8 @@ public class ServletWebRequestHttpMethodsTests {
|
||||
|
||||
assertEquals(304, servletResponse.getStatus());
|
||||
assertEquals(eTag, servletResponse.getHeader("ETag"));
|
||||
assertEquals(RFC_1123_DATE_TIME.format(currentDate.toInstant().atZone(GMT)), servletResponse.getHeader("Last-Modified"));
|
||||
assertEquals(RFC_1123_DATE_TIME.format(currentDate.toInstant().atZone(GMT)),
|
||||
servletResponse.getHeader("Last-Modified"));
|
||||
}
|
||||
|
||||
@Test // SPR-14224
|
||||
@@ -235,7 +238,8 @@ public class ServletWebRequestHttpMethodsTests {
|
||||
|
||||
assertEquals(304, servletResponse.getStatus());
|
||||
assertEquals(eTag, servletResponse.getHeader("ETag"));
|
||||
assertEquals(RFC_1123_DATE_TIME.format(Instant.ofEpochMilli(currentEpoch).atZone(GMT)), servletResponse.getHeader("Last-Modified"));
|
||||
assertEquals(RFC_1123_DATE_TIME.format(Instant.ofEpochMilli(currentEpoch).atZone(GMT)),
|
||||
servletResponse.getHeader("Last-Modified"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -250,7 +254,8 @@ public class ServletWebRequestHttpMethodsTests {
|
||||
|
||||
assertEquals(200, servletResponse.getStatus());
|
||||
assertEquals(currentETag, servletResponse.getHeader("ETag"));
|
||||
assertEquals(RFC_1123_DATE_TIME.format(Instant.ofEpochMilli(epochTime).atZone(GMT)), servletResponse.getHeader("Last-Modified"));
|
||||
assertEquals(RFC_1123_DATE_TIME.format(Instant.ofEpochMilli(epochTime).atZone(GMT)),
|
||||
servletResponse.getHeader("Last-Modified"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -297,7 +302,8 @@ public class ServletWebRequestHttpMethodsTests {
|
||||
assertTrue(request.checkNotModified(epochTime));
|
||||
|
||||
assertEquals(304, servletResponse.getStatus());
|
||||
assertEquals(RFC_1123_DATE_TIME.format(Instant.ofEpochMilli(epochTime).atZone(GMT)), servletResponse.getHeader("Last-Modified"));
|
||||
assertEquals(RFC_1123_DATE_TIME.format(Instant.ofEpochMilli(epochTime).atZone(GMT)),
|
||||
servletResponse.getHeader("Last-Modified"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -309,7 +315,8 @@ public class ServletWebRequestHttpMethodsTests {
|
||||
assertFalse(request.checkNotModified(epochTime));
|
||||
|
||||
assertEquals(200, servletResponse.getStatus());
|
||||
assertEquals(RFC_1123_DATE_TIME.format(Instant.ofEpochMilli(epochTime).atZone(GMT)), servletResponse.getHeader("Last-Modified"));
|
||||
assertEquals(RFC_1123_DATE_TIME.format(Instant.ofEpochMilli(epochTime).atZone(GMT)),
|
||||
servletResponse.getHeader("Last-Modified"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -42,11 +42,16 @@ public class StandardServletEnvironmentTests {
|
||||
ConfigurableEnvironment env = new StandardServletEnvironment();
|
||||
MutablePropertySources sources = env.getPropertySources();
|
||||
|
||||
assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), equalTo(0));
|
||||
assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)), equalTo(1));
|
||||
assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME)), equalTo(2));
|
||||
assertThat(sources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)), equalTo(3));
|
||||
assertThat(sources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)), equalTo(4));
|
||||
assertThat(sources.precedenceOf(PropertySource.named(
|
||||
StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), equalTo(0));
|
||||
assertThat(sources.precedenceOf(PropertySource.named(
|
||||
StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)), equalTo(1));
|
||||
assertThat(sources.precedenceOf(PropertySource.named(
|
||||
StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME)), equalTo(2));
|
||||
assertThat(sources.precedenceOf(PropertySource.named(
|
||||
StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)), equalTo(3));
|
||||
assertThat(sources.precedenceOf(PropertySource.named(
|
||||
StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)), equalTo(4));
|
||||
assertThat(sources.size(), is(5));
|
||||
}
|
||||
|
||||
|
||||
@@ -232,8 +232,10 @@ public class CorsConfigurationTests {
|
||||
config.addAllowedHeader("header1");
|
||||
config.addAllowedHeader("header2");
|
||||
assertEquals(Arrays.asList("header1"), config.checkHeaders(Arrays.asList("header1")));
|
||||
assertEquals(Arrays.asList("header1", "header2"), config.checkHeaders(Arrays.asList("header1", "header2")));
|
||||
assertEquals(Arrays.asList("header1", "header2"), config.checkHeaders(Arrays.asList("header1", "header2", "header3")));
|
||||
assertEquals(Arrays.asList("header1", "header2"),
|
||||
config.checkHeaders(Arrays.asList("header1", "header2")));
|
||||
assertEquals(Arrays.asList("header1", "header2"),
|
||||
config.checkHeaders(Arrays.asList("header1", "header2", "header3")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -32,15 +32,20 @@ public class UrlBasedCorsConfigurationSourceTests {
|
||||
|
||||
@Test
|
||||
public void empty() {
|
||||
assertNull(this.configSource.getCorsConfiguration(new MockHttpServletRequest(HttpMethod.GET.name(), "/bar/test.html")));
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(HttpMethod.GET.name(), "/bar/test.html");
|
||||
assertNull(this.configSource.getCorsConfiguration(request));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerAndMatch() {
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
this.configSource.registerCorsConfiguration("/bar/**", config);
|
||||
assertNull(this.configSource.getCorsConfiguration(new MockHttpServletRequest(HttpMethod.GET.name(), "/foo/test.html")));
|
||||
assertEquals(config, this.configSource.getCorsConfiguration(new MockHttpServletRequest(HttpMethod.GET.name(), "/bar/test.html")));
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo/test.html");
|
||||
assertNull(this.configSource.getCorsConfiguration(request));
|
||||
|
||||
request.setRequestURI("/bar/test.html");
|
||||
assertEquals(config, this.configSource.getCorsConfiguration(request));
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
|
||||
@@ -46,7 +46,7 @@ public class CharacterEncodingFilterTests {
|
||||
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||
request.setCharacterEncoding(ENCODING);
|
||||
given(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)).willReturn(null);
|
||||
given(request.getAttribute(FILTER_NAME + OncePerRequestFilter.ALREADY_FILTERED_SUFFIX)).willReturn(null);
|
||||
given(request.getAttribute(filteredName(FILTER_NAME))).willReturn(null);
|
||||
|
||||
HttpServletResponse response = mock(HttpServletResponse.class);
|
||||
FilterChain filterChain = mock(FilterChain.class);
|
||||
@@ -55,8 +55,8 @@ public class CharacterEncodingFilterTests {
|
||||
filter.init(new MockFilterConfig(FILTER_NAME));
|
||||
filter.doFilter(request, response, filterChain);
|
||||
|
||||
verify(request).setAttribute(FILTER_NAME + OncePerRequestFilter.ALREADY_FILTERED_SUFFIX, Boolean.TRUE);
|
||||
verify(request).removeAttribute(FILTER_NAME + OncePerRequestFilter.ALREADY_FILTERED_SUFFIX);
|
||||
verify(request).setAttribute(filteredName(FILTER_NAME), Boolean.TRUE);
|
||||
verify(request).removeAttribute(filteredName(FILTER_NAME));
|
||||
verify(response).setCharacterEncoding(ENCODING);
|
||||
verify(filterChain).doFilter(request, response);
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class CharacterEncodingFilterTests {
|
||||
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||
given(request.getCharacterEncoding()).willReturn(null);
|
||||
given(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)).willReturn(null);
|
||||
given(request.getAttribute(FILTER_NAME + OncePerRequestFilter.ALREADY_FILTERED_SUFFIX)).willReturn(null);
|
||||
given(request.getAttribute(filteredName(FILTER_NAME))).willReturn(null);
|
||||
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
@@ -77,8 +77,8 @@ public class CharacterEncodingFilterTests {
|
||||
filter.doFilter(request, response, filterChain);
|
||||
|
||||
verify(request).setCharacterEncoding(ENCODING);
|
||||
verify(request).setAttribute(FILTER_NAME + OncePerRequestFilter.ALREADY_FILTERED_SUFFIX, Boolean.TRUE);
|
||||
verify(request).removeAttribute(FILTER_NAME + OncePerRequestFilter.ALREADY_FILTERED_SUFFIX);
|
||||
verify(request).setAttribute(filteredName(FILTER_NAME), Boolean.TRUE);
|
||||
verify(request).removeAttribute(filteredName(FILTER_NAME));
|
||||
verify(filterChain).doFilter(request, response);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public class CharacterEncodingFilterTests {
|
||||
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||
given(request.getCharacterEncoding()).willReturn(ENCODING);
|
||||
given(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)).willReturn(null);
|
||||
given(request.getAttribute(FILTER_NAME + OncePerRequestFilter.ALREADY_FILTERED_SUFFIX)).willReturn(null);
|
||||
given(request.getAttribute(filteredName(FILTER_NAME))).willReturn(null);
|
||||
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
@@ -97,8 +97,8 @@ public class CharacterEncodingFilterTests {
|
||||
filter.init(new MockFilterConfig(FILTER_NAME));
|
||||
filter.doFilter(request, response, filterChain);
|
||||
|
||||
verify(request).setAttribute(FILTER_NAME + OncePerRequestFilter.ALREADY_FILTERED_SUFFIX, Boolean.TRUE);
|
||||
verify(request).removeAttribute(FILTER_NAME + OncePerRequestFilter.ALREADY_FILTERED_SUFFIX);
|
||||
verify(request).setAttribute(filteredName(FILTER_NAME), Boolean.TRUE);
|
||||
verify(request).removeAttribute(filteredName(FILTER_NAME));
|
||||
verify(filterChain).doFilter(request, response);
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class CharacterEncodingFilterTests {
|
||||
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||
given(request.getCharacterEncoding()).willReturn(null);
|
||||
given(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)).willReturn(null);
|
||||
given(request.getAttribute(FILTER_NAME + OncePerRequestFilter.ALREADY_FILTERED_SUFFIX)).willReturn(null);
|
||||
given(request.getAttribute(filteredName(FILTER_NAME))).willReturn(null);
|
||||
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
@@ -120,8 +120,8 @@ public class CharacterEncodingFilterTests {
|
||||
filter.doFilter(request, response, filterChain);
|
||||
|
||||
verify(request).setCharacterEncoding(ENCODING);
|
||||
verify(request).setAttribute(FILTER_NAME + OncePerRequestFilter.ALREADY_FILTERED_SUFFIX, Boolean.TRUE);
|
||||
verify(request).removeAttribute(FILTER_NAME + OncePerRequestFilter.ALREADY_FILTERED_SUFFIX);
|
||||
verify(request).setAttribute(filteredName(FILTER_NAME), Boolean.TRUE);
|
||||
verify(request).removeAttribute(filteredName(FILTER_NAME));
|
||||
verify(filterChain).doFilter(request, response);
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public class CharacterEncodingFilterTests {
|
||||
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||
given(request.getCharacterEncoding()).willReturn(null);
|
||||
given(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)).willReturn(null);
|
||||
given(request.getAttribute(CharacterEncodingFilter.class.getName() + OncePerRequestFilter.ALREADY_FILTERED_SUFFIX)).willReturn(null);
|
||||
given(request.getAttribute(filteredName(CharacterEncodingFilter.class.getName()))).willReturn(null);
|
||||
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
@@ -140,8 +140,8 @@ public class CharacterEncodingFilterTests {
|
||||
filter.doFilter(request, response, filterChain);
|
||||
|
||||
verify(request).setCharacterEncoding(ENCODING);
|
||||
verify(request).setAttribute(CharacterEncodingFilter.class.getName() + OncePerRequestFilter.ALREADY_FILTERED_SUFFIX, Boolean.TRUE);
|
||||
verify(request).removeAttribute(CharacterEncodingFilter.class.getName() + OncePerRequestFilter.ALREADY_FILTERED_SUFFIX);
|
||||
verify(request).setAttribute(filteredName(CharacterEncodingFilter.class.getName()), Boolean.TRUE);
|
||||
verify(request).removeAttribute(filteredName(CharacterEncodingFilter.class.getName()));
|
||||
verify(filterChain).doFilter(request, response);
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ public class CharacterEncodingFilterTests {
|
||||
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||
request.setCharacterEncoding(ENCODING);
|
||||
given(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)).willReturn(null);
|
||||
given(request.getAttribute(FILTER_NAME + OncePerRequestFilter.ALREADY_FILTERED_SUFFIX)).willReturn(null);
|
||||
given(request.getAttribute(filteredName(FILTER_NAME))).willReturn(null);
|
||||
|
||||
HttpServletResponse response = mock(HttpServletResponse.class);
|
||||
FilterChain filterChain = mock(FilterChain.class);
|
||||
@@ -160,11 +160,15 @@ public class CharacterEncodingFilterTests {
|
||||
filter.init(new MockFilterConfig(FILTER_NAME));
|
||||
filter.doFilter(request, response, filterChain);
|
||||
|
||||
verify(request).setAttribute(FILTER_NAME + OncePerRequestFilter.ALREADY_FILTERED_SUFFIX, Boolean.TRUE);
|
||||
verify(request).removeAttribute(FILTER_NAME + OncePerRequestFilter.ALREADY_FILTERED_SUFFIX);
|
||||
verify(request).setAttribute(filteredName(FILTER_NAME), Boolean.TRUE);
|
||||
verify(request).removeAttribute(filteredName(FILTER_NAME));
|
||||
verify(request, times(2)).setCharacterEncoding(ENCODING);
|
||||
verify(response, never()).setCharacterEncoding(ENCODING);
|
||||
verify(filterChain).doFilter(request, response);
|
||||
}
|
||||
|
||||
private String filteredName(String prefix) {
|
||||
return prefix + OncePerRequestFilter.ALREADY_FILTERED_SUFFIX;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -146,7 +146,9 @@ public class DelegatingFilterProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDelegatingFilterProxyWithTargetBeanNameAndNotYetRefreshedApplicationContext() throws ServletException, IOException {
|
||||
public void testDelegatingFilterProxyWithTargetBeanNameAndNotYetRefreshedApplicationContext()
|
||||
throws ServletException, IOException {
|
||||
|
||||
MockServletContext sc = new MockServletContext();
|
||||
|
||||
StaticWebApplicationContext wac = new StaticWebApplicationContext();
|
||||
@@ -172,7 +174,9 @@ public class DelegatingFilterProxyTests {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testDelegatingFilterProxyWithTargetBeanNameAndNoApplicationContext() throws ServletException, IOException {
|
||||
public void testDelegatingFilterProxyWithTargetBeanNameAndNoApplicationContext()
|
||||
throws ServletException, IOException {
|
||||
|
||||
MockServletContext sc = new MockServletContext();
|
||||
|
||||
DelegatingFilterProxy filterProxy = new DelegatingFilterProxy("targetFilter", null);
|
||||
@@ -325,7 +329,9 @@ public class DelegatingFilterProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDelegatingFilterProxyNotInjectedWacServletAttrPreferred() throws ServletException, IOException {
|
||||
public void testDelegatingFilterProxyNotInjectedWacServletAttrPreferred()
|
||||
throws ServletException, IOException {
|
||||
|
||||
ServletContext sc = new MockServletContext();
|
||||
StaticWebApplicationContext wac = new StaticWebApplicationContext();
|
||||
wac.setServletContext(sc);
|
||||
@@ -401,7 +407,9 @@ public class DelegatingFilterProxyTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
|
||||
throws IOException, ServletException {
|
||||
|
||||
request.setAttribute("called", Boolean.TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -91,8 +91,9 @@ public class DelegatingNavigationHandlerTests {
|
||||
private String lastOutcome;
|
||||
|
||||
@Override
|
||||
public void handleNavigation(
|
||||
FacesContext facesContext, @Nullable String fromAction, @Nullable String outcome, @Nullable NavigationHandler originalNavigationHandler) {
|
||||
public void handleNavigation(FacesContext facesContext, @Nullable String fromAction,
|
||||
@Nullable String outcome, @Nullable NavigationHandler originalNavigationHandler) {
|
||||
|
||||
lastFromAction = fromAction;
|
||||
lastOutcome = outcome;
|
||||
if (originalNavigationHandler != null) {
|
||||
|
||||
@@ -49,7 +49,9 @@ public class UriComponentsBuilderTests {
|
||||
@Test
|
||||
public void plain() throws URISyntaxException {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
|
||||
UriComponents result = builder.scheme("http").host("example.com").path("foo").queryParam("bar").fragment("baz").build();
|
||||
UriComponents result = builder.scheme("http").host("example.com")
|
||||
.path("foo").queryParam("bar").fragment("baz")
|
||||
.build();
|
||||
assertEquals("http", result.getScheme());
|
||||
assertEquals("example.com", result.getHost());
|
||||
assertEquals("foo", result.getPath());
|
||||
@@ -62,7 +64,8 @@ public class UriComponentsBuilderTests {
|
||||
|
||||
@Test
|
||||
public void multipleFromSameBuilder() throws URISyntaxException {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.newInstance().scheme("http").host("example.com").pathSegment("foo");
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.newInstance()
|
||||
.scheme("http").host("example.com").pathSegment("foo");
|
||||
UriComponents result1 = builder.build();
|
||||
builder = builder.pathSegment("foo2").queryParam("bar").fragment("baz");
|
||||
UriComponents result2 = builder.build();
|
||||
@@ -129,7 +132,8 @@ public class UriComponentsBuilderTests {
|
||||
public void fromUriEncodedQuery() throws URISyntaxException {
|
||||
URI uri = new URI("http://www.example.org/?param=aGVsbG9Xb3JsZA%3D%3D");
|
||||
String fromUri = UriComponentsBuilder.fromUri(uri).build().getQueryParams().get("param").get(0);
|
||||
String fromUriString = UriComponentsBuilder.fromUriString(uri.toString()).build().getQueryParams().get("param").get(0);
|
||||
String fromUriString = UriComponentsBuilder.fromUriString(uri.toString())
|
||||
.build().getQueryParams().get("param").get(0);
|
||||
|
||||
assertEquals(fromUri, fromUriString);
|
||||
}
|
||||
@@ -146,9 +150,9 @@ public class UriComponentsBuilderTests {
|
||||
assertNull(result.getQuery());
|
||||
assertNull(result.getFragment());
|
||||
|
||||
result = UriComponentsBuilder.fromUriString(
|
||||
"http://arjen:foobar@java.sun.com:80/javase/6/docs/api/java/util/BitSet.html?foo=bar#and(java.util.BitSet)")
|
||||
.build();
|
||||
String url = "http://arjen:foobar@java.sun.com:80" +
|
||||
"/javase/6/docs/api/java/util/BitSet.html?foo=bar#and(java.util.BitSet)";
|
||||
result = UriComponentsBuilder.fromUriString(url).build();
|
||||
assertEquals("http", result.getScheme());
|
||||
assertEquals("arjen:foobar", result.getUserInfo());
|
||||
assertEquals("java.sun.com", result.getHost());
|
||||
@@ -635,7 +639,8 @@ public class UriComponentsBuilderTests {
|
||||
|
||||
@Test
|
||||
public void buildAndExpandOpaque() {
|
||||
UriComponents result = UriComponentsBuilder.fromUriString("mailto:{user}@{domain}").buildAndExpand("foo", "example.com");
|
||||
UriComponents result = UriComponentsBuilder.fromUriString("mailto:{user}@{domain}")
|
||||
.buildAndExpand("foo", "example.com");
|
||||
assertEquals("mailto:foo@example.com", result.toUriString());
|
||||
|
||||
Map<String, String> values = new HashMap<>();
|
||||
@@ -670,23 +675,38 @@ public class UriComponentsBuilderTests {
|
||||
|
||||
@Test
|
||||
public void relativeUrls() throws Exception {
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com/foo/../bar").build().toString(), equalTo("http://example.com/foo/../bar"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com/foo/../bar").build().toUriString(), equalTo("http://example.com/foo/../bar"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com/foo/../bar").build().toUri().getPath(), equalTo("/foo/../bar"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("../../").build().toString(), equalTo("../../"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("../../").build().toUriString(), equalTo("../../"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("../../").build().toUri().getPath(), equalTo("../../"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com").path("foo/../bar").build().toString(), equalTo("http://example.com/foo/../bar"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com").path("foo/../bar").build().toUriString(), equalTo("http://example.com/foo/../bar"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com").path("foo/../bar").build().toUri().getPath(), equalTo("/foo/../bar"));
|
||||
String baseUrl = "http://example.com";
|
||||
assertThat(UriComponentsBuilder.fromUriString(baseUrl + "/foo/../bar").build().toString(),
|
||||
equalTo(baseUrl + "/foo/../bar"));
|
||||
assertThat(UriComponentsBuilder.fromUriString(baseUrl + "/foo/../bar").build().toUriString(),
|
||||
equalTo(baseUrl + "/foo/../bar"));
|
||||
assertThat(UriComponentsBuilder.fromUriString(baseUrl + "/foo/../bar").build().toUri().getPath(),
|
||||
equalTo("/foo/../bar"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("../../").build().toString(),
|
||||
equalTo("../../"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("../../").build().toUriString(),
|
||||
equalTo("../../"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("../../").build().toUri().getPath(),
|
||||
equalTo("../../"));
|
||||
assertThat(UriComponentsBuilder.fromUriString(baseUrl).path("foo/../bar").build().toString(),
|
||||
equalTo(baseUrl + "/foo/../bar"));
|
||||
assertThat(UriComponentsBuilder.fromUriString(baseUrl).path("foo/../bar").build().toUriString(),
|
||||
equalTo(baseUrl + "/foo/../bar"));
|
||||
assertThat(UriComponentsBuilder.fromUriString(baseUrl).path("foo/../bar").build().toUri().getPath(),
|
||||
equalTo("/foo/../bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptySegments() throws Exception {
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com/abc/").path("/x/y/z").build().toString(), equalTo("http://example.com/abc/x/y/z"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com/abc/").pathSegment("x", "y", "z").build().toString(), equalTo("http://example.com/abc/x/y/z"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com/abc/").path("/x/").path("/y/z").build().toString(), equalTo("http://example.com/abc/x/y/z"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com/abc/").pathSegment("x").path("y").build().toString(), equalTo("http://example.com/abc/x/y"));
|
||||
String baseUrl = "http://example.com/abc/";
|
||||
assertThat(UriComponentsBuilder.fromUriString(baseUrl).path("/x/y/z").build().toString(),
|
||||
equalTo("http://example.com/abc/x/y/z"));
|
||||
assertThat(UriComponentsBuilder.fromUriString(baseUrl).pathSegment("x", "y", "z").build().toString(),
|
||||
equalTo("http://example.com/abc/x/y/z"));
|
||||
assertThat(UriComponentsBuilder.fromUriString(baseUrl).path("/x/").path("/y/z").build().toString(),
|
||||
equalTo("http://example.com/abc/x/y/z"));
|
||||
assertThat(UriComponentsBuilder.fromUriString(baseUrl).pathSegment("x").path("y").build().toString(),
|
||||
equalTo("http://example.com/abc/x/y"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -159,24 +159,26 @@ public class UriComponentsTests {
|
||||
|
||||
@Test
|
||||
public void equalsHierarchicalUriComponents() throws Exception {
|
||||
UriComponents uriComponents1 = UriComponentsBuilder.fromUriString("http://example.com").path("/{foo}").query("bar={baz}").build();
|
||||
UriComponents uriComponents2 = UriComponentsBuilder.fromUriString("http://example.com").path("/{foo}").query("bar={baz}").build();
|
||||
UriComponents uriComponents3 = UriComponentsBuilder.fromUriString("http://example.com").path("/{foo}").query("bin={baz}").build();
|
||||
assertThat(uriComponents1, instanceOf(HierarchicalUriComponents.class));
|
||||
assertThat(uriComponents1, equalTo(uriComponents1));
|
||||
assertThat(uriComponents1, equalTo(uriComponents2));
|
||||
assertThat(uriComponents1, not(equalTo(uriComponents3)));
|
||||
String url = "http://example.com";
|
||||
UriComponents uric1 = UriComponentsBuilder.fromUriString(url).path("/{foo}").query("bar={baz}").build();
|
||||
UriComponents uric2 = UriComponentsBuilder.fromUriString(url).path("/{foo}").query("bar={baz}").build();
|
||||
UriComponents uric3 = UriComponentsBuilder.fromUriString(url).path("/{foo}").query("bin={baz}").build();
|
||||
assertThat(uric1, instanceOf(HierarchicalUriComponents.class));
|
||||
assertThat(uric1, equalTo(uric1));
|
||||
assertThat(uric1, equalTo(uric2));
|
||||
assertThat(uric1, not(equalTo(uric3)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsOpaqueUriComponents() throws Exception {
|
||||
UriComponents uriComponents1 = UriComponentsBuilder.fromUriString("http:example.com/foo/bar").build();
|
||||
UriComponents uriComponents2 = UriComponentsBuilder.fromUriString("http:example.com/foo/bar").build();
|
||||
UriComponents uriComponents3 = UriComponentsBuilder.fromUriString("http:example.com/foo/bin").build();
|
||||
assertThat(uriComponents1, instanceOf(OpaqueUriComponents.class));
|
||||
assertThat(uriComponents1, equalTo(uriComponents1));
|
||||
assertThat(uriComponents1, equalTo(uriComponents2));
|
||||
assertThat(uriComponents1, not(equalTo(uriComponents3)));
|
||||
String baseUrl = "http:example.com";
|
||||
UriComponents uric1 = UriComponentsBuilder.fromUriString(baseUrl + "/foo/bar").build();
|
||||
UriComponents uric2 = UriComponentsBuilder.fromUriString(baseUrl + "/foo/bar").build();
|
||||
UriComponents uric3 = UriComponentsBuilder.fromUriString(baseUrl + "/foo/bin").build();
|
||||
assertThat(uric1, instanceOf(OpaqueUriComponents.class));
|
||||
assertThat(uric1, equalTo(uric1));
|
||||
assertThat(uric1, equalTo(uric2));
|
||||
assertThat(uric1, not(equalTo(uric3)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,10 @@ import org.springframework.http.server.ServletServerHttpRequest;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
@@ -126,10 +129,15 @@ public class WebUtilsTests {
|
||||
// Handling of IPv6 hosts as described in SPR-13525
|
||||
assertTrue(checkSameOrigin("[::1]", -1, "http://[::1]"));
|
||||
assertTrue(checkSameOrigin("[::1]", 8080, "http://[::1]:8080"));
|
||||
assertTrue(checkSameOrigin("[2001:0db8:0000:85a3:0000:0000:ac1f:8001]", -1, "http://[2001:0db8:0000:85a3:0000:0000:ac1f:8001]"));
|
||||
assertTrue(checkSameOrigin("[2001:0db8:0000:85a3:0000:0000:ac1f:8001]", 8080, "http://[2001:0db8:0000:85a3:0000:0000:ac1f:8001]:8080"));
|
||||
assertTrue(checkSameOrigin(
|
||||
"[2001:0db8:0000:85a3:0000:0000:ac1f:8001]", -1,
|
||||
"http://[2001:0db8:0000:85a3:0000:0000:ac1f:8001]"));
|
||||
assertTrue(checkSameOrigin(
|
||||
"[2001:0db8:0000:85a3:0000:0000:ac1f:8001]", 8080,
|
||||
"http://[2001:0db8:0000:85a3:0000:0000:ac1f:8001]:8080"));
|
||||
assertFalse(checkSameOrigin("[::1]", -1, "http://[::1]:8080"));
|
||||
assertFalse(checkSameOrigin("[::1]", 8080, "http://[2001:0db8:0000:85a3:0000:0000:ac1f:8001]:8080"));
|
||||
assertFalse(checkSameOrigin("[::1]", 8080,
|
||||
"http://[2001:0db8:0000:85a3:0000:0000:ac1f:8001]:8080"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Exercise the {@link PathPatternParser}.
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class PathPatternParserTests {
|
||||
@@ -62,7 +61,8 @@ public class PathPatternParserTests {
|
||||
public void multiwildcardPattern() {
|
||||
pathPattern = checkStructure("/**");
|
||||
assertPathElements(pathPattern, WildcardTheRestPathElement.class);
|
||||
pathPattern = checkStructure("/**acb"); // this is not double wildcard use, it is / then **acb (an odd, unnecessary use of double *)
|
||||
// this is not double wildcard, it's / then **acb (an odd, unnecessary use of double *)
|
||||
pathPattern = checkStructure("/**acb");
|
||||
assertPathElements(pathPattern, SeparatorPathElement.class, RegexPathElement.class);
|
||||
}
|
||||
|
||||
@@ -122,33 +122,40 @@ public class PathPatternParserTests {
|
||||
checkError("/{var:a{{1,2}}}", 6, PatternMessage.REGEX_PATTERN_SYNTAX_EXCEPTION);
|
||||
|
||||
pathPattern = checkStructure("/{var:\\\\}");
|
||||
assertEquals(CaptureVariablePathElement.class.getName(), pathPattern.getHeadSection().next.getClass().getName());
|
||||
PathElement next = pathPattern.getHeadSection().next;
|
||||
assertEquals(CaptureVariablePathElement.class.getName(), next.getClass().getName());
|
||||
assertMatches(pathPattern,"/\\");
|
||||
|
||||
pathPattern = checkStructure("/{var:\\/}");
|
||||
assertEquals(CaptureVariablePathElement.class.getName(), pathPattern.getHeadSection().next.getClass().getName());
|
||||
next = pathPattern.getHeadSection().next;
|
||||
assertEquals(CaptureVariablePathElement.class.getName(), next.getClass().getName());
|
||||
assertNoMatch(pathPattern,"/aaa");
|
||||
|
||||
pathPattern = checkStructure("/{var:a{1,2}}");
|
||||
assertEquals(CaptureVariablePathElement.class.getName(), pathPattern.getHeadSection().next.getClass().getName());
|
||||
next = pathPattern.getHeadSection().next;
|
||||
assertEquals(CaptureVariablePathElement.class.getName(), next.getClass().getName());
|
||||
|
||||
pathPattern = checkStructure("/{var:[^\\/]*}");
|
||||
assertEquals(CaptureVariablePathElement.class.getName(), pathPattern.getHeadSection().next.getClass().getName());
|
||||
next = pathPattern.getHeadSection().next;
|
||||
assertEquals(CaptureVariablePathElement.class.getName(), next.getClass().getName());
|
||||
PathPattern.PathMatchInfo result = matchAndExtract(pathPattern,"/foo");
|
||||
assertEquals("foo", result.getUriVariables().get("var"));
|
||||
|
||||
pathPattern = checkStructure("/{var:\\[*}");
|
||||
assertEquals(CaptureVariablePathElement.class.getName(), pathPattern.getHeadSection().next.getClass().getName());
|
||||
next = pathPattern.getHeadSection().next;
|
||||
assertEquals(CaptureVariablePathElement.class.getName(), next.getClass().getName());
|
||||
result = matchAndExtract(pathPattern,"/[[[");
|
||||
assertEquals("[[[", result.getUriVariables().get("var"));
|
||||
|
||||
pathPattern = checkStructure("/{var:[\\{]*}");
|
||||
assertEquals(CaptureVariablePathElement.class.getName(), pathPattern.getHeadSection().next.getClass().getName());
|
||||
next = pathPattern.getHeadSection().next;
|
||||
assertEquals(CaptureVariablePathElement.class.getName(), next.getClass().getName());
|
||||
result = matchAndExtract(pathPattern,"/{{{");
|
||||
assertEquals("{{{", result.getUriVariables().get("var"));
|
||||
|
||||
pathPattern = checkStructure("/{var:[\\}]*}");
|
||||
assertEquals(CaptureVariablePathElement.class.getName(), pathPattern.getHeadSection().next.getClass().getName());
|
||||
next = pathPattern.getHeadSection().next;
|
||||
assertEquals(CaptureVariablePathElement.class.getName(), next.getClass().getName());
|
||||
result = matchAndExtract(pathPattern,"/}}}");
|
||||
assertEquals("}}}", result.getUriVariables().get("var"));
|
||||
|
||||
@@ -159,7 +166,8 @@ public class PathPatternParserTests {
|
||||
checkStructure("*/");
|
||||
checkStructure("/*/");
|
||||
pathPattern = checkStructure("/*a*/");
|
||||
assertEquals(RegexPathElement.class.getName(), pathPattern.getHeadSection().next.getClass().getName());
|
||||
next = pathPattern.getHeadSection().next;
|
||||
assertEquals(RegexPathElement.class.getName(), next.getClass().getName());
|
||||
pathPattern = checkStructure("*/");
|
||||
assertEquals(WildcardPathElement.class.getName(), pathPattern.getHeadSection().getClass().getName());
|
||||
checkError("{foo}_{foo}", 0, PatternMessage.ILLEGAL_DOUBLE_CAPTURE, "foo");
|
||||
@@ -308,12 +316,12 @@ public class PathPatternParserTests {
|
||||
public void multipleSeparatorPatterns() {
|
||||
pathPattern = checkStructure("///aaa");
|
||||
assertEquals(6, pathPattern.getNormalizedLength());
|
||||
assertPathElements(pathPattern, SeparatorPathElement.class, SeparatorPathElement.class, SeparatorPathElement.class,
|
||||
LiteralPathElement.class);
|
||||
assertPathElements(pathPattern, SeparatorPathElement.class, SeparatorPathElement.class,
|
||||
SeparatorPathElement.class, LiteralPathElement.class);
|
||||
pathPattern = checkStructure("///aaa////aaa/b");
|
||||
assertEquals(15, pathPattern.getNormalizedLength());
|
||||
assertPathElements(pathPattern, SeparatorPathElement.class, SeparatorPathElement.class, SeparatorPathElement.class,
|
||||
LiteralPathElement.class, SeparatorPathElement.class,
|
||||
assertPathElements(pathPattern, SeparatorPathElement.class, SeparatorPathElement.class,
|
||||
SeparatorPathElement.class, LiteralPathElement.class, SeparatorPathElement.class,
|
||||
SeparatorPathElement.class, SeparatorPathElement.class, SeparatorPathElement.class,
|
||||
LiteralPathElement.class, SeparatorPathElement.class, LiteralPathElement.class);
|
||||
pathPattern = checkStructure("/////**");
|
||||
@@ -421,7 +429,9 @@ public class PathPatternParserTests {
|
||||
return pp;
|
||||
}
|
||||
|
||||
private void checkError(String pattern, int expectedPos, PatternMessage expectedMessage, String... expectedInserts) {
|
||||
private void checkError(String pattern, int expectedPos, PatternMessage expectedMessage,
|
||||
String... expectedInserts) {
|
||||
|
||||
try {
|
||||
pathPattern = parse(pattern);
|
||||
fail("Expected to fail");
|
||||
|
||||
@@ -329,13 +329,16 @@ public class PathPatternTests {
|
||||
// With a /** on the end have to check if there is any more data post
|
||||
// 'the match' it starts with a separator
|
||||
assertNull(parse("/resource/**").matchStartOfPath(toPathContainer("/resourceX")));
|
||||
assertEquals("",parse("/resource/**").matchStartOfPath(toPathContainer("/resource")).getPathRemaining().value());
|
||||
assertEquals("",parse("/resource/**")
|
||||
.matchStartOfPath(toPathContainer("/resource")).getPathRemaining().value());
|
||||
|
||||
// Similar to above for the capture-the-rest variant
|
||||
assertNull(parse("/resource/{*foo}").matchStartOfPath(toPathContainer("/resourceX")));
|
||||
assertEquals("",parse("/resource/{*foo}").matchStartOfPath(toPathContainer("/resource")).getPathRemaining().value());
|
||||
assertEquals("", parse("/resource/{*foo}")
|
||||
.matchStartOfPath(toPathContainer("/resource")).getPathRemaining().value());
|
||||
|
||||
PathPattern.PathRemainingMatchInfo pri = parse("/aaa/{bbb}/c?d/e*f/*/g").matchStartOfPath(toPathContainer("/aaa/b/ccd/ef/x/g/i"));
|
||||
PathPattern.PathRemainingMatchInfo pri = parse("/aaa/{bbb}/c?d/e*f/*/g")
|
||||
.matchStartOfPath(toPathContainer("/aaa/b/ccd/ef/x/g/i"));
|
||||
assertNotNull(pri);
|
||||
assertEquals("/i",pri.getPathRemaining().value());
|
||||
assertEquals("b",pri.getUriVariables().get("bbb"));
|
||||
@@ -397,7 +400,8 @@ public class PathPatternTests {
|
||||
@Test
|
||||
public void multipleSeparatorsInPattern() {
|
||||
PathPattern pp = parse("a//b//c");
|
||||
assertEquals("Literal(a) Separator(/) Separator(/) Literal(b) Separator(/) Separator(/) Literal(c)",pp.toChainString());
|
||||
assertEquals("Literal(a) Separator(/) Separator(/) Literal(b) Separator(/) Separator(/) Literal(c)",
|
||||
pp.toChainString());
|
||||
assertMatches(pp,"a//b//c");
|
||||
assertEquals("Literal(a) Separator(/) WildcardTheRest(/**)",parse("a//**").toChainString());
|
||||
checkMatches("///abc", "///abc");
|
||||
@@ -812,7 +816,8 @@ public class PathPatternTests {
|
||||
assertEquals("com.example", result.getUriVariables().get("symbolicName"));
|
||||
assertEquals("1.0.0", result.getUriVariables().get("version"));
|
||||
|
||||
p = pp.parse("{symbolicName:[\\w\\.]+}-sources-{version:[\\d\\.]+}-{year:\\d{4}}{month:\\d{2}}{day:\\d{2}}.jar");
|
||||
p = pp.parse("{symbolicName:[\\w\\.]+}-sources-" +
|
||||
"{version:[\\d\\.]+}-{year:\\d{4}}{month:\\d{2}}{day:\\d{2}}.jar");
|
||||
result = matchAndExtract(p,"com.example-sources-1.0.0-20100220.jar");
|
||||
assertEquals("com.example", result.getUriVariables().get("symbolicName"));
|
||||
assertEquals("1.0.0", result.getUriVariables().get("version"));
|
||||
|
||||
Reference in New Issue
Block a user