"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "spring-web/src/test/java/org/springframework/http/codec/support/ServerCodecConfigurerTests.java" between
spring-framework-5.3.7.tar.gz and spring-framework-5.3.8.tar.gz

About: Spring Framework is an application framework for the Java platform and .NET Framework. Community edition.

ServerCodecConfigurerTests.java  (spring-framework-5.3.7):ServerCodecConfigurerTests.java  (spring-framework-5.3.8)
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
skipping to change at line 127 skipping to change at line 127
assertThat(getNextEncoder(writers).getClass()).isEqualTo(KotlinSe rializationJsonEncoder.class); assertThat(getNextEncoder(writers).getClass()).isEqualTo(KotlinSe rializationJsonEncoder.class);
assertThat(getNextEncoder(writers).getClass()).isEqualTo(Jackson2 JsonEncoder.class); assertThat(getNextEncoder(writers).getClass()).isEqualTo(Jackson2 JsonEncoder.class);
assertThat(getNextEncoder(writers).getClass()).isEqualTo(Jackson2 SmileEncoder.class); assertThat(getNextEncoder(writers).getClass()).isEqualTo(Jackson2 SmileEncoder.class);
assertThat(getNextEncoder(writers).getClass()).isEqualTo(Jaxb2Xml Encoder.class); assertThat(getNextEncoder(writers).getClass()).isEqualTo(Jaxb2Xml Encoder.class);
assertSseWriter(writers); assertSseWriter(writers);
assertStringEncoder(getNextEncoder(writers), false); assertStringEncoder(getNextEncoder(writers), false);
} }
@Test @Test
public void jackson2EncoderOverride() { public void jackson2EncoderOverride() {
Jackson2JsonDecoder decoder = new Jackson2JsonDecoder();
Jackson2JsonEncoder encoder = new Jackson2JsonEncoder(); Jackson2JsonEncoder encoder = new Jackson2JsonEncoder();
this.configurer.defaultCodecs().jackson2JsonDecoder(decoder);
this.configurer.defaultCodecs().jackson2JsonEncoder(encoder); this.configurer.defaultCodecs().jackson2JsonEncoder(encoder);
assertThat(this.configurer.getWriters().stream() List<HttpMessageReader<?>> readers = this.configurer.getReaders()
.filter(writer -> ServerSentEventHttpMessageWrite ;
r.class.equals(writer.getClass())) Jackson2JsonDecoder actualDecoder = findCodec(readers, Jackson2Js
.map(writer -> (ServerSentEventHttpMessageWriter) onDecoder.class);
writer) assertThat(actualDecoder).isSameAs(decoder);
.findFirst()
.map(ServerSentEventHttpMessageWriter::getEncoder List<HttpMessageWriter<?>> writers = this.configurer.getWriters()
) ;
.filter(e -> e == encoder).orElse(null)).isSameAs Jackson2JsonEncoder actualEncoder = findCodec(writers, Jackson2Js
(encoder); onEncoder.class);
assertThat(actualEncoder).isSameAs(encoder);
assertThat(findCodec(writers, ServerSentEventHttpMessageWriter.cl
ass).getEncoder()).isSameAs(encoder);
} }
@Test @Test
public void maxInMemorySize() { public void maxInMemorySize() {
int size = 99; int size = 99;
this.configurer.defaultCodecs().maxInMemorySize(size); this.configurer.defaultCodecs().maxInMemorySize(size);
List<HttpMessageReader<?>> readers = this.configurer.getReaders() ; List<HttpMessageReader<?>> readers = this.configurer.getReaders() ;
assertThat(((ByteArrayDecoder) getNextDecoder(readers)).getMaxInM emorySize()).isEqualTo(size); assertThat(((ByteArrayDecoder) getNextDecoder(readers)).getMaxInM emorySize()).isEqualTo(size);
assertThat(((ByteBufferDecoder) getNextDecoder(readers)).getMaxIn MemorySize()).isEqualTo(size); assertThat(((ByteBufferDecoder) getNextDecoder(readers)).getMaxIn MemorySize()).isEqualTo(size);
skipping to change at line 263 skipping to change at line 267
} }
private Encoder<?> getNextEncoder(List<HttpMessageWriter<?>> writers) { private Encoder<?> getNextEncoder(List<HttpMessageWriter<?>> writers) {
HttpMessageWriter<?> writer = writers.get(this.index.getAndIncrem ent()); HttpMessageWriter<?> writer = writers.get(this.index.getAndIncrem ent());
assertThat(writer.getClass()).isEqualTo(EncoderHttpMessageWriter. class); assertThat(writer.getClass()).isEqualTo(EncoderHttpMessageWriter. class);
return ((EncoderHttpMessageWriter<?>) writer).getEncoder(); return ((EncoderHttpMessageWriter<?>) writer).getEncoder();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T> T findCodec(List<?> codecs, Class<T> type) { private <T> T findCodec(List<?> codecs, Class<T> type) {
return (T) codecs.stream().filter(type::isInstance).findFirst().g return (T) codecs.stream()
et(); .map(c -> {
if (c instanceof EncoderHttpMessageWriter
) {
return ((EncoderHttpMessageWriter
<?>) c).getEncoder();
}
else if (c instanceof DecoderHttpMessageR
eader) {
return ((DecoderHttpMessageReader
<?>) c).getDecoder();
}
else {
return c;
}
})
.filter(type::isInstance).findFirst().get();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void assertStringDecoder(Decoder<?> decoder, boolean textOnly) { private void assertStringDecoder(Decoder<?> decoder, boolean textOnly) {
assertThat(decoder.getClass()).isEqualTo(StringDecoder.class); assertThat(decoder.getClass()).isEqualTo(StringDecoder.class);
assertThat(decoder.canDecode(forClass(String.class), MimeTypeUtil s.TEXT_PLAIN)).isTrue(); assertThat(decoder.canDecode(forClass(String.class), MimeTypeUtil s.TEXT_PLAIN)).isTrue();
Object expected = !textOnly; Object expected = !textOnly;
assertThat(decoder.canDecode(forClass(String.class), MediaType.TE XT_EVENT_STREAM)).isEqualTo(expected); assertThat(decoder.canDecode(forClass(String.class), MediaType.TE XT_EVENT_STREAM)).isEqualTo(expected);
byte[] bytes = "line1\nline2".getBytes(StandardCharsets.UTF_8); byte[] bytes = "line1\nline2".getBytes(StandardCharsets.UTF_8);
 End of changes. 5 change blocks. 
13 lines changed or deleted 33 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)