GH-1707 Initial removal of 2.0.0 deprecated classes and methods
This commit is contained in:
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.stream.config;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
import org.springframework.cloud.stream.binder.BinderFactory;
|
||||
import org.springframework.cloud.stream.messaging.Processor;
|
||||
import org.springframework.cloud.stream.test.binder.TestSupportBinder;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.tuple.Tuple;
|
||||
import org.springframework.tuple.TupleBuilder;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Marius Bogoevici
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = InboundJsonToTupleConversionTest.FooProcessor.class)
|
||||
public class InboundJsonToTupleConversionTest {
|
||||
|
||||
@Autowired
|
||||
private Processor testProcessor;
|
||||
|
||||
@Autowired
|
||||
private BinderFactory binderFactory;
|
||||
|
||||
@Test
|
||||
public void testInboundJsonTupleConversion() throws Exception {
|
||||
this.testProcessor.input()
|
||||
.send(MessageBuilder.withPayload("{'name':'foo'}").build());
|
||||
@SuppressWarnings("unchecked")
|
||||
Message<byte[]> received = (Message<byte[]>) ((TestSupportBinder) this.binderFactory
|
||||
.getBinder(null, MessageChannel.class)).messageCollector()
|
||||
.forChannel(this.testProcessor.output())
|
||||
.poll(1, TimeUnit.SECONDS);
|
||||
assertThat(received).isNotNull();
|
||||
String payload = new String(received.getPayload(), StandardCharsets.UTF_8);
|
||||
assertThat(TupleBuilder.fromString(payload))
|
||||
.isEqualTo(TupleBuilder.tuple().of("name", "foo"));
|
||||
}
|
||||
|
||||
@EnableBinding(Processor.class)
|
||||
@EnableAutoConfiguration
|
||||
@PropertySource("classpath:/org/springframework/cloud/stream/config/inboundjsontuple/inbound-json-tuple.properties")
|
||||
public static class FooProcessor {
|
||||
|
||||
@ServiceActivator(inputChannel = "input", outputChannel = "output")
|
||||
public Tuple consume(Tuple tuple) {
|
||||
return tuple;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,18 +19,14 @@ package org.springframework.cloud.stream.config;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
import org.springframework.cloud.stream.binder.BinderHeaders;
|
||||
import org.springframework.cloud.stream.converter.CompositeMessageConverterFactory;
|
||||
import org.springframework.cloud.stream.messaging.DirectWithAttributesChannel;
|
||||
import org.springframework.cloud.stream.messaging.Sink;
|
||||
import org.springframework.cloud.stream.messaging.Source;
|
||||
@@ -39,10 +35,7 @@ import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.converter.CompositeMessageConverter;
|
||||
import org.springframework.messaging.converter.MessageConverter;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -63,9 +56,6 @@ public class MessageChannelConfigurerTests {
|
||||
@Autowired
|
||||
private Source testSource;
|
||||
|
||||
@Autowired
|
||||
private CompositeMessageConverterFactory messageConverterFactory;
|
||||
|
||||
@Autowired
|
||||
private MessageCollector messageCollector;
|
||||
|
||||
@@ -94,23 +84,6 @@ public class MessageChannelConfigurerTests {
|
||||
this.testSink.input().unsubscribe(messageHandler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectMapperConfig() throws Exception {
|
||||
CompositeMessageConverter converters = (CompositeMessageConverter) this.messageConverterFactory
|
||||
.getMessageConverterForType(MimeTypeUtils.APPLICATION_JSON);
|
||||
for (MessageConverter converter : converters.getConverters()) {
|
||||
DirectFieldAccessor converterAccessor = new DirectFieldAccessor(converter);
|
||||
ObjectMapper objectMapper = (ObjectMapper) converterAccessor
|
||||
.getPropertyValue("objectMapper");
|
||||
// assert that the ObjectMapper used by the converters is compliant with the
|
||||
// Boot configuration
|
||||
assertThat(!objectMapper.getSerializationConfig().isEnabled(
|
||||
SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)).withFailMessage(
|
||||
"SerializationFeature 'WRITE_DATES_AS_TIMESTAMPS' should be disabled");
|
||||
// assert that the globally set bean is used by the converters
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartitionHeader() throws Exception {
|
||||
this.testSource.output()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2018 the original author or authors.
|
||||
* Copyright 2017-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,16 +16,11 @@
|
||||
|
||||
package org.springframework.cloud.stream.config.contentType;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.esotericsoftware.kryo.Kryo;
|
||||
import com.esotericsoftware.kryo.io.Output;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -33,8 +28,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
import org.springframework.cloud.stream.annotation.Input;
|
||||
import org.springframework.cloud.stream.annotation.StreamListener;
|
||||
import org.springframework.cloud.stream.converter.KryoMessageConverter;
|
||||
import org.springframework.cloud.stream.converter.MessageConverterUtils;
|
||||
import org.springframework.cloud.stream.messaging.Source;
|
||||
import org.springframework.cloud.stream.test.binder.MessageCollector;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
@@ -43,8 +36,6 @@ import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.SubscribableChannel;
|
||||
import org.springframework.messaging.handler.annotation.Headers;
|
||||
import org.springframework.tuple.Tuple;
|
||||
import org.springframework.tuple.TupleBuilder;
|
||||
import org.springframework.util.MimeType;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
@@ -173,45 +164,6 @@ public class ContentTypeTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendJavaSerializable() throws Exception {
|
||||
try (ConfigurableApplicationContext context = SpringApplication.run(
|
||||
SourceApplication.class, "--server.port=0", "--spring.jmx.enabled=false",
|
||||
"--spring.cloud.stream.bindings.output.contentType=application/x-java-serialized-object")) {
|
||||
MessageCollector collector = context.getBean(MessageCollector.class);
|
||||
Source source = context.getBean(Source.class);
|
||||
User user = new User("Alice");
|
||||
source.output().send(MessageBuilder.withPayload(user).build());
|
||||
Message<User> message = (Message<User>) collector.forChannel(source.output())
|
||||
.poll(1, TimeUnit.SECONDS);
|
||||
assertThat(
|
||||
message.getHeaders().get(MessageHeaders.CONTENT_TYPE, MimeType.class)
|
||||
.includes(MessageConverterUtils.X_JAVA_SERIALIZED_OBJECT));
|
||||
User received = message.getPayload();
|
||||
assertThat(user.getName()).isEqualTo(received.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendKryoSerialized() throws Exception {
|
||||
try (ConfigurableApplicationContext context = SpringApplication.run(
|
||||
SourceApplication.class, "--server.port=0", "--spring.jmx.enabled=false",
|
||||
"--spring.cloud.stream.bindings.output.contentType=application/x-java-object")) {
|
||||
MessageCollector collector = context.getBean(MessageCollector.class);
|
||||
Source source = context.getBean(Source.class);
|
||||
User user = new User("Alice");
|
||||
source.output().send(MessageBuilder.withPayload(user).build());
|
||||
Message<User> message = (Message<User>) collector.forChannel(source.output())
|
||||
.poll(1, TimeUnit.SECONDS);
|
||||
User received = message.getPayload();
|
||||
assertThat(message.getHeaders()
|
||||
.get(MessageHeaders.CONTENT_TYPE, MimeType.class)
|
||||
.includes(MimeType.valueOf(KryoMessageConverter.KRYO_MIME_TYPE)));
|
||||
assertThat(user.getName()).isEqualTo(received.getName());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendStringType() throws Exception {
|
||||
try (ConfigurableApplicationContext context = SpringApplication.run(
|
||||
@@ -230,25 +182,6 @@ public class ContentTypeTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendTuple() throws Exception {
|
||||
try (ConfigurableApplicationContext context = SpringApplication.run(
|
||||
SourceApplication.class, "--server.port=0", "--spring.jmx.enabled=false",
|
||||
"--spring.cloud.stream.bindings.output.contentType=application/x-spring-tuple")) {
|
||||
MessageCollector collector = context.getBean(MessageCollector.class);
|
||||
Source source = context.getBean(Source.class);
|
||||
Tuple tuple = TupleBuilder.tuple().of("foo", "bar");
|
||||
source.output().send(MessageBuilder.withPayload(tuple).build());
|
||||
Message<byte[]> message = (Message<byte[]>) collector
|
||||
.forChannel(source.output()).poll(1, TimeUnit.SECONDS);
|
||||
assertThat(
|
||||
message.getHeaders().get(MessageHeaders.CONTENT_TYPE, MimeType.class)
|
||||
.includes(MessageConverterUtils.X_SPRING_TUPLE));
|
||||
assertThat(TupleBuilder.fromString(new String(message.getPayload())))
|
||||
.isEqualTo(tuple);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceiveWithDefaults() throws Exception {
|
||||
try (ConfigurableApplicationContext context = SpringApplication.run(
|
||||
@@ -289,78 +222,6 @@ public class ContentTypeTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testReceiveKryoPayload() {
|
||||
try (ConfigurableApplicationContext context = SpringApplication.run(
|
||||
SinkApplication.class, "--server.port=0", "--debug",
|
||||
"--spring.jmx.enabled=false",
|
||||
"--spring.cloud.stream.bindings.pojo_input.contentType="
|
||||
+ "application/x-java-object;type=org.springframework.cloud.stream.config.contentType.User")) {
|
||||
TestSink testSink = context.getBean(TestSink.class);
|
||||
SinkApplication sourceApp = context.getBean(SinkApplication.class);
|
||||
Kryo kryo = new Kryo();
|
||||
User user = new User("Alice");
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
Output output = new Output(baos);
|
||||
kryo.writeObject(output, user);
|
||||
output.close();
|
||||
testSink.pojo().send(MessageBuilder.withPayload(baos.toByteArray()).build());
|
||||
Map<String, Object> headers = (Map<String, Object>) sourceApp.arguments.pop();
|
||||
User received = (User) sourceApp.arguments.pop();
|
||||
assertThat(((MimeType) headers.get(MessageHeaders.CONTENT_TYPE))
|
||||
.includes(MimeType.valueOf(KryoMessageConverter.KRYO_MIME_TYPE)));
|
||||
assertThat(user.getName()).isEqualTo(received.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testReceiveKryoWithHeadersOverridingDefault() {
|
||||
try (ConfigurableApplicationContext context = SpringApplication.run(
|
||||
SinkApplication.class, "--server.port=0", "--spring.jmx.enabled=false")) {
|
||||
TestSink testSink = context.getBean(TestSink.class);
|
||||
SinkApplication sourceApp = context.getBean(SinkApplication.class);
|
||||
Kryo kryo = new Kryo();
|
||||
User user = new User("Alice");
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
Output output = new Output(baos);
|
||||
kryo.writeObject(output, user);
|
||||
output.close();
|
||||
testSink.pojo()
|
||||
.send(MessageBuilder.withPayload(baos.toByteArray())
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE,
|
||||
MimeType.valueOf(KryoMessageConverter.KRYO_MIME_TYPE))
|
||||
.build());
|
||||
Map<String, Object> headers = (Map<String, Object>) sourceApp.arguments.pop();
|
||||
User received = (User) sourceApp.arguments.pop();
|
||||
assertThat(((MimeType) headers.get(MessageHeaders.CONTENT_TYPE))
|
||||
.includes(MimeType.valueOf(KryoMessageConverter.KRYO_MIME_TYPE)));
|
||||
assertThat(user.getName()).isEqualTo(received.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testReceiveJavaSerializable() throws Exception {
|
||||
try (ConfigurableApplicationContext context = SpringApplication.run(
|
||||
SinkApplication.class, "--server.port=0", "--spring.jmx.enabled=false",
|
||||
"--spring.cloud.stream.bindings.pojo_input.contentType=application/x-java-serialized-object")) {
|
||||
TestSink testSink = context.getBean(TestSink.class);
|
||||
SinkApplication sourceApp = context.getBean(SinkApplication.class);
|
||||
User user = new User("Alice");
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
new ObjectOutputStream(baos).writeObject(user);
|
||||
testSink.pojo().send(MessageBuilder.withPayload(baos.toByteArray()).build());
|
||||
Map<String, Object> headers = (Map<String, Object>) sourceApp.arguments.pop();
|
||||
User received = (User) sourceApp.arguments.pop();
|
||||
assertThat(((MimeType) headers.get(MessageHeaders.CONTENT_TYPE))
|
||||
.includes(MessageConverterUtils.X_JAVA_SERIALIZED_OBJECT));
|
||||
assertThat(user.getName()).isEqualTo(received.getName());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public interface TestSink {
|
||||
|
||||
@Input("POJO_INPUT")
|
||||
@@ -395,10 +256,6 @@ public class ContentTypeTests {
|
||||
this.arguments.push(headers);
|
||||
}
|
||||
|
||||
@StreamListener("TUPLE_INPUT")
|
||||
public void receive(Tuple tuple) {
|
||||
}
|
||||
|
||||
@StreamListener("STRING_INPUT")
|
||||
public void receive(String string) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user