Move spring-cloud-stream tuple

- The `spring-cloud-stream-tuple` is now split into `spring-tuple`, `spring-integration-tuple` along with `spring-batch-tuple`
  - Update dependencies to use the new ones

This resolves #326
This commit is contained in:
Ilayaperumal Gopinathan
2016-02-26 00:32:57 +05:30
committed by Marius Bogoevici
parent 995e268da5
commit 69e484163c
47 changed files with 32 additions and 4048 deletions

View File

@@ -36,7 +36,6 @@
<module>spring-cloud-stream</module>
<module>spring-cloud-stream-binders</module>
<module>spring-cloud-stream-codec</module>
<module>spring-cloud-stream-tuple</module>
<module>spring-cloud-stream-starters</module>
<module>spring-cloud-stream-rxjava</module>
<module>spring-cloud-stream-test-support</module>

View File

@@ -21,7 +21,6 @@ import java.util.List;
import org.springframework.cloud.stream.binder.AbstractTestBinder;
import org.springframework.cloud.stream.test.junit.kafka.KafkaTestSupport;
import org.springframework.cloud.stream.test.junit.kafka.TestKafkaCluster;
import org.springframework.cloud.stream.tuple.integration.TupleKryoRegistrar;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.integration.codec.Codec;
import org.springframework.integration.codec.kryo.KryoRegistrar;
@@ -29,6 +28,7 @@ import org.springframework.integration.codec.kryo.PojoCodec;
import org.springframework.integration.kafka.support.LoggingProducerListener;
import org.springframework.integration.kafka.support.ProducerListener;
import org.springframework.integration.kafka.support.ZookeeperConnect;
import org.springframework.integration.tuple.TupleKryoRegistrar;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Registration;

View File

@@ -31,9 +31,9 @@ import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cloud.stream.tuple.Tuple;
import org.springframework.cloud.stream.tuple.TupleBuilder;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.tuple.Tuple;
import org.springframework.tuple.TupleBuilder;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

View File

@@ -29,18 +29,18 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.cloud.stream.binder.AbstractBinder.JavaClassMimeTypeConversion;
import org.springframework.cloud.stream.tuple.DefaultTuple;
import org.springframework.cloud.stream.tuple.Tuple;
import org.springframework.cloud.stream.tuple.TupleBuilder;
import org.springframework.cloud.stream.tuple.integration.TupleKryoRegistrar;
import org.springframework.integration.codec.kryo.KryoRegistrar;
import org.springframework.integration.codec.kryo.PojoCodec;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.tuple.TupleKryoRegistrar;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.converter.ContentTypeResolver;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.tuple.DefaultTuple;
import org.springframework.tuple.Tuple;
import org.springframework.tuple.TupleBuilder;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;

View File

@@ -15,6 +15,8 @@
<properties>
<rxjava.version>1.0.14</rxjava.version>
<spring-integration.version>4.2.4.RELEASE</spring-integration.version>
<spring.tuple.version>1.0.0.BUILD-SNAPSHOT</spring.tuple.version>
<spring.integration.tuple.version>1.0.0.BUILD-SNAPSHOT</spring.integration.tuple.version>
</properties>
<dependencyManagement>
<dependencies>
@@ -74,9 +76,14 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-tuple</artifactId>
<version>${project.version}</version>
<groupId>org.springframework</groupId>
<artifactId>spring-tuple</artifactId>
<version>${spring.tuple.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-tuple</artifactId>
<version>${spring.integration.tuple.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>

View File

@@ -37,7 +37,6 @@ import org.springframework.cloud.stream.binder.redis.config.RedisMessageChannelB
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.cloud.stream.test.junit.redis.RedisTestSupport;
import org.springframework.cloud.stream.tuple.Tuple;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.integration.support.MessageBuilder;
@@ -45,6 +44,7 @@ import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessagingException;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.tuple.Tuple;
/**
* @author Ilayaperumal Gopinathan

View File

@@ -1,47 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-cloud-stream-tuple</artifactId>
<packaging>jar</packaging>
<name>spring-cloud-stream-tuple</name>
<description>Spring Cloud Stream Tuple</description>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-parent</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo-shaded</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -1,63 +0,0 @@
/*
* Copyright 2016 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
*
* http://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.tuple;
import java.util.List;
import org.springframework.core.convert.support.ConfigurableConversionService;
/**
* Extension of {@link DefaultTuple} that also allows tuple {@link MutableTuple mutation}.
*
* <p>Note that this implementation is not threadsafe.</p>
*
* @author Eric Bottard
*/
public class DefaultMutableTuple extends DefaultTuple implements MutableTuple {
/**
* Construct a new DefaultMutableTuple, given a list of names and object values along
* with a conversion service.
* @param names The list of String names to associate with the list of Object values
* @param values The list of Object values to associate with the list of String names
* @param configurableConversionService A conversion service instance that can Converting strings to Java types.
*/
public DefaultMutableTuple(List<String> names, List<Object> values, ConfigurableConversionService configurableConversionService) {
super(names, values, configurableConversionService);
}
@Override
public void setValue(int index, Object value) {
if (index < 0 || index >= size()) {
throw new IndexOutOfBoundsException();
}
values.set(index, value);
}
@Override
public void setValue(String name, Object value) {
int index = indexOf(name);
if (index != -1) {
setValue(index, value);
} else {
names.add(name);
values.add(value);
}
}
}

View File

@@ -1,628 +0,0 @@
/*
* Copyright 2013-2016 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
*
* http://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.tuple;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.support.ConfigurableConversionService;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
/**
* Default implementation of Tuple interface.
*
* @author Mark Pollack
* @author David Turanski
* @author Michael Minella
*/
public class DefaultTuple implements Tuple {
protected List<String> names;
protected List<Object> values;
protected transient ConfigurableConversionService configurableConversionService;
protected transient Converter<Tuple, String> tupleToStringConverter = new TupleToJsonStringConverter();
/**
* Construct a new DefaultMutableTuple, given a list of names and object values along
* with a conversion service.
*
* @param names The list of names to associate with the list of values
* @param values The list of values to associate with the list of names
* @param configurableConversionService A conversion service instance that can Converting strings to Java types.
*/
public DefaultTuple(List<String> names, List<Object> values, ConfigurableConversionService
configurableConversionService) {
Assert.notNull(names);
Assert.notNull(values);
Assert.notNull(configurableConversionService);
if (values.size() != names.size()) {
throw new IllegalArgumentException("Field names must be same length as values: names=" + names
+ ", values=" + values);
}
this.names = new ArrayList<>(names);
this.values = new ArrayList<>(values); // shallow copy
this.configurableConversionService = configurableConversionService;
}
/*
* (non-Javadoc)
*
* @see org.springframework.cloud.stream.tuple.Tuple#size()
*/
@Override
public int size() {
return values.size();
}
/**
* Return the values for all the fields in this tuple
* @return an unmodifiable List of names.
*/
@Override
public List<String> getFieldNames() {
return Collections.unmodifiableList(names);
}
/**
* Return the values for all the fields in this tuple
* @return an unmodifiable List list of values.
*/
@Override
public List<Object> getValues() {
return Collections.unmodifiableList(values);
}
@Override
public int getFieldCount() {
return this.names.size();
}
/*
* (non-Javadoc)
*
* @see org.springframework.cloud.stream.tuple.Tuple#hasName(java.lang.String)
*/
@Override
public boolean hasFieldName(String name) {
return names.contains(name);
}
/*
* (non-Javadoc)
*
* @see org.springframework.cloud.stream.tuple.Tuple#getValue(java.lang.String)
*/
@Override
public Object getValue(String name) {
int index = indexOf(name);
if (index == -1) {
throw new IllegalArgumentException("Field name [" + name + "] does not exist");
}
return getValue(index);
}
/*
* (non-Javadoc)
*
* @see org.springframework.cloud.stream.tuple.Tuple#getValue(int)
*/
@Override
public Object getValue(int index) {
return values.get(index);
}
@SuppressWarnings("rawtypes")
@Override
public List<Class> getFieldTypes() {
ArrayList<Class> types = new ArrayList<>(values.size());
for (Object val : values) {
types.add(val.getClass());
}
return Collections.unmodifiableList(types);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((names == null) ? 0 : names.hashCode());
result = prime * result + ((values == null) ? 0 : values.hashCode());
return result;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof DefaultTuple)) {
return false;
}
DefaultTuple other = (DefaultTuple) obj;
if (names == null) {
if (other.names != null) {
return false;
}
}
else if (!names.equals(other.names)) {
return false;
}
if (values == null) {
if (other.values != null) {
return false;
}
}
else if (!values.equals(other.values)) {
return false;
}
return true;
}
@Override
public String getString(String name) {
int index = indexOf(name);
return (index == -1) ? null : getString(index);
}
@Override
public String getString(int index) {
return readAndTrim(index);
}
@Override
public Tuple getTuple(int index) {
return convert(values.get(index), Tuple.class);
}
@Override
public Tuple getTuple(String name) {
return getTuple(indexOf(name));
}
/**
* @param index the index of the value
* @return the converted raw value, trimmed
*/
private String readAndTrim(int index) {
Object rawValue = values.get(index);
if (rawValue != null) {
String value = convert(rawValue, String.class);
if (value != null) {
return value.trim();
}
else {
return null;
}
}
else {
return null;
}
}
@Override
public String getRawString(String name) {
int index = indexOf(name);
return (index == -1) ? null : getRawString(index);
}
@Override
public String getRawString(int index) {
Object rawValue = values.get(index);
if (rawValue != null) {
String value = convert(rawValue, String.class);
if (value != null) {
return value;
}
else {
return null;
}
}
else {
return null;
}
}
@Override
public char getChar(int index) {
String value = readAndTrim(index);
if (value != null) {
Assert.isTrue(value.length() == 1, "Cannot convert field value '" + value + "' to char.");
return value.charAt(0);
}
return '\u0000';
}
@Override
public char getChar(String name) {
return getChar(indexOf(name));
}
@Override
public boolean getBoolean(int index) {
return getBoolean(index, "true");
}
@Override
public boolean getBoolean(String name) {
return getBoolean(indexOf(name));
}
@Override
public boolean getBoolean(int index, String trueValue) {
Assert.notNull(trueValue, "'trueValue' cannot be null.");
String value = readAndTrim(index);
return trueValue.equals(value);
}
@Override
public boolean getBoolean(String name, String trueValue) {
return getBoolean(indexOf(name), trueValue);
}
@Override
public byte getByte(String name) {
int index = indexOf(name);
return (index == -1) ? 0 : getByte(index);
}
@Override
public byte getByte(int index) {
Byte b = convert(values.get(index), Byte.class);
return (b != null) ? b : 0;
}
@Override
public byte getByte(String name, byte defaultValue) {
int index = indexOf(name);
return (index == -1) ? defaultValue : getByte(index, defaultValue);
}
@Override
public byte getByte(int index, byte defaultValue) {
Byte b = convert(values.get(index), Byte.class);
return (b != null) ? b : defaultValue;
}
@Override
public short getShort(String name) {
int index = indexOf(name);
return (index == -1) ? 0 : getShort(index);
}
@Override
public short getShort(int index) {
Short s = convert(values.get(index), Short.class);
return (s != null) ? s : 0;
}
@Override
public short getShort(String name, short defaultValue) {
int index = indexOf(name);
return (index == -1) ? defaultValue : getShort(index, defaultValue);
}
@Override
public short getShort(int index, short defaultValue) {
Short s = convert(values.get(index), Short.class);
return (s != null) ? s : defaultValue;
}
@Override
public int getInt(String name) {
int index = indexOf(name);
return (index == -1) ? 0 : getInt(index);
}
@Override
public int getInt(int index) {
Integer i = convert(values.get(index), Integer.class);
return (i != null) ? i : 0;
}
@Override
public int getInt(String name, int defaultValue) {
int index = indexOf(name);
return (index == -1) ? defaultValue : getInt(index, defaultValue);
}
@Override
public int getInt(int index, int defaultValue) {
Integer i = convert(values.get(index), Integer.class);
return (i != null) ? i : defaultValue;
}
@Override
public long getLong(String name) {
int index = indexOf(name);
return (index == -1) ? 0 : getLong(index);
}
@Override
public long getLong(int index) {
Long l = convert(values.get(index), Long.class);
return (l != null) ? l : 0;
}
@Override
public long getLong(String name, long defaultValue) {
int index = indexOf(name);
return (index == -1) ? defaultValue : getLong(index, defaultValue);
}
@Override
public long getLong(int index, long defaultValue) {
Long l = convert(values.get(index), Long.class);
return (l != null) ? l : defaultValue;
}
@Override
public float getFloat(String name) {
int index = indexOf(name);
return (index == -1) ? 0 : getFloat(index);
}
@Override
public float getFloat(int index) {
Float f = convert(values.get(index), Float.class);
return (f != null) ? f : 0;
}
@Override
public float getFloat(String name, float defaultValue) {
int index = indexOf(name);
return (index == -1) ? defaultValue : getFloat(index, defaultValue);
}
@Override
public float getFloat(int index, float defaultValue) {
Float f = convert(values.get(index), Float.class);
return (f != null) ? f : defaultValue;
}
@Override
public double getDouble(String name) {
int index = indexOf(name);
return (index == -1) ? 0 : getDouble(index);
}
@Override
public double getDouble(int index) {
Double d = convert(values.get(index), Double.class);
return (d != null) ? d : 0;
}
@Override
public double getDouble(String name, double defaultValue) {
int index = indexOf(name);
return (index == -1) ? defaultValue : getDouble(index, defaultValue);
}
@Override
public double getDouble(int index, double defaultValue) {
Double d = convert(values.get(index), Double.class);
return (d != null) ? d : defaultValue;
}
@Override
public BigDecimal getBigDecimal(String name) {
return getBigDecimal(indexOf(name));
}
@Override
public BigDecimal getBigDecimal(int index) {
return convert(values.get(index), BigDecimal.class);
}
@Override
public BigDecimal getBigDecimal(String name, BigDecimal defaultValue) {
int index = indexOf(name);
return (index == -1) ? defaultValue : getBigDecimal(index, defaultValue);
}
@Override
public BigDecimal getBigDecimal(int index, BigDecimal defaultValue) {
BigDecimal bd = convert(values.get(index), BigDecimal.class);
return (bd != null) ? bd : defaultValue;
}
@Override
public Date getDate(int index) {
return convert(values.get(index), Date.class);
}
@Override
public Date getDate(String name) {
return getDate(indexOf(name));
}
@Override
public Date getDate(String name, Date defaultValue) {
int index = indexOf(name);
return (index == -1) ? defaultValue : getDate(index, defaultValue);
}
@Override
public Date getDate(int index, Date defaultValue) {
Date d = getDate(index);
return (d != null) ? d : defaultValue;
}
@Override
public Date getDateWithPattern(int index, String pattern) {
StringToDateConverter converter = new StringToDateConverter(pattern);
return converter.convert(this.readAndTrim(index));
}
@Override
public Date getDateWithPattern(String name, String pattern) {
try {
return getDateWithPattern(indexOf(name), pattern);
}
catch (IllegalArgumentException e) {
throw new IllegalArgumentException(e.getMessage() + ", name: [" + name + "]");
}
}
@Override
public Date getDateWithPattern(int index, String pattern, Date defaultValue) {
try {
Date d = getDateWithPattern(index, pattern);
return (d != null) ? d : defaultValue;
}
catch (IllegalArgumentException e) {
return defaultValue;
}
}
@Override
public Date getDateWithPattern(String name, String pattern, Date defaultValue) {
try {
return getDateWithPattern(indexOf(name), pattern, defaultValue);
}
catch (IllegalArgumentException e) {
throw new IllegalArgumentException(e.getMessage() + ", name: [" + name + "]");
}
}
@Override
public <T> T getValue(String name, Class<T> valueClass) {
Object value = values.get(indexOf(name));
return convert(value, valueClass);
}
@Override
public <T> T getValue(int index, Class<T> valueClass) {
return convert(values.get(index), valueClass);
}
@SuppressWarnings("unchecked")
@Override
public Tuple select(String expression) {
EvaluationContext context = new StandardEvaluationContext(toMap());
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression(expression);
Object result = exp.getValue(context);
Map<String, Object> resultMap = null;
if (ClassUtils.isAssignableValue(Map.class, result)) {
resultMap = (Map<String, Object>) result;
}
if (resultMap != null) {
return toTuple(resultMap);
}
else {
return new DefaultTuple(new ArrayList<String>(0), new ArrayList<>(0),
this.configurableConversionService);
}
}
/**
* @return names and values as a {@code Map<String, Object>}
*/
Map<String, Object> toMap() {
Map<String, Object> map = new LinkedHashMap<>(values.size());
for (int i = 0; i < values.size(); i++) {
map.put(names.get(i), values.get(i));
}
return map;
}
Tuple toTuple(Map<String, Object> resultMap) {
List<String> newNames = new ArrayList<>();
List<Object> newValues = new ArrayList<>();
for (String name : resultMap.keySet()) {
newNames.add(name);
}
for (Object value : resultMap.values()) {
newValues.add(value);
}
return new DefaultTuple(newNames, newValues, this.configurableConversionService);
}
@SuppressWarnings("unchecked")
<T> T convert(Object value, Class<T> targetType) {
return (T) configurableConversionService.convert(value, TypeDescriptor.forObject(value),
TypeDescriptor.valueOf(targetType));
}
/**
* Find the index in the names collection for the given name.
* Returns -1 if not found.
*/
protected int indexOf(String name) {
return names.indexOf(name);
}
/**
* @param tupleToStringConverter used to convert a {@link Tuple} to a String
*/
protected void setTupleToStringConverter(Converter<Tuple, String> tupleToStringConverter) {
Assert.notNull(tupleToStringConverter, "tupleToStringConverter cannot be null");
this.tupleToStringConverter = tupleToStringConverter;
}
/**
* Returns a JSON representation of this Tuple.
*/
@Override
public String toString() {
if (tupleToStringConverter == null) {
return new TupleToJsonStringConverter().convert(this);
}
return tupleToStringConverter.convert(this);
}
public ConfigurableConversionService getConversionService() {
return this.configurableConversionService;
}
}

View File

@@ -1,37 +0,0 @@
/*
* Copyright 2002-2013 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
*
* http://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.tuple;
import java.util.Collection;
import org.springframework.core.convert.ConversionService;
import org.springframework.format.support.DefaultFormattingConversionService;
/**
* Base {@link ConversionService} implementation suitable for use with {@link Tuple}
*
* @author David Turanski
*
*/
public class DefaultTupleConversionService extends DefaultFormattingConversionService {
public DefaultTupleConversionService() {
/*
* DefaultFormattingConversionService provides Collection -> Object conversion which will produce the first item
* if the target type matches. Here, this results in an unfortunate side effect, getTuple(List<Tuple> list)
* would return a Tuple. In this case it is preferable to treat it as an error if the argument is not a Tuple.
*/
removeConvertible(Collection.class, Object.class);
}
}

View File

@@ -1,48 +0,0 @@
/*
* Copyright 2013 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
*
* http://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.tuple;
import org.springframework.core.convert.converter.Converter;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* @author David Turanski
*
*/
public class JsonBytesToTupleConverter implements Converter<byte[], Tuple> {
private final ObjectMapper mapper = new ObjectMapper();
private final JsonNodeToTupleConverter jsonNodeToTupleConverter = new JsonNodeToTupleConverter();
public JsonBytesToTupleConverter() {
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
}
@Override
public Tuple convert(byte[] source) {
if (source == null) {
return null;
}
try {
return jsonNodeToTupleConverter.convert(mapper.readTree(source));
}
catch (Exception e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
}
}

View File

@@ -1,94 +0,0 @@
/*
* Copyright 2013-2015 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
*
* http://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.tuple;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import org.springframework.core.convert.converter.Converter;
import com.fasterxml.jackson.databind.JsonNode;
/**
* @author David Turanski
*/
public class JsonNodeToTupleConverter implements Converter<JsonNode, Tuple> {
@Override
public Tuple convert(JsonNode root) {
TupleBuilder builder = TupleBuilder.tuple();
if (root.isValueNode()) {
return builder.of("value", root.asText());
}
try {
for (Iterator<Entry<String, JsonNode>> it = root.fields(); it.hasNext();) {
Entry<String, JsonNode> entry = it.next();
String name = entry.getKey();
JsonNode node = entry.getValue();
if (node.isObject()) {
// tuple
builder.addEntry(name, convert(node));
}
else if (node.isArray()) {
builder.addEntry(name, nodeToList(node));
}
else if (node.isNull()) {
builder.addEntry(name, null);
}
else if (node.isBoolean()) {
builder.addEntry(name, node.booleanValue());
}
else if (node.isNumber()) {
builder.addEntry(name, node.numberValue());
}
else {
builder.addEntry(name, node.asText());
}
}
}
catch (Exception e) {
throw new RuntimeException(e);
}
return builder.build();
}
private List<Object> nodeToList(JsonNode node) {
List<Object> list = new ArrayList<Object>(node.size());
for (int i = 0; i < node.size(); i++) {
JsonNode item = node.get(i);
if (item.isObject()) {
list.add(convert(item));
}
else if (item.isArray()) {
list.add(nodeToList(item));
}
else if (item.isNull()) {
list.add(null);
}
else if (item.isBoolean()) {
list.add(item.booleanValue());
}
else if (item.isNumber()) {
list.add(item.numberValue());
}
else {
list.add(item.asText());
}
}
return list;
}
}

View File

@@ -1,102 +0,0 @@
/*
* Copyright 2002-2015 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
*
* http://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.tuple;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.core.convert.converter.Converter;
/**
* @author David Turanski
*/
public class JsonStringToTupleConverter implements Converter<String, Tuple> {
private final ObjectMapper mapper = new ObjectMapper();
public JsonStringToTupleConverter() {
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
}
@Override
public Tuple convert(String source) {
TupleBuilder builder = TupleBuilder.tuple();
try {
JsonNode root = mapper.readTree(source);
for (Iterator<Entry<String, JsonNode>> it = root.fields(); it.hasNext();) {
Entry<String, JsonNode> entry = it.next();
String name = entry.getKey();
JsonNode node = entry.getValue();
if (node.isObject()) {
// tuple
builder.addEntry(name, convert(node.toString()));
}
else if (node.isArray()) {
builder.addEntry(name, nodeToList(node));
}
else if (node.isNull()) {
builder.addEntry(name, null);
}
else if (node.isBoolean()) {
builder.addEntry(name, node.booleanValue());
}
else if (node.isNumber()) {
builder.addEntry(name, node.numberValue());
}
else {
builder.addEntry(name, mapper.treeToValue(node, Object.class));
}
}
}
catch (Exception e) {
throw new RuntimeException(e);
}
return builder.build();
}
private List<Object> nodeToList(JsonNode node) throws JsonProcessingException {
List<Object> list = new ArrayList<Object>(node.size());
for (int i = 0; i < node.size(); i++) {
JsonNode item = node.get(i);
if (item.isObject()) {
list.add(convert(item.toString()));
}
else if (item.isArray()) {
list.add(nodeToList(item));
}
else if (item.isNull()) {
list.add(null);
}
else if (item.isBoolean()) {
list.add(item.booleanValue());
}
else if (item.isNumber()) {
list.add(item.numberValue());
}
else {
list.add(mapper.treeToValue(item, Object.class));
}
}
return list;
}
}

View File

@@ -1,75 +0,0 @@
/*
* Copyright 2013 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
*
* http://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.tuple;
import java.text.NumberFormat;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterFactory;
import org.springframework.util.NumberUtils;
/**
* Converts from a String any JDK-standard Number implementation.
*
* <p>
* Support Number classes including Byte, Short, Integer, Float, Double, Long, BigInteger, BigDecimal. This class
* delegates to {@link NumberUtils#parseNumber(String, Class, NumberFormat)} to perform the conversion.
*
* @author Mark Pollack
* @author Keith Donald
*
* @see Byte
* @see Short
* @see Integer
* @see Long
* @see java.math.BigInteger
* @see Float
* @see Double
* @see java.math.BigDecimal
* @see NumberUtils
*/
public class LocaleAwareStringToNumberConverterFactory implements ConverterFactory<String, Number> {
private NumberFormat numberFormat;
public LocaleAwareStringToNumberConverterFactory(NumberFormat numberFormat) {
this.numberFormat = numberFormat;
}
@Override
public <T extends Number> Converter<String, T> getConverter(Class<T> targetType) {
return new StringToNumber<T>(targetType, numberFormat);
}
private static final class StringToNumber<T extends Number> implements Converter<String, T> {
private final Class<T> targetType;
private NumberFormat numberFormat;
public StringToNumber(Class<T> targetType, NumberFormat numberFormat) {
this.targetType = targetType;
this.numberFormat = numberFormat;
}
@Override
public T convert(String source) {
return NumberUtils.parseNumber(source, this.targetType, numberFormat);
}
}
}

View File

@@ -1,38 +0,0 @@
/*
* Copyright 2016 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
*
* http://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.tuple;
/**
* Extension of {@link Tuple} that allows mutating and addition of fields.
*
* @author Eric Bottard
*/
public interface MutableTuple extends Tuple {
/**
* Sets the value of an already existing property, given its index.
*/
void setValue(int index, Object value);
/**
* Sets the value of a property, by name. If this Tuple does not currently hold
* a property under that name, a new mapping is added at the end and the size of this
* Tuple is extended by 1.
*/
void setValue(String name, Object value);
}

View File

@@ -1,70 +0,0 @@
/*
* Copyright 2013 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
*
* http://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.tuple;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.core.convert.converter.Converter;
/**
* Converter for Strings to Date that can take into account date patterns
*
* @author Mark Pollack
*
*/
public class StringToDateConverter implements Converter<String, Date> {
private final static String DEFAULT_DATE_PATTERN = "yyyy-MM-dd";
private DateFormat dateFormat;
public StringToDateConverter() {
this.dateFormat = new SimpleDateFormat(DEFAULT_DATE_PATTERN);
this.dateFormat.setLenient(false);
}
public StringToDateConverter(String pattern) {
this.dateFormat = new SimpleDateFormat(pattern);
this.dateFormat.setLenient(false);
}
public StringToDateConverter(DateFormat dateFormat) {
this.dateFormat = dateFormat;
}
@Override
public Date convert(String source) {
try {
return dateFormat.parse(source);
}
catch (ParseException e) {
String pattern;
if (dateFormat instanceof SimpleDateFormat) {
pattern = ((SimpleDateFormat) dateFormat).toPattern();
}
else {
pattern = dateFormat.toString();
}
throw new IllegalArgumentException(e.getMessage() + ", format: [" + pattern + "]");
}
}
}

View File

@@ -1,559 +0,0 @@
/*
* Copyright 2013-2016 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
*
* http://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.tuple;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import org.springframework.core.convert.ConversionFailedException;
/**
* Data structure that stores a fixed number of ordered key-value pairs and adds convenience methods to access values in
* a type-safe manner.
*
* Values do not need to be of the same type. When accessing values,
* Spring's type conversion system is used to convert the value type to the requested type. The type conversion system
* is extensible.
*
* This interface only allows querying properties. Concrete Tuples can also implement {@link MutableTuple} to allow
* mutation. Tuples are created using the TupleBuilder class.
*
* @author Mark Pollack
*
*/
public interface Tuple {
/**
* Return the number of elements in this tuple.
*
* @return number of elements
*/
int size();
/**
* Return the fields names that can reference elements by name in this tuple
*
* @return list of field names
*/
List<String> getFieldNames();
/**
* Return the values for all the fields in this tuple
*
* @return list of values.
*/
List<Object> getValues();
/**
* Return true if the tuple contains a field of the given name
*
* @param name the name of the field
* @return true if present, otherwise false
*/
boolean hasFieldName(String name);
/**
* Return the Java types of the fields in this tuple.
*
* @return the Java types of the fields in this tuple.
*/
@SuppressWarnings("rawtypes")
List<Class> getFieldTypes();
/**
* Return the number of fields in this tuple.
*
* @return the number of fields in this tuple.
*/
int getFieldCount();
/**
* Return the value of the field given the name
*
* @param name the name of the field
* @return value of the field
* @throws IllegalArgumentException if the name is not present
*/
Object getValue(String name);
/**
* Return the value of the field given the index position
*
* @param index position in the tuple
* @return value of the field
* @throws IndexOutOfBoundsException if the index position is out of bounds.
*/
Object getValue(int index);
/**
* Return the value of the field given the name
*
* @param name the field name
* @param valueClass Class to coerce the value into.
* @return value of the field
*/
<T> T getValue(String name, Class<T> valueClass);
/**
* Return the value of the field given the index position
*
* @param index position in the tuple
* @param valueClass Class to coerce the value into
* @return value of the field
*/
<T> T getValue(int index, Class<T> valueClass);
/**
* Read the {@link String} value given the field '<code>name</code>'.
*
* @param name the field name.
* @return value of the field
*/
String getString(String name);
/**
* Read the String value given the index position
*
* @param index position in the tuple
* @return value of the field
*/
String getString(int index);
/**
* Read the {@link Tuple} value given the field '<code>name</code>'.
*
* @param name the field name.
* @return value of the field
*/
Tuple getTuple(String name);
/**
* Read the Tuple value given the index position
*
* @param index position in the tuple
* @return value of the field
*/
Tuple getTuple(int index);
/**
* Read the {@link String} value at index '<code>index</code>' including trailing whitespace (don't trim).
*
* @param index the field index.
* @throws IndexOutOfBoundsException if the index is out of bounds.
*/
String getRawString(int index);
/**
* Read the {@link String} value from column with given '<code>name</code>' including trailing whitespace (don't
* trim).
*
* @param name the field name.
*/
String getRawString(String name);
/**
* Read the '<code>char</code>' value at index '<code>index</code>'.
*
* @param index the field index.
* @throws IndexOutOfBoundsException if the index is out of bounds.
*/
char getChar(int index);
/**
* Read the '<code>char</code>' value from field with given '<code>name</code>'.
*
* @param name the field name.
* @throws IllegalArgumentException if a field with given name is not defined.
*/
char getChar(String name);
/**
* Read the '<code>boolean</code>' value at index '<code>index</code>'.
*
* @param index the field index.
* @throws IndexOutOfBoundsException if the index is out of bounds.
*/
boolean getBoolean(int index);
/**
* Read the '<code>boolean</code>' value from field with given '<code>name</code>'.
*
* @param name the field name.
* @throws IllegalArgumentException if a field with given name is not defined.
*/
boolean getBoolean(String name);
/**
* Read the '<code>boolean</code>' value at index '<code>index</code>'.
*
* @param index the field index.
* @param trueValue the value that signifies {@link Boolean#TRUE true}; case-sensitive.
* @throws IndexOutOfBoundsException if the index is out of bounds, or if the supplied <code>trueValue</code> is
* <code>null</code>.
*/
boolean getBoolean(int index, String trueValue);
/**
* Read the '<code>boolean</code>' value from column with given '<code>name</code>'.
*
* @param name the field name.
* @param trueValue the value that signifies {@link Boolean#TRUE true}; case-sensitive.
* @throws IllegalArgumentException if a column with given name is not defined, or if the supplied
* <code>trueValue</code> is <code>null</code>.
*/
boolean getBoolean(String name, String trueValue);
/**
* Read the '<code>byte</code>' value at index '<code>index</code>'.
*
* @param index the field index.
* @throws IndexOutOfBoundsException if the index is out of bounds.
*/
byte getByte(int index);
/**
* Read the '<code>byte</code>' value from column with given '<code>name</code>'.
*
* @param name the field name.
*/
byte getByte(String name);
/**
* Read the '<code>byte</code>' value at index '<code>index</code>'. using the supplied <code>defaultValue</code> if
* the field value is a zero length string or null.
*
* @param index the field index.
* @param defaultValue the default value to return if field value is not found.
* @throws IndexOutOfBoundsException if the index is out of bounds.
*/
byte getByte(int index, byte defaultValue);
/**
* Read the '<code>byte</code>' value from column with given '<code>name</code>'. using the supplied
* <code>defaultValue</code> if the field value is a zero length string or null.
*
* @param name the field name.
* @param defaultValue the default value to return if field value is not found.
*/
byte getByte(String name, byte defaultValue);
/**
* Read the '<code>short</code>' value at index '<code>index</code>'.
*
* @param index the field index.
* @throws IndexOutOfBoundsException if the index is out of bounds.
*/
short getShort(int index);
/**
* Read the '<code>short</code>' value from column with given '<code>name</code>'.
*
* @param name the field name.
*/
short getShort(String name);
/**
* Read the '<code>short</code>' value at index '<code>index</code>'. using the supplied <code>defaultValue</code>
* if the field value is a zero length string or null.
*
* @param index the field index.
* @param defaultValue the default value to return if field value is not found.
* @throws IndexOutOfBoundsException if the index is out of bounds.
*/
short getShort(int index, short defaultValue);
/**
* Read the '<code>short</code>' value from column with given '<code>name</code>'. using the supplied
* <code>defaultValue</code> if the field value is a zero length string or null.
*
* @param name the field name.
* @param defaultValue the default value to return if field value is not found.
*/
short getShort(String name, short defaultValue);
/**
* Read the '<code>int</code>' value at index '<code>index</code>'.
*
* @param index the field index.
* @throws IndexOutOfBoundsException if the index is out of bounds.
*/
int getInt(int index);
/**
* Read the '<code>int</code>' value from column with given '<code>name</code>'.
*
* @param name the field name.
*/
int getInt(String name);
/**
* Read the '<code>int</code>' value at index '<code>index</code>'. using the supplied <code>defaultValue</code> if
* the field value is a zero length string or null.
*
* @param index the field index.
* @param defaultValue the default value to return if field value is not found.
* @throws IndexOutOfBoundsException if the index is out of bounds.
*/
int getInt(int index, int defaultValue);
/**
* Read the '<code>int</code>' value from column with given '<code>name</code>'. using the supplied
* <code>defaultValue</code> if the field value is a zero length string or null.
*
* @param name the field name.
* @param defaultValue the default value to return if field value is not found.
*/
int getInt(String name, int defaultValue);
/**
* Read the '<code>long</code>' value at index '<code>index</code>'.
*
* @param index the field index.
* @throws IndexOutOfBoundsException if the index is out of bounds.
*/
long getLong(int index);
/**
* Read the '<code>int</code>' value from column with given '<code>name</code>'.
*
* @param name the field name.
*/
long getLong(String name);
/**
* Read the '<code>long</code>' value at index '<code>index</code>'. using the supplied <code>defaultValue</code> if
* the field value is a zero length string or null.
*
* @param index the field index.
* @param defaultValue the default value to return if field value is not found.
* @throws IndexOutOfBoundsException if the index is out of bounds.
*/
long getLong(int index, long defaultValue);
/**
* Read the '<code>long</code>' value from column with given '<code>name</code>'. using the supplied
* <code>defaultValue</code> if the field value is a zero length string or null.
*
* @param name the field name.
* @param defaultValue the default value to return if field value is not found.
*/
long getLong(String name, long defaultValue);
/**
* Read the '<code>float</code>' value at index '<code>index</code>'.
*
* @param index the field index.
* @throws IndexOutOfBoundsException if the index is out of bounds.
*/
float getFloat(int index);
/**
* Read the '<code>float</code>' value from column with given '<code>name</code>'.
*
* @param name the field name.
*/
float getFloat(String name);
/**
* Read the '<code>float</code>' value at index '<code>index</code>'. using the supplied <code>defaultValue</code>
* if the field value is a zero length string or null.
*
* @param index the field index.
* @param defaultValue the default value to return if field value is not found.
* @throws IndexOutOfBoundsException if the index is out of bounds.
*/
float getFloat(int index, float defaultValue);
/**
* Read the '<code>float</code>' value from column with given '<code>name</code>'. using the supplied
* <code>defaultValue</code> if the field value is a zero length string or null.
*
* @param name the field name.
* @param defaultValue the default value to return if field value is not found.
*/
float getFloat(String name, float defaultValue);
/**
* Read the '<code>double</code>' value at index '<code>index</code>'.
*
* @param index the field index.
* @throws IndexOutOfBoundsException if the index is out of bounds.
*/
double getDouble(int index);
/**
* Read the '<code>double</code>' value from column with given '<code>name</code>'.
*
* @param name the field name.
*/
double getDouble(String name);
/**
* Read the '<code>double</code>' value at index '<code>index</code>'. using the supplied <code>defaultValue</code>
* if the field value is a zero length string or null.
*
* @param index the field index.
* @param defaultValue the default value to return if field value is not found.
* @throws IndexOutOfBoundsException if the index is out of bounds.
*/
double getDouble(int index, double defaultValue);
/**
* Read the '<code>double</code>' value from column with given '<code>name</code>'. using the supplied
* <code>defaultValue</code> if the field value is a zero length string or null.
*
* @param name the field name.
* @param defaultValue the default value to return if field value is not found.
*/
double getDouble(String name, double defaultValue);
/**
* Read the '<code>BigDecimal</code>' value at index '<code>index</code>'.
*
* @param index the field index.
* @throws IndexOutOfBoundsException if the index is out of bounds.
*/
BigDecimal getBigDecimal(int index);
/**
* Read the '<code>BigDecimal</code>' value from column with given '<code>name</code>'.
*
* @param name the field name.
*/
BigDecimal getBigDecimal(String name);
/**
* Read the '<code>BigDecimal</code>' value at index '<code>index</code>'. using the supplied
* <code>defaultValue</code> if the field value is a zero length string or null.
*
* @param index the field index.
* @param defaultValue the default value to return if field value is not found.
* @throws IndexOutOfBoundsException if the index is out of bounds.
*/
BigDecimal getBigDecimal(int index, BigDecimal defaultValue);
/**
* Read the '<code>BigDecimal</code>' value from column with given '<code>name</code>'. using the supplied
* <code>defaultValue</code> if the field value is a zero length string or null.
*
* @param name the field name.
* @param defaultValue the default value to return if field value is not found.
*/
BigDecimal getBigDecimal(String name, BigDecimal defaultValue);
/**
* Read the <code>java.util.Date</code> value in default format at designated column <code>index</code>.
*
* @param index the field index.
* @throws IndexOutOfBoundsException if the index is out of bounds.
* @throws ConversionFailedException if the value is not parseable
*/
Date getDate(int index);
/**
* Read the <code>java.util.Date</code> value in default format at designated column with given <code>name</code>.
*
* @param name the field name.
* @throws IllegalArgumentException if a column with given name is not defined
* @throws ConversionFailedException if the value is not parseable
*/
Date getDate(String name);
/**
* Read the <code>java.util.Date</code> value in default format at designated column <code>index</code> using the
* supplied <code>defaultValue</code> if the field value is a zero length string or null.
*
* @param index the field index.
* @param defaultValue the default value to return if field value is not found.
* @throws IndexOutOfBoundsException if the index is out of bounds.
* @throws ConversionFailedException if the value is not parseable
*/
Date getDate(int index, Date defaultValue);
/**
* Read the <code>java.util.Date</code> value in default format at designated column with given <code>name</code>.
* using the supplied <code>defaultValue</code> if the field value is a zero length string or null.
*
* @param name the field name.
* @param defaultValue the default value to return if field value is not found.
* @throws IllegalArgumentException if a column with given name is not defined
* @throws ConversionFailedException if the value is not parseable
*/
Date getDate(String name, Date defaultValue);
/**
* Read the <code>java.util.Date</code> value in default format at designated column <code>index</code>.
*
* @param index the field index.
* @param pattern the pattern describing the date and time format
* @throws IndexOutOfBoundsException if the index is out of bounds.
* @throws IllegalArgumentException if the date cannot be parsed.
*
*/
Date getDateWithPattern(int index, String pattern);
/**
* Read the <code>java.util.Date</code> value in given format from column with given <code>name</code>.
*
* @param name the field name.
* @param pattern the pattern describing the date and time format
* @throws IllegalArgumentException if a column with given name is not defined or if the specified field cannot be
* parsed
*
*/
Date getDateWithPattern(String name, String pattern);
/**
* Read the <code>java.util.Date</code> value in default format at designated column <code>index</code>. using the
* supplied <code>defaultValue</code> if the field value is a zero length string or null.
*
* @param index the field index.
* @param pattern the pattern describing the date and time format
* @param defaultValue the default value to return if field value is not found.
* @throws IndexOutOfBoundsException if the index is out of bounds.
* @throws IllegalArgumentException if the date cannot be parsed.
*
*/
Date getDateWithPattern(int index, String pattern, Date defaultValue);
/**
* Read the <code>java.util.Date</code> value in given format from column with given <code>name</code>. using the
* supplied <code>defaultValue</code> if the field value is a zero length string or null.
*
* @param name the field name.
* @param pattern the pattern describing the date and time format
* @param defaultValue the default value to return if field value is not found.
* @throws IllegalArgumentException if a column with given name is not defined or if the specified field cannot be
* parsed
*
*/
Date getDateWithPattern(String name, String pattern, Date defaultValue);
/**
* Use SpEL expression to return a subset of the tuple that matches the expression
*
* @param expression SpEL expression to select from a Map, e.g. ?[key.startsWith('b')]
* @return a new Tuple with data selected from the current instance.
*/
Tuple select(String expression);
}

View File

@@ -1,232 +0,0 @@
/*
* Copyright 2013-2016 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
*
* http://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.tuple;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.support.ConfigurableConversionService;
import org.springframework.util.Assert;
/**
* Builder class to create Tuple instances.
*
* Default Locale is US for NumberFormat and default DatePattern is "yyyy-MM-dd"
*
* <em>Note:</em> Using a custom conversion service that is instance based (not configured
* as a singleton) will have <em>significant</em> performance impacts.
*
* @author Mark Pollack
* @author David Turanski
* @author Michael Minella
* @author Gunnar Hillert
*/
public class TupleBuilder {
private List<String> names = new ArrayList<>();
private List<Object> values = new ArrayList<>();
private final boolean mutable;
private ConfigurableConversionService customConversionService = null;
private final static String DEFAULT_DATE_PATTERN = "yyyy-MM-dd";
private final static Locale DEFAULT_LOCALE = Locale.US;
private static final ConfigurableConversionService defaultConversionService;
private static Converter<Tuple, String> tupleToStringConverter = new TupleToJsonStringConverter();
private static Converter<String, Tuple> stringToTupleConverter = new JsonStringToTupleConverter();
static {
defaultConversionService = new DefaultTupleConversionService();
defaultConversionService.addConverterFactory(new LocaleAwareStringToNumberConverterFactory(NumberFormat
.getInstance(DEFAULT_LOCALE)));
DateFormat dateFormat = new SimpleDateFormat(DEFAULT_DATE_PATTERN);
dateFormat.setLenient(false);
defaultConversionService.addConverter(new StringToDateConverter(dateFormat));
}
/**
* Return a new builder that will create immutable Tuples.
*/
public static TupleBuilder mutableTuple() {
return new TupleBuilder(true);
}
/**
* Return a new builder that will create {@link MutableTuple}.
*/
public static TupleBuilder tuple() {
return new TupleBuilder(false);
}
/**
* Creates a builder that will create immutable Tuples.
*/
public TupleBuilder() {
this(false);
}
private TupleBuilder(boolean mutable) {
this.mutable = mutable;
}
public Tuple of(String k1, Object v1) {
return newTuple(namesOf(k1), valuesOf(v1));
}
public Tuple of(String k1, Object v1, String k2, Object v2) {
addEntry(k1, v1);
addEntry(k2, v2);
return build();
}
public Tuple of(String k1, Object v1, String k2, Object v2, String k3, Object v3) {
addEntry(k1, v1);
addEntry(k2, v2);
addEntry(k3, v3);
return build();
}
public Tuple of(String k1, Object v1, String k2, Object v2, String k3, Object v3, String k4, Object v4) {
addEntry(k1, v1);
addEntry(k2, v2);
addEntry(k3, v3);
addEntry(k4, v4);
return build();
}
public Tuple ofNamesAndValues(List<String> names, List<Object> values) {
this.names = names;
this.values = values;
return build();
}
public TupleBuilder put(String k1, Object v1) {
addEntry(k1, v1);
return this;
}
/**
* Add all names and values of the tuple to the built tuple.
* @param tuple names and value to add to the tuple being built
* @return builder to continue creating a new tuple instance
*/
public TupleBuilder putAll(Tuple tuple) {
for (int i = 0; i < tuple.size(); i++) {
Object value = tuple.getValues().get(i);
String name = tuple.getFieldNames().get(i);
addEntry(name, value);
}
return this;
}
public Tuple build() {
return newTuple(names, values);
}
public static Tuple fromString(String source) {
return stringToTupleConverter.convert(source);
}
public TupleBuilder setConfigurableConversionService(ConfigurableConversionService formattingConversionService) {
Assert.notNull(formattingConversionService);
this.customConversionService = formattingConversionService;
return this;
}
public ConversionServiceBuilder setFormats(Locale locale, DateFormat dateFormat) {
return new ConversionServiceBuilder(this, locale, dateFormat);
}
void addEntry(String k1, Object v1) {
names.add(k1);
values.add(v1);
}
static List<Object> valuesOf(Object v1) {
ArrayList<Object> values = new ArrayList<>();
values.add(v1);
return Collections.unmodifiableList(values);
}
static List<String> namesOf(String k1) {
List<String> fields = new ArrayList<>(1);
fields.add(k1);
return Collections.unmodifiableList(fields);
}
protected Tuple newTuple(List<String> names, List<Object> values) {
DefaultTuple tuple;
ConfigurableConversionService conversionService = customConversionService != null ? customConversionService : defaultConversionService;
tuple = mutable
? new DefaultMutableTuple(names, values, conversionService)
: new DefaultTuple(names, values, conversionService);
tuple.setTupleToStringConverter(tupleToStringConverter);
return tuple;
}
/**
* Provides the ability to inject a {@link ConfigurableConversionService} as a way to
* customize conversion behavior in the built {@link Tuple}.
*
* @author Michael Minella
*/
public static class ConversionServiceBuilder {
private TupleBuilder builder;
private Locale locale;
private DateFormat dateFormat;
ConversionServiceBuilder(TupleBuilder builder, Locale locale, DateFormat dateFormat) {
this.builder = builder;
this.locale = locale;
this.dateFormat = dateFormat;
}
public TupleBuilder setConfigurableConversionService(ConfigurableConversionService formattingConversionService) {
Assert.notNull(formattingConversionService);
if (locale != null) {
formattingConversionService.addConverterFactory(new LocaleAwareStringToNumberConverterFactory(NumberFormat
.getInstance(locale)));
}
if (dateFormat != null) {
formattingConversionService.addConverter(new StringToDateConverter(dateFormat));
}
builder.setConfigurableConversionService(formattingConversionService);
return builder;
}
}
}

View File

@@ -1,30 +0,0 @@
/*
* Copyright 2015 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
*
* http://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.tuple;
/**
* @author David Turanski
*
*/
public class TupleJsonMarshaller extends TupleStringMarshaller {
public TupleJsonMarshaller() {
super(new TupleToJsonStringConverter(), new JsonStringToTupleConverter());
}
}

View File

@@ -1,44 +0,0 @@
/*
* Copyright 2015 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
*
* http://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.tuple;
import org.springframework.core.convert.converter.Converter;
/**
* @author David Turanski
*
*/
public class TupleStringMarshaller {
private final Converter<Tuple, String> tupleToStringConverter;
private final Converter<String, Tuple> stringToTupleConverter;
public TupleStringMarshaller(Converter<Tuple, String> tupleToStringConverter,
Converter<String, Tuple> stringToTupleConverter) {
this.tupleToStringConverter = tupleToStringConverter;
this.stringToTupleConverter = stringToTupleConverter;
}
public Tuple toTuple(String source) {
return stringToTupleConverter.convert(source);
}
public String fromTuple(Tuple source) {
return tupleToStringConverter.convert(source);
}
}

View File

@@ -1,93 +0,0 @@
/*
* Copyright 2002-2015 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
*
* http://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.tuple;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.BaseJsonNode;
import org.springframework.core.convert.converter.Converter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.List;
/**
* Converts a Tuple to JSON representation
*
* @author David Turanski
* @author Gunnar Hillert
*/
public class TupleToJsonStringConverter implements Converter<Tuple, String> {
private final ObjectMapper mapper = new ObjectMapper();
@Override
public String convert(Tuple source) {
ObjectNode root = toObjectNode(source);
String json = null;
try {
json = mapper.writeValueAsString(root);
}
catch (Exception e) {
throw new IllegalArgumentException("Tuple to string conversion failed", e);
}
return json;
}
private ObjectNode toObjectNode(Tuple source) {
ObjectNode root = mapper.createObjectNode();
for (int i = 0; i < source.size(); i++) {
Object value = source.getValues().get(i);
String name = source.getFieldNames().get(i);
if (value == null) {
root.putNull(name);
} else {
root.putPOJO(name, toNode(value));
}
}
return root;
}
private ArrayNode toArrayNode(List<?> source) {
ArrayNode array = mapper.createArrayNode();
for (Object value : source) {
if (value != null) {
array.add(toNode(value));
}
}
return array;
}
private BaseJsonNode toNode(Object value) {
if (value != null) {
if (value instanceof Tuple) {
return toObjectNode((Tuple) value);
}
else if (value instanceof List<?>) {
return toArrayNode((List<?>) value);
}
else if (!value.getClass().isPrimitive()) {
return mapper.getNodeFactory().pojoNode(value);
}
else {
return mapper.valueToTree(value);
}
}
return null;
}
}

View File

@@ -1,60 +0,0 @@
/*
* Copyright 2013 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
*
* http://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.tuple.integration;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.springframework.integration.transformer.AbstractPayloadTransformer;
import org.springframework.cloud.stream.tuple.Tuple;
import org.springframework.cloud.stream.tuple.TupleBuilder;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Converts from a json string into a tuple data structure.
*
* @author Mark Fisher
*/
public class JsonToTupleTransformer extends AbstractPayloadTransformer<String, Tuple> {
private final ObjectMapper mapper = new ObjectMapper();
public JsonToTupleTransformer() {
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
}
@Override
public Tuple transformPayload(String json) throws Exception {
List<String> names = new ArrayList<String>();
List<Object> values = new ArrayList<Object>();
JsonNode node = this.mapper.readTree(json);
Iterator<String> fieldNames = node.fieldNames();
while (fieldNames.hasNext()) {
String name = fieldNames.next();
JsonNode valueNode = node.get(name);
Object value = mapper.treeToValue(valueNode, Object.class);
names.add(name);
values.add(value);
}
return TupleBuilder.tuple().ofNamesAndValues(names, values);
}
}

View File

@@ -1,47 +0,0 @@
/*
* Copyright 2013-2015 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
*
* http://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.tuple.integration;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.springframework.cloud.stream.tuple.Tuple;
import org.springframework.cloud.stream.tuple.TupleBuilder;
import org.springframework.integration.transformer.AbstractPayloadTransformer;
/**
* Converts from a Map to the Tuple data structure.
*
* @author Mark Pollack
* @author Ilayaperumal Gopinathan
*/
public class MapToTupleTransformer extends AbstractPayloadTransformer<Map<Object, Object>, Tuple> {
@Override
public Tuple transformPayload(Map<Object, Object> map) {
List<String> newNames = new ArrayList<String>();
List<Object> newValues = new ArrayList<Object>();
for (Map.Entry<Object, Object> entry: map.entrySet()) {
newNames.add(entry.getKey().toString());
newValues.add(entry.getValue());
}
return TupleBuilder.tuple().ofNamesAndValues(newNames, newValues);
}
}

View File

@@ -1,52 +0,0 @@
/*
* Copyright 2015 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
*
* http://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.tuple.integration;
import java.util.ArrayList;
import java.util.List;
import org.springframework.cloud.stream.tuple.kryo.DefaultTupleSerializer;
import org.springframework.integration.codec.kryo.AbstractKryoRegistrar;
import org.springframework.integration.codec.kryo.KryoRegistrar;
import org.springframework.cloud.stream.tuple.DefaultTuple;
import com.esotericsoftware.kryo.Registration;
import com.esotericsoftware.kryo.serializers.CollectionSerializer;
/**
* A {@link KryoRegistrar} used to register a Tuple serializer.
*
* @author David Turanski
*/
public class TupleKryoRegistrar extends AbstractKryoRegistrar {
private final static int TUPLE_REGISTRATION_ID = 43;
private final static int ARRAY_LIST_REGISTRATION_ID = 44;
private final DefaultTupleSerializer defaultTupleSerializer = new DefaultTupleSerializer();
private final CollectionSerializer collectionSerializer = new CollectionSerializer();
@Override
public List<Registration> getRegistrations() {
List<Registration> registrations = new ArrayList<>(2);
registrations.add(new Registration(DefaultTuple.class, defaultTupleSerializer, TUPLE_REGISTRATION_ID));
registrations.add(new Registration(ArrayList.class, collectionSerializer, ARRAY_LIST_REGISTRATION_ID));
return registrations;
}
}

View File

@@ -1,5 +0,0 @@
/**
* Contains classes that support tuple integration such as tuple transformers.
*/
package org.springframework.cloud.stream.tuple.integration;

View File

@@ -1,54 +0,0 @@
/*
* Copyright 2015 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
*
* http://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.tuple.kryo;
import java.util.ArrayList;
import java.util.List;
import org.springframework.cloud.stream.tuple.Tuple;
import org.springframework.cloud.stream.tuple.TupleBuilder;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Serializer;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
/**
* Serializes Tuples by writing the field names and then the values as class/object pairs.
*
* @author David Turanski
*/
public class DefaultTupleSerializer extends Serializer<Tuple> {
@Override
public void write(Kryo kryo, Output output, Tuple tuple) {
kryo.writeObject(output, tuple.getFieldNames());
for (Object val: tuple.getValues()) {
kryo.writeClassAndObject(output, val);
}
}
@Override
@SuppressWarnings("unchecked")
public Tuple read(Kryo kryo, Input input, Class<Tuple> type) {
List<String> names = kryo.readObject(input, ArrayList.class);
List<Object> values = new ArrayList<>(names.size());
for (int i = 0; i < names.size(); i++) {
Object val = kryo.readClassAndObject(input);
values.add(i, val);
}
return TupleBuilder.tuple().ofNamesAndValues(names, values);
}
}

View File

@@ -1,20 +0,0 @@
/*
* Copyright 2014 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
*
* http://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.
*/
/**
* Contains tuple processor classes.
*/
package org.springframework.cloud.stream.tuple.kryo;

View File

@@ -1,5 +0,0 @@
/**
* Base package for tuple classes.
*/
package org.springframework.cloud.stream.tuple;

View File

@@ -1,30 +0,0 @@
/*
* Copyright 2013 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
*
* http://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.tuple.processor;
import org.springframework.cloud.stream.tuple.Tuple;
/**
* Simple type-safe process callback method that returns another Tuple
*
* @author Mark Pollack
*
*/
public interface TupleProcessor {
Tuple process(Tuple tuple);
}

View File

@@ -1,5 +0,0 @@
/**
* Contains tuple processor classes.
*/
package org.springframework.cloud.stream.tuple.processor;

View File

@@ -1,124 +0,0 @@
/*
* Copyright 2013-2016 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
*
* http://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.tuple.spel;
import org.springframework.cloud.stream.tuple.MutableTuple;
import org.springframework.expression.AccessException;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.PropertyAccessor;
import org.springframework.expression.TypedValue;
import org.springframework.cloud.stream.tuple.Tuple;
/**
* A {@link PropertyAccessor} implementation that enables reading of {@link Tuple} values using dot notation within SpEL
* expressions.
*
* @author Mark Fisher
* @author Eric Bottard
*/
public class TuplePropertyAccessor implements PropertyAccessor {
@Override
public Class<?>[] getSpecificTargetClasses() {
return new Class<?>[] { Tuple.class, MutableTuple.class};
}
@Override
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
Tuple tuple = (Tuple) target;
if (tuple.hasFieldName(name)) {
return true;
}
return maybeIndex(name, tuple) != null;
}
/**
* Return an integer if the String property name can be parsed as an int, or null otherwise.
*/
private Integer maybeIndex(String name, Tuple tuple) {
Integer index = null;
try {
int i = Integer.parseInt(name);
if (i > -1 && tuple.size() > i) {
index = i;
}
}
catch (NumberFormatException e) {
// not an integer
}
return index;
}
@Override
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
Tuple tuple = (Tuple) target;
boolean hasKey = false;
Object value = null;
if (tuple.hasFieldName(name)) {
hasKey = true;
value = tuple.getValue(name);
}
else {
Integer index = maybeIndex(name, tuple);
if (index != null) {
hasKey = true;
value = tuple.getValue(index);
}
}
if (value == null && !hasKey) {
throw new TupleAccessException(name);
}
return new TypedValue(value);
}
@Override
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
return target instanceof MutableTuple;
}
@Override
public void write(EvaluationContext context, Object target, String name, Object newValue) throws AccessException {
MutableTuple tuple = (MutableTuple) target;
Integer index = maybeIndex(name, tuple);
if (index != null) {
tuple.setValue(index, newValue);
} else {
tuple.setValue(name, newValue);
}
}
/**
* Exception thrown from {@code read} in order to reset a cached PropertyAccessor, allowing other accessors to have
* a try.
*/
@SuppressWarnings("serial")
private static class TupleAccessException extends AccessException {
private final String name;
public TupleAccessException(String name) {
super(null);
this.name = name;
}
@Override
public String getMessage() {
return "Tuple does not contain a value for field name '" + this.name + "'";
}
}
}

View File

@@ -1,5 +0,0 @@
/**
* Contains tuple SpEL accessor classes.
*/
package org.springframework.cloud.stream.tuple.spel;

View File

@@ -1,119 +0,0 @@
/*
* Copyright 2002-2013 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
*
* http://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.tuple;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.Resource;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.springframework.cloud.stream.tuple.TupleBuilder.tuple;
/**
* @author David Turanski
*
*/
public abstract class AbstractTupleMarshallerTests {
private TupleStringMarshaller marshaller;
private ObjectMapper mapper = new ObjectMapper();
@Before
public void setUp() {
marshaller = getMarshaller();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
}
@Test
public void testMarshallSimpleTuple() {
DefaultTuple tuple = (DefaultTuple) tuple().of("foo", "bar", "int", 1);
String result = marshaller.fromTuple(tuple);
Tuple newTuple = marshaller.toTuple(result);
assertEquals(2, newTuple.getFieldCount());
assertEquals("bar", newTuple.getString(0));
assertEquals(1, newTuple.getInt(1));
}
@Test
public void testMarshallNestedTuple() {
Tuple t1 = tuple().of("foo", "bar", "int", 1);
Tuple tuple = tuple().of("t1", t1, "hello", "world");
String result = marshaller.fromTuple(tuple);
Tuple newTuple = marshaller.toTuple(result);
assertEquals(2, newTuple.getFieldCount());
assertEquals("world", newTuple.getString(1));
Tuple nested = newTuple.getTuple(0);
assertEquals(2, nested.getFieldCount());
assertEquals("bar", nested.getString(0));
assertEquals(1, nested.getInt(1));
}
@Test
public void testMarshallTupleWithCollection() {
List<?> values = Arrays.asList("a", "b", "c");
Tuple tuple = tuple().of("list", values);
String result = marshaller.fromTuple(tuple);
Tuple newTuple = marshaller.toTuple(result);
assertTrue(newTuple.getValue(0) instanceof List);
List<?> list = (List<?>) newTuple.getValue(0);
assertEquals(values.size(), list.size());
}
@Test
public void testMarshallTupleWithMap() {
Map<String, String> map = new HashMap<String, String>();
map.put("k1", "v1");
map.put("k2", "v2");
Tuple tuple = tuple().of("map", map);
String result = marshaller.fromTuple(tuple);
Tuple newTuple = marshaller.toTuple(result);
assertNotNull(newTuple.getValue("map"));
// Map is converted to a tuple
assertEquals("v1", newTuple.getTuple("map").getString("k1"));
assertEquals("v2", newTuple.getTuple("map").getString("k2"));
}
public String prettyPrintJson(String json) throws IOException {
Object jsonObject = mapper.readValue(json, Object.class);
return mapper.writeValueAsString(jsonObject);
}
public String readJson(Resource resource) throws IOException {
Object jsonObject = mapper.readValue(resource.getInputStream(), Object.class);
return mapper.writeValueAsString(jsonObject);
}
protected abstract TupleStringMarshaller getMarshaller();
}

View File

@@ -1,466 +0,0 @@
/*
* Copyright 2013 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
*
* http://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.tuple;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.springframework.cloud.stream.tuple.TupleBuilder.tuple;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.convert.ConversionFailedException;
/**
* This is a port of the FieldSet tests from Spring Batch
*
*/
public class DefaultTupleTestForBatch {
Tuple tuple;
List<Object> values;
List<String> names;
@Before
public void setUp() throws Exception {
Object[] tokens = new String[] { "TestString", "true", "C", "10", "-472", "354224", "543", "124.3", "424.3",
"1,3245",
null, "2007-10-12", "12-10-2007", "" };
String[] nameArray = new String[] { "String", "Boolean", "Char", "Byte", "Short", "Integer", "Long", "Float",
"Double",
"BigDecimal", "Null", "Date", "DatePattern", "BlankInput" };
names = Arrays.asList(nameArray);
values = Arrays.asList(tokens);
/*
* values = new ArrayList<Object>(); for (String token : tokens) { values.add(token); }
*/
tuple = tuple().ofNamesAndValues(names, values);
assertEquals(14, tuple.size());
}
@Test
public void testNames() throws Exception {
// MLP - tuples always have names, FieldSet in Spring Batch doesn't require a name.
assertThat(tuple.getFieldCount(), is(tuple.getFieldNames().size()));
}
@Test
public void testReadString() {
assertThat(tuple.getString(0), is("TestString"));
assertThat(tuple.getString("String"), is("TestString"));
}
@Test
public void testReadChar() {
assertThat(tuple.getChar(2), is('C'));
assertThat(tuple.getChar("Char"), is('C'));
}
@Test
public void testReadBooleanTrue() {
assertThat(tuple.getBoolean(1), is(true));
assertThat(tuple.getBoolean("Boolean"), is(true));
}
@Test
public void testReadByte() {
assertTrue(tuple.getByte(3) == 10);
assertTrue(tuple.getByte("Byte") == 10);
}
@Test
public void testReadShort() {
assertTrue(tuple.getShort(4) == -472);
assertTrue(tuple.getShort("Short") == -472);
}
@Test
public void testReadIntegerAsFloat() {
assertEquals(354224, tuple.getFloat(5), .001);
assertEquals(354224, tuple.getFloat("Integer"), .001);
}
@Test
public void testReadFloat() throws Exception {
assertTrue(tuple.getFloat(7) == 124.3F);
assertTrue(tuple.getFloat("Float") == 124.3F);
}
@Test
public void testReadIntegerAsDouble() throws Exception {
assertEquals(354224, tuple.getDouble(5), .001);
assertEquals(354224, tuple.getDouble("Integer"), .001);
}
@Test
public void testReadDouble() throws Exception {
assertTrue(tuple.getDouble(8) == 424.3);
assertTrue(tuple.getDouble("Double") == 424.3);
}
@Test
public void testReadBigDecimal() throws Exception {
BigDecimal bd = new BigDecimal("424.3");
assertEquals(bd, tuple.getBigDecimal(8));
assertEquals(bd, tuple.getBigDecimal("Double"));
}
@Test
public void testReadBigBigDecimal() throws Exception {
BigDecimal bd = new BigDecimal("12345678901234567890");
Tuple tuple = TupleBuilder.tuple().of("bigd", "12345678901234567890");
assertEquals(bd, tuple.getBigDecimal(0));
}
@Test
public void testReadBigDecimalWithFormat() throws Exception {
Tuple numberFormatTuple = TupleBuilder.tuple()
.setFormats(Locale.US, null)
.setConfigurableConversionService(new DefaultTupleConversionService())
.ofNamesAndValues(tuple.getFieldNames(), tuple.getValues());
BigDecimal bd = new BigDecimal("424.3");
assertEquals(bd, numberFormatTuple.getBigDecimal(8));
}
@Test
public void testReadBigDecimalWithEuroFormat() throws Exception {
Tuple numberFormatTuple = TupleBuilder.tuple()
.setFormats(Locale.GERMANY, null)
.setConfigurableConversionService(new DefaultTupleConversionService())
.ofNamesAndValues(tuple.getFieldNames(), tuple.getValues());
BigDecimal bd = new BigDecimal("1.3245");
assertEquals(bd, numberFormatTuple.getBigDecimal(9));
}
@Test
public void testReadNonExistentField() {
String s = tuple.getString("something");
assertThat(s, nullValue());
}
@Test
public void testReadIndexOutOfRange() {
try {
tuple.getShort(-1);
fail("field set returns value even index is out of range!");
}
catch (IndexOutOfBoundsException e) {
assertTrue(true);
}
try {
tuple.getShort(99);
fail("field set returns value even index is out of range!");
}
catch (Exception e) {
assertTrue(true);
}
}
@Test
public void testReadBooleanWithTrueValue() {
assertTrue(tuple.getBoolean(1, "true"));
assertFalse(tuple.getBoolean(1, "incorrect trueValue"));
assertTrue(tuple.getBoolean("Boolean", "true"));
assertFalse(tuple.getBoolean("Boolean", "incorrect trueValue"));
}
@Test
public void testReadBooleanFalse() {
Tuple t = TupleBuilder.tuple().of("foo", false);
assertFalse(t.getBoolean(0));
}
@Test
public void testReadCharException() {
try {
tuple.getChar(1);
fail("the value read was not a character, exception expected");
}
catch (IllegalArgumentException expected) {
assertTrue(true);
}
try {
tuple.getChar("Boolean");
fail("the value read was not a character, exception expected");
}
catch (IllegalArgumentException expected) {
assertTrue(true);
}
}
@Test
public void testReadInt() throws Exception {
assertThat(354224, equalTo(tuple.getInt(5)));
assertThat(354224, equalTo(tuple.getInt("Integer")));
}
@Test
public void testReadIntWithSeparator() {
Tuple t = TupleBuilder.tuple().of("foo", "354,224");
assertThat(354224, equalTo(t.getInt(0)));
}
@Test
public void testReadIntWithSeparatorAndFormat() throws Exception {
Tuple t = TupleBuilder.tuple()
.setFormats(Locale.GERMAN, null)
.setConfigurableConversionService(new DefaultTupleConversionService())
.of("foo", "354.224");
assertThat(354224, equalTo(t.getInt(0)));
}
@Test
public void testReadBlankInt() {
// Trying to parse a blank field as an integer, but without a default
// value should throw a NumberFormatException
try {
tuple.getInt(13);
fail();
}
catch (ConversionFailedException ex) {
// expected
}
try {
tuple.getInt("BlankInput");
fail();
}
catch (ConversionFailedException ex) {
// expected
}
}
@Test
public void testReadLong() throws Exception {
assertThat(543L, equalTo(tuple.getLong(6)));
assertThat(543L, equalTo(tuple.getLong("Long")));
}
@Test
public void testReadLongWithPadding() throws Exception {
Tuple t = TupleBuilder.tuple().of("foo", "000009");
assertThat(9L, equalTo(t.getLong(0)));
}
@Test
public void testReadIntWithNullValue() {
assertThat(5, equalTo(tuple.getInt(10, 5)));
assertThat(5, equalTo(tuple.getInt("Null", 5)));
}
@Test
public void testReadIntWithDefaultAndNotNull() {
assertThat(354224, equalTo(tuple.getInt(5, 5)));
assertThat(354224, equalTo(tuple.getInt("Integer", 5)));
}
@Test
public void testReadLongWithNullValue() {
long defaultValue = 5;
int indexOfNull = 10;
int indexNotNull = 6;
String nameNull = "Null";
String nameNotNull = "Long";
long longValueAtIndex = 543;
assertThat(defaultValue, equalTo(tuple.getLong(indexOfNull, defaultValue)));
assertThat(longValueAtIndex, equalTo(tuple.getLong(indexNotNull, defaultValue)));
assertThat(defaultValue, equalTo(tuple.getLong(nameNull, defaultValue)));
assertThat(longValueAtIndex, equalTo(tuple.getLong(nameNotNull, defaultValue)));
}
@Test
public void testReadBigDecimalInvalid() {
int index = 0;
try {
tuple.getBigDecimal(index);
fail("field value is not a number, exception expected");
}
catch (ConversionFailedException e) {
assertTrue(e.getMessage().indexOf("TestString") > 0);
}
}
@Test
public void testReadBigDecimalByNameInvalid() throws Exception {
try {
tuple.getBigDecimal("String");
fail("field value is not a number, exception expected");
}
catch (ConversionFailedException e) {
assertTrue(e.getMessage().indexOf("TestString") > 0);
}
}
@Test
public void testReadDate() throws Exception {
assertNotNull(tuple.getDate(11));
assertNotNull(tuple.getDate("Date"));
}
@Test
public void testReadDateWithDefault() {
Date date = null;
assertEquals(date, tuple.getDateWithPattern(13, "dd-MM-yyyy", date));
assertEquals(date, tuple.getDateWithPattern("BlankInput", "dd-MM-yyyy", date));
}
@Test
public void testReadDateWithFormat() throws Exception {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Tuple t = TupleBuilder.tuple()
.setFormats(null, dateFormat)
.setConfigurableConversionService(new DefaultTupleConversionService())
.of("foo", "13/01/1999");
assertEquals(dateFormat.parse("13/01/1999"), t.getDate(0));
}
@Test
public void testReadDateInvalid() throws Exception {
try {
tuple.getDate(0);
fail("field value is not a date, exception expected");
}
catch (ConversionFailedException e) {
assertTrue(e.getMessage().indexOf("TestString") > 0);
}
}
@Test
public void testReadDateInvalidByName() throws Exception {
try {
tuple.getDate("String");
fail("field value is not a date, exception expected");
}
catch (ConversionFailedException e) {
assertTrue(e.getMessage().indexOf("TestString") > 0);
// assertTrue(e.getMessage().indexOf("name: [String]") > 0);
}
}
@Test
public void testReadDateInvalidWithPattern() throws Exception {
try {
tuple.getDateWithPattern(0, "dd-MM-yyyy");
fail("field value is not a date, exception expected");
}
catch (IllegalArgumentException e) {
assertTrue(e.getMessage().indexOf("dd-MM-yyyy") > 0);
}
}
@Test
public void testReadDateWithPatternAndDefault() {
Date date = null;
assertEquals(date, tuple.getDateWithPattern(13, "dd-MM-yyyy", date));
assertEquals(date, tuple.getDateWithPattern("BlankInput", "dd-MM-yyyy", date));
}
@Test
public void testStrictReadDateWithPattern() throws Exception {
Tuple t = tuple().of("foo", "50-2-13");
try {
t.getDateWithPattern(0, "dd-MM-yyyy");
fail("field value is not a valid date for strict parser, exception expected");
}
catch (IllegalArgumentException e) {
String message = e.getMessage();
assertTrue("Message did not contain: " + message, message.indexOf("dd-MM-yyyy") > 0);
}
}
@Test
public void testStrictReadDateWithPatternAndStrangeDate() throws Exception {
Tuple t = tuple().of("foo", "5550212");
try {
System.err.println(t.getDateWithPattern(0, "yyyyMMdd"));
fail("field value is not a valid date for strict parser, exception expected");
}
catch (IllegalArgumentException e) {
String message = e.getMessage();
assertTrue("Message did not contain: " + message, message.indexOf("yyyyMMdd") > 0);
}
}
@Test
public void testReadDateByNameInvalidWithPattern() throws Exception {
try {
tuple.getDateWithPattern("String", "dd-MM-yyyy");
fail("field value is not a date, exception expected");
}
catch (IllegalArgumentException e) {
assertTrue(e.getMessage().indexOf("dd-MM-yyyy") > 0);
assertTrue(e.getMessage().indexOf("String") > 0);
}
}
@Test
public void testPaddedLong() {
Tuple t = tuple().of("foo", "00000009");
// FieldSet fs = new DefaultFieldSet(new String[] { "00000009" });
long value = t.getLong(0);
assertEquals(value, 9);
}
@Test
public void testReadRawString() {
String name = "fieldName";
String value = " string with trailing whitespace ";
Tuple t = tuple().of(name, value);
assertEquals(value, t.getRawString(0));
assertEquals(value, t.getRawString(name));
}
}

View File

@@ -1,497 +0,0 @@
/*
* Copyright 2013 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
*
* http://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.tuple;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.sameInstance;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.springframework.cloud.stream.tuple.TupleBuilder.tuple;
import java.awt.Color;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.core.convert.ConverterNotFoundException;
public class DefaultTupleTests {
@Test(expected = IllegalArgumentException.class)
public void nullForNameArray() {
List<Object> values = new ArrayList<Object>();
values.add("bar");
tuple().ofNamesAndValues(null, values);
}
@Test(expected = IllegalArgumentException.class)
public void nullForValueArray() {
List<String> names = new ArrayList<String>();
names.add("foo");
tuple().ofNamesAndValues(names, null);
}
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void notEqualNumberOfNamesAndValues() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Field names must be same length as values: names=[foo, oof], values=[bar]");
List<String> names = new ArrayList<String>();
names.add("foo");
names.add("oof");
List<Object> values = new ArrayList<Object>();
values.add("bar");
tuple().ofNamesAndValues(names, values);
}
@Test
public void accessNonExistentEntry() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Field name [does-not-exist] does not exist");
Tuple tuple = TupleBuilder.tuple().of("foo", "bar");
Object v = tuple.getValue("does-not-exist");
assertThat(v, nullValue());
}
@Test
public void singleEntry() {
Tuple tuple = TupleBuilder.tuple().of("foo", "bar");
assertThat(tuple.size(), equalTo(1));
List<String> names = tuple.getFieldNames();
assertThat(names.get(0), equalTo("foo"));
assertThat((String) tuple.getValue("foo"), equalTo("bar"));
assertThat(tuple.hasFieldName("foo"), equalTo(true));
assertThat(tuple.getValue("foo").toString(), equalTo("bar"));
}
@Test
public void twoEntries() {
Tuple tuple = TupleBuilder.tuple().of("up", "down", "charm", "strange");
assertTwoEntries(tuple);
}
@Test
public void testTupleAsValue() {
Tuple t1 = tuple().of("up", 1, "down", 2);
Tuple t2 = tuple().of("1stgen", t1, "charm", 3, "strange", 4);
assertThat(t2.size(), equalTo(3));
Tuple t3 = t2.getTuple(0);
assertThat(t3.size(), equalTo(2));
assertThat(t3.getFieldNames().get(0), equalTo("up"));
assertThat(t3.getFieldNames().get(1), equalTo("down"));
assertThat(t3.getInt("up"), equalTo(1));
assertThat(t3.getInt("down"), equalTo(2));
Tuple t4 = t2.getTuple("1stgen");
assertThat(t3, equalTo(t4));
}
/**
* @param tuple
*/
private void assertTwoEntries(Tuple tuple) {
assertThat(tuple.size(), equalTo(2));
assertThat(tuple.getFieldNames().get(0), equalTo("up"));
assertThat(tuple.getFieldNames().get(1), equalTo("charm"));
assertThat((String) tuple.getValue("up"), equalTo("down"));
assertThat((String) tuple.getValue("charm"), equalTo("strange"));
}
@Test
public void threeEntries() {
Tuple tuple = TupleBuilder.tuple().of("up", 1, "charm", 2, "top", 3);
assertThat(tuple.size(), equalTo(3));
assertThat(tuple.getFieldNames().get(0), equalTo("up"));
assertThat(tuple.getFieldNames().get(1), equalTo("charm"));
assertThat(tuple.getFieldNames().get(2), equalTo("top"));
// access by name
assertThat((Integer) tuple.getValue("up"), equalTo(1));
assertThat((Integer) tuple.getValue("charm"), equalTo(2));
assertThat((Integer) tuple.getValue("top"), equalTo(3));
// access by position
assertThat((Integer) tuple.getValue(0), equalTo(1));
assertThat((Integer) tuple.getValue(1), equalTo(2));
assertThat((Integer) tuple.getValue(2), equalTo(3));
// access from separate collection
List<Object> values = tuple.getValues();
assertThat((Integer) values.get(0), equalTo(1));
assertThat((Integer) values.get(1), equalTo(2));
assertThat((Integer) values.get(2), equalTo(3));
}
@Test
public void fourEntries() {
Tuple tuple = TupleBuilder.tuple().of("up", 1, "charm", 2, "top", 3, "e", 4);
assertThat(tuple.size(), equalTo(4));
assertThat(tuple.getFieldNames().get(0), equalTo("up"));
assertThat(tuple.getFieldNames().get(1), equalTo("charm"));
assertThat(tuple.getFieldNames().get(2), equalTo("top"));
assertThat(tuple.getFieldNames().get(3), equalTo("e"));
// access by name
assertThat((Integer) tuple.getValue("up"), equalTo(1));
assertThat((Integer) tuple.getValue("charm"), equalTo(2));
assertThat((Integer) tuple.getValue("top"), equalTo(3));
assertThat((Integer) tuple.getValue("e"), equalTo(4));
// access by position
assertThat((Integer) tuple.getValue(0), equalTo(1));
assertThat((Integer) tuple.getValue(1), equalTo(2));
assertThat((Integer) tuple.getValue(2), equalTo(3));
assertThat((Integer) tuple.getValue(3), equalTo(4));
}
@Test
public void getValue() {
Tuple tuple = TupleBuilder.tuple().of("up", 1, "charm", 2.0, "top", true);
assertThat(tuple.getValue(0, Integer.class), equalTo(1));
assertThat(tuple.getValue(0, String.class), equalTo("1"));
assertThat(tuple.getValue(1, Double.class), equalTo(2.0D));
assertThat(tuple.getValue(2, Boolean.class), equalTo(true));
assertThat(tuple.getValue(2, String.class), equalTo("true"));
assertThat(tuple.getValue("up", Integer.class), equalTo(1));
assertThat(tuple.getValue("up", String.class), equalTo("1"));
assertThat(tuple.getValue("charm", Double.class), equalTo(2.0D));
assertThat(tuple.getValue("top", Boolean.class), equalTo(true));
assertThat(tuple.getValue("top", String.class), equalTo("true"));
}
@Test
public void testPrimitiveGetters() {
Tuple tuple = TupleBuilder.tuple().of("up", "down", "charm", 2.0, "top", true);
assertThat(tuple.getBoolean("top"), equalTo(true));
assertThat(tuple.getBoolean(2), equalTo(true));
assertThat(tuple.getBoolean("up", "down"), equalTo(true));
}
@Test
public void testToString() throws JsonProcessingException, IOException {
Tuple tuple = TupleBuilder.tuple().put("up", "down").put("charm", "strange").build();
String tupleString = tuple.toString();
// valid JSON
new ObjectMapper().readTree(tupleString);
Tuple tupleFromString = TupleBuilder.fromString(tupleString);
assertEquals(2, tupleFromString.getFieldCount());
assertEquals("down", tupleFromString.getString("up"));
assertEquals("strange", tupleFromString.getString("charm"));
}
@Test
public void testPutApi() {
TupleBuilder builder = TupleBuilder.tuple();
Tuple tuple = builder.put("up", "down").put("charm", "strange").build();
assertTwoEntries(tuple);
}
@Test
public void testPutAllApi() {
Tuple tuple = TupleBuilder.tuple().put("red", "rot").put("brown", "braun").put("blue", "blau").put("yellow", "gelb")
.put("beige", "beige").build();
assertThat(tuple.size(), equalTo(5));
Tuple tuplePlusOne = TupleBuilder.tuple().putAll(tuple).put("up", 1).build();
assertThat(tuplePlusOne.size(), equalTo(6));
assertThat(tuplePlusOne.getFieldNames().get(0), equalTo("red"));
assertThat(tuplePlusOne.getFieldNames().get(5), equalTo("up"));
}
@Test
public void testEqualsAndHashCodeSunnyDay() {
Tuple tuple1 = TupleBuilder.tuple().of("up", 1, "charm", 2, "top", 3);
Tuple tuple2 = TupleBuilder.tuple().of("up", 1, "charm", 2, "top", 3);
assertThat(tuple1, equalTo(tuple2));
assertThat(tuple1.hashCode(), equalTo(tuple2.hashCode()));
assertThat(tuple1, not(sameInstance(tuple2)));
}
@Test
public void testEqualsAndHashFailureCases() {
Tuple tuple1 = TupleBuilder.tuple().of("up", 1, "charm", 2, "top", 3);
Tuple tuple2 = TupleBuilder.tuple().of("up", 2, "charm", 3, "top", 4);
assertThat(tuple1, not(equalTo((tuple2))));
assertThat(tuple1.hashCode(), not(equalTo(tuple2.hashCode())));
tuple1 = TupleBuilder.tuple().of("up", 1, "charm", 2, "top", 3);
tuple2 = TupleBuilder.tuple().of("top", 1, "charm", 2, "up", 3);
assertThat(tuple1, not(equalTo((tuple2))));
assertThat(tuple1.hashCode(), not(equalTo(tuple2.hashCode())));
}
@SuppressWarnings("rawtypes")
@Test
public void testGetFieldTypes() {
Tuple tuple = TupleBuilder.tuple().of("up", 1, "charm", 2, "top", 3);
Class[] expectedTypes = new Class[] { Integer.class, Integer.class, Integer.class };
assertThat(tuple.getFieldTypes(), equalTo(Arrays.asList(expectedTypes)));
tuple = TupleBuilder.tuple().of("up", 1, "charm", 2.0f, "top", "bottom");
expectedTypes = new Class[] { Integer.class, Float.class, String.class };
assertThat(tuple.getFieldTypes(), equalTo(Arrays.asList(expectedTypes)));
tuple = TupleBuilder.tuple().of("up", 1, "charm", 2.0, "top", true);
expectedTypes = new Class[] { Integer.class, Double.class, Boolean.class };
assertThat(tuple.getFieldTypes(), equalTo(Arrays.asList(expectedTypes)));
}
@Test
public void testGetString() {
// test conversions of string, int, and float.
Tuple tuple = TupleBuilder.tuple().of("up", "down", "charm", 2, "top", 2.0f);
assertThat(tuple.getString("up"), equalTo("down"));
assertThat(tuple.getString("charm"), equalTo("2"));
assertThat(tuple.getString("top"), equalTo("2.0"));
}
@Test
public void testGetNullValue() {
Tuple tuple = tuple().of("foo", null);
// non primitive types will return null
assertThat(tuple.getString("foo"), nullValue());
assertThat(tuple.getBigDecimal("foo"), nullValue());
assertThat(tuple.getDate("foo"), nullValue());
// primitive types will return default values
assertThat(tuple.getChar("foo"), equalTo('\u0000'));
assertThat(tuple.getBoolean("foo"), equalTo(false));
byte b = 0;
assertThat(tuple.getByte("foo"), equalTo(b));
short s = 0;
assertThat(tuple.getShort("foo"), equalTo(s));
assertThat(tuple.getInt("foo"), equalTo(0));
assertThat(tuple.getLong("foo"), equalTo(0L));
assertThat(tuple.getFloat("foo"), equalTo(0f));
assertThat(tuple.getDouble("foo"), equalTo(0d));
}
@Test
public void testGetStringThatFails() {
Tuple tuple = TupleBuilder.tuple().of("up", "down", "charm", 2, "top", 2.0f, "black", Color.black);
thrown.expect(ConverterNotFoundException.class);
thrown.expectMessage(allOf(containsString("No converter found capable of converting from type"),
containsString("java.awt.Color"),
containsString("java.lang.String")));
assertThat(tuple.getString("black"), equalTo("omg"));
}
@Test
public void testSelection() {
Tuple tuple = tuple().put("red", "rot").put("brown", "braun").put("blue", "blau").put("yellow", "gelb")
.put("beige", "beige").build();
Tuple selectedTuple = tuple.select("?[key.startsWith('b')]");
assertThat(selectedTuple.size(), equalTo(3));
selectedTuple = tuple.select("^[key.startsWith('b')]");
assertThat(selectedTuple.size(), equalTo(1));
assertThat(selectedTuple.getFieldNames().get(0), equalTo("brown"));
assertThat(selectedTuple.getString(0), equalTo("braun"));
selectedTuple = tuple.select("?[value.length() < 4]");
assertThat(selectedTuple.size(), equalTo(1));
assertThat(selectedTuple.getFieldNames().get(0), equalTo("red"));
assertThat(selectedTuple.getString(0), equalTo("rot"));
}
@Test
public void testReadByteWithDefault() {
// with a value
byte b = 1;
Tuple t = tuple().of("foo", b);
byte defaultByte = 2;
assertTrue(t.getByte(0, defaultByte) == b);
assertTrue(t.getByte("foo", defaultByte) == b);
assertTrue(t.getByte("bar", defaultByte) == defaultByte);
// with a null value
t = tuple().of("foo", null);
assertTrue(t.getByte(0, defaultByte) == defaultByte);
assertTrue(t.getByte("foo", defaultByte) == defaultByte);
assertTrue(t.getByte("bar", defaultByte) == defaultByte);
}
@Test
public void testReadShortWithDefault() {
// with a value
short s = 1;
Tuple t = tuple().of("foo", s);
short defaultShort = 2;
assertTrue(t.getShort(0, defaultShort) == s);
assertTrue(t.getShort("foo", defaultShort) == s);
assertTrue(t.getShort("bar", defaultShort) == defaultShort);
// with a null value
t = tuple().of("foo", null);
assertTrue(t.getShort(0, defaultShort) == defaultShort);
assertTrue(t.getShort("foo", defaultShort) == defaultShort);
assertTrue(t.getShort("bar", defaultShort) == defaultShort);
}
@Test
public void testReadIntWithDefault() {
// with a value
int i = 1;
Tuple t = tuple().of("foo", i);
int defaultInt = 2;
assertTrue(t.getInt(0, defaultInt) == i);
assertTrue(t.getInt("foo", defaultInt) == i);
assertTrue(t.getInt("bar", defaultInt) == defaultInt);
// with a null value
t = tuple().of("foo", null);
assertTrue(t.getInt(0, defaultInt) == defaultInt);
assertTrue(t.getInt("foo", defaultInt) == defaultInt);
assertTrue(t.getInt("bar", defaultInt) == defaultInt);
}
@Test
public void testReadLongWithDefault() {
// with a value
long l = 1;
Tuple t = tuple().of("foo", l);
int defaultLong = 2;
assertTrue(t.getLong(0, defaultLong) == l);
assertTrue(t.getLong("foo", defaultLong) == l);
assertTrue(t.getLong("bar", defaultLong) == defaultLong);
// with a null value
t = tuple().of("foo", null);
assertTrue(t.getLong(0, defaultLong) == defaultLong);
assertTrue(t.getLong("foo", defaultLong) == defaultLong);
assertTrue(t.getLong("bar", defaultLong) == defaultLong);
}
@Test
public void testReadFloatWithDefault() {
// with a value
float f = 1;
Tuple t = tuple().of("foo", f);
float defaultFloat = 2.0f;
assertTrue(t.getFloat(0, defaultFloat) == f);
assertTrue(t.getFloat("foo", defaultFloat) == f);
assertTrue(t.getFloat("bar", defaultFloat) == defaultFloat);
// with a null value
t = tuple().of("foo", null);
assertTrue(t.getFloat(0, defaultFloat) == defaultFloat);
assertTrue(t.getFloat("foo", defaultFloat) == defaultFloat);
assertTrue(t.getFloat("bar", defaultFloat) == defaultFloat);
}
@Test
public void testReadDoubleWithDefault() {
// with a value
double d = 1;
Tuple t = tuple().of("foo", d);
double defaultDouble = 2.0d;
assertTrue(t.getDouble(0, defaultDouble) == d);
assertTrue(t.getDouble("foo", defaultDouble) == d);
assertTrue(t.getDouble("bar", defaultDouble) == defaultDouble);
// with a null value
t = tuple().of("foo", null);
assertTrue(t.getDouble(0, defaultDouble) == defaultDouble);
assertTrue(t.getDouble("foo", defaultDouble) == defaultDouble);
assertTrue(t.getDouble("bar", defaultDouble) == defaultDouble);
}
@Test
public void testReadBigDecimalWithDefault() {
// with a value
BigDecimal bd = new BigDecimal(1);
Tuple t = tuple().of("foo", bd);
BigDecimal defaultBigDecimal = new BigDecimal(2);
assertTrue(t.getBigDecimal(0, defaultBigDecimal) == bd);
assertTrue(t.getBigDecimal("foo", defaultBigDecimal) == bd);
assertTrue(t.getBigDecimal("bar", defaultBigDecimal) == defaultBigDecimal);
// with a null value
t = tuple().of("foo", null);
assertTrue(t.getBigDecimal(0, defaultBigDecimal) == defaultBigDecimal);
assertTrue(t.getBigDecimal("foo", defaultBigDecimal) == defaultBigDecimal);
assertTrue(t.getBigDecimal("bar", defaultBigDecimal) == defaultBigDecimal);
}
@Test
public void testReadDateWithDefault() throws InterruptedException {
// with a value
Date date = new Date();
Tuple t = tuple().of("foo", date);
Thread.sleep(1000);
Date defaultDate = new Date();
assertTrue(t.getDate(0, defaultDate) == date);
assertTrue(t.getDate("foo", defaultDate) == date);
assertTrue(t.getDate("bar", defaultDate) == defaultDate);
// with a null value
t = tuple().of("foo", null);
assertTrue(t.getDate(0, defaultDate) == defaultDate);
assertTrue(t.getDate("foo", defaultDate) == defaultDate);
assertTrue(t.getDate("bar", defaultDate) == defaultDate);
}
@Test
public void testReadDateWithPattern() throws ParseException, InterruptedException {
Tuple t = tuple().of("foo", "24-12-2013");
Date d = t.getDateWithPattern(0, "dd-MM-yyyy");
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
assertEquals(dateFormat.parse("24-12-2013"), d);
Thread.sleep(1000);
Date defaultDate = new Date();
assertTrue(t.getDateWithPattern("foo", "xyz-abc", defaultDate) == defaultDate);
assertTrue(t.getDateWithPattern(0, "xyz-abc", defaultDate) == defaultDate);
}
@Test
public void testCollectionToTupleConversionFails() {
thrown.expect(ConverterNotFoundException.class);
Tuple t1 = tuple().of("hello", "world");
Tuple t2 = tuple().of("foo", "bar");
List<Tuple> list = Arrays.asList(t1, t2);
Tuple t = tuple().of("list", list);
t.getTuple("list");
}
}

View File

@@ -1,34 +0,0 @@
/*
* Copyright 2002-2013 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
*
* http://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.tuple;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* @author David Turanski
*
*/
public class JsonBytesToTupleConverterTests {
private JsonBytesToTupleConverter converter = new JsonBytesToTupleConverter();
@Test
public void testSimple() {
String json = "{\"symbol\":\"VMW\",\"price\":73}";
Tuple t = converter.convert(json.getBytes());
assertEquals("VMW", t.getValue("symbol"));
}
}

View File

@@ -1,38 +0,0 @@
/*
* Copyright 2014 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
*
* http://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.tuple;
import org.junit.Test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import static org.junit.Assert.assertEquals;
public class SpringToDateConverterTests {
@Test
public void testCtor() throws ParseException {
StringToDateConverter converter = new StringToDateConverter();
Date d = converter.convert("2013-05-02");
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
assertEquals(dateFormat.parse("2013-05-02"), d);
}
}

View File

@@ -1,80 +0,0 @@
/*
* Copyright 2002-2013 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
*
* http://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.tuple;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import java.io.IOException;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* @author David Turanski
*
*/
public class TupleJsonMarshallerTests extends AbstractTupleMarshallerTests {
/*
* (non-Javadoc)
*
* @see org.springframework.xd.tuple.AbstractTupleMarshallerTests#getMarshaller()
*/
@Override
protected TupleJsonMarshaller getMarshaller() {
return new TupleJsonMarshaller();
}
@Test
public void testComplexJson() throws IOException {
Resource jsonFile = new ClassPathResource("/tweet.json");
assertTrue(jsonFile.exists());
String source = readJson(jsonFile);
TupleJsonMarshaller marshaller = getMarshaller();
Tuple tuple = marshaller.toTuple(source);
assertEquals("Gabriel", tuple.getTuple("user").getString("name"));
List<?> mentions = (List<?>) tuple.getTuple("entities").getValue("user_mentions");
assertEquals(2, mentions.size());
assertTrue(mentions.get(0) instanceof Tuple);
Tuple t = (Tuple) mentions.get(0);
assertEquals("someoneFollowed", t.getString("screen_name"));
}
@Test
public void testJsonWithArrays() throws IOException {
Resource jsonFile = new ClassPathResource("/jsonWithArrays.json");
assertTrue(jsonFile.exists());
String json = readJson(jsonFile);
//Convert to tuple
TupleJsonMarshaller marshaller = getMarshaller();
Tuple tuple = marshaller.toTuple(json);
//Validate contents
List<Tuple> body = (List<Tuple>) tuple.getValue("body");
Tuple t2 = body.get(0).getTuple("har");
Tuple t3 = t2.getTuple("log");
List<?> pages = (List<?>)t3.getValue("pages");
assertEquals(2, pages.size());
//Convert back to json.
String convertedJson = prettyPrintJson(marshaller.fromTuple(tuple));
assertEquals(json, convertedJson);
}
}

View File

@@ -1,171 +0,0 @@
/*
* Copyright 2016 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
*
* http://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.tuple.spel;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cloud.stream.tuple.Tuple;
import org.springframework.cloud.stream.tuple.TupleBuilder;
import org.springframework.expression.spel.SpelEvaluationException;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
/**
* Unit tests for {@link TuplePropertyAccessor}.
*
* @author Eric Bottard
* @author Mark Fisher
*/
public class TuplePropertyAccessorTests {
private final SpelExpressionParser parser = new SpelExpressionParser();
private final StandardEvaluationContext context = new StandardEvaluationContext();
@Before
public void setup() {
this.context.addPropertyAccessor(new TuplePropertyAccessor());
}
@Test
public void testSimplePropertyByFieldName() {
Tuple tuple = TupleBuilder.tuple().of("foo", "bar");
String result = evaluate("foo", tuple, String.class);
assertThat(result, is("bar"));
}
@Test
public void testSimplePropertyByIndex() {
Tuple tuple = TupleBuilder.tuple().of("foo", "bar");
String result = evaluate("['0']", tuple, String.class);
assertThat(result, is("bar"));
}
@Test(expected = SpelEvaluationException.class)
public void failOnNegativeIndex() {
Tuple tuple = TupleBuilder.tuple().of("foo", "bar");
evaluate("['-3']", tuple, String.class);
}
@Test
public void testNestedPropertyByFieldName() {
Tuple child = TupleBuilder.tuple().of("b", 123);
Tuple tuple = TupleBuilder.tuple().of("a", child);
int result = evaluate("a.b", tuple, Integer.class);
assertThat(result, is(123));
}
@Test
public void testNestedPropertyByIndex() {
Tuple child = TupleBuilder.tuple().of("b", 123);
Tuple tuple = TupleBuilder.tuple().of("a", child);
int result = evaluate("a['0']", tuple, Integer.class);
assertThat(result, is(123));
}
@Test
public void testNestedPropertyByIndexOnly() {
Tuple child = TupleBuilder.tuple().of("b", 123);
Tuple tuple = TupleBuilder.tuple().of("a", child);
int result = evaluate("['0']['0']", tuple, Integer.class);
assertThat(result, is(123));
}
@Test
public void testArrayPropertyByFieldName() {
Tuple tuple = TupleBuilder.tuple().of("numbers", new Integer[] { 1, 2, 3 });
int result = evaluate("numbers[1]", tuple, Integer.class);
assertThat(result, is(2));
}
@Test
public void testArrayPropertyByIndex() {
Tuple tuple = TupleBuilder.tuple().of("numbers", new Integer[] { 1, 2, 3 });
int result = evaluate("['0'][0]", tuple, Integer.class);
assertThat(result, is(1));
}
@Test
public void testNestedArrayPropertyByFieldName() {
Tuple child = TupleBuilder.tuple().of("numbers", new Integer[] { 7, 8, 9 });
Tuple tuple = TupleBuilder.tuple().of("child", child);
int result = evaluate("child.numbers[1]", tuple, Integer.class);
assertThat(result, is(8));
}
@Test
public void testNestedArrayPropertyByIndex() {
Tuple child = TupleBuilder.tuple().of("numbers", new Integer[] { 7, 8, 9 });
Tuple tuple = TupleBuilder.tuple().of("child", child);
int result = evaluate("child['0'][2]", tuple, Integer.class);
assertThat(result, is(9));
}
@Test
public void testNestedArrayPropertyByIndexOnly() {
Tuple child = TupleBuilder.tuple().of("numbers", new Integer[] { 7, 8, 9 });
Tuple tuple = TupleBuilder.tuple().of("child", child);
int result = evaluate("['0']['0'][1]", tuple, Integer.class);
assertThat(result, is(8));
}
// Write
@Test
public void testSimpleWriteOnExistingProperty() {
Tuple tuple = TupleBuilder.mutableTuple().of("foo", "bar");
write("foo", tuple, 123);
assertThat(tuple.getInt("foo"), is(123));
}
@Test
public void testSimpleWriteOnNewProperty() {
Tuple tuple = TupleBuilder.mutableTuple().of("foo", "bar");
write("other", tuple, 123);
assertThat(tuple.getInt("other"), is(123));
assertThat(tuple.getValue("foo"), CoreMatchers.<Object>is("bar"));
}
@Test
public void testSimpleWriteOnExistingPropertyByIndex() {
Tuple tuple = TupleBuilder.mutableTuple().of("foo", "bar");
write("['0']", tuple, 123);
assertThat(tuple.getInt("foo"), is(123));
}
@Test
public void testSimpleWriteOnNewPropertyByIndex() {
Tuple tuple = TupleBuilder.mutableTuple().of("foo", "bar");
write("['12']", tuple, 123);
assertThat(tuple.getInt("12"), is(123));
assertThat(tuple.getValue("foo"), CoreMatchers.<Object>is("bar"));
}
private <T> T evaluate(String expression, Tuple tuple, Class<T> expectedType) {
return parser.parseExpression(expression).getValue(this.context, tuple, expectedType);
}
private void write(String expression, Tuple tuple, Object value) {
parser.parseExpression(expression).setValue(this.context, tuple, value);
}
}

View File

@@ -1,53 +0,0 @@
{
"body" : [ {
"dataType" : "har",
"har" : {
"log" : {
"browser" : {
"name" : "Google Chrome",
"version" : "44.0.2403.155"
},
"creator" : {
"name" : "My extension",
"version" : "0.23.6"
},
"pages" : [ {
"_requestTimings" : {
"blocked" : -1,
"connect" : -1,
"dns" : -1,
"receive" : 11,
"send" : -1,
"ssl" : -1,
"wait" : null
},
"_requestUrl" : "https://google.com"
}, {
"_requestTimings" : {
"blocked" : -1,
"connect" : -1,
"dns" : -1,
"receive" : 11,
"send" : -1,
"ssl" : -1,
"wait" : 244
},
"_requestUrl" : "https://google.com"
} ],
"version" : "1.2"
}
},
"testId" : 1
} ],
"bodyType" : "models.MultiMessage",
"headers" : {
"appInstance" : "localhost/127.0.0.1:8080",
"clientIp" : "0:0:0:0:0:0:0:1",
"host" : "localhost:8080",
"requestId" : "27acf948-33ff-491c-8be7-1beb4b8c95d9",
"requestMethod" : "POST",
"requestUrl" : "http://localhost:8080/har",
"timestamp" : 1445914510549,
"userPrincipal" : "235"
}
}

View File

@@ -1 +0,0 @@
{"created_at":"Mon Jul 15 14:00:51 +0000 2013","id":1234567890000000,"id_str":"1234567890000000","text":"@someoneFollowed @ScreenName Hi","source":"web","truncated":false,"in_reply_to_status_id":1234567890,"in_reply_to_status_id_str":"1234567890","in_reply_to_user_id":12345678,"in_reply_to_user_id_str":"12345678","in_reply_to_screen_name":"someoneFollowed","user":{"id":1447674373,"id_str":"1447674373","name":"Gabriel","screen_name":"Django","location":"\u2661 Mile \u2661 Alice \u2661 Lia \u2661 ","url":null,"description":"\u25bd F\u00e3 this is a description \u25b3","protected":false,"followers_count":1569,"friends_count":1525,"listed_count":0,"created_at":"Wed May 22 01:13:27 +0000 2013","favourites_count":45,"utc_offset":-10800,"time_zone":"Brasilia","geo_enabled":false,"verified":false,"statuses_count":7930,"lang":"pt","contributors_enabled":false,"is_translator":false,"profile_background_color":"FFFFFF","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/8888000000\/abc.png","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/888800000013245\/abc.png","profile_background_tile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/88000000\/449e706e706ba4574eab44904c97ed0d_normal.png","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/8888000000888888\/0_normal.png","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/12345678\/12345678","profile_link_color":"5374BA","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"E6E6E6","profile_text_color":"2EC7D7","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"symbols":[],"urls":[],"user_mentions":[{"screen_name":"someoneFollowed","name":"Someone Followed","id":12345678,"id_str":"12345678","indices":[0,13]},{"screen_name":"ScreenName","name":"My Name","id":86754321,"id_str":"86754321","indices":[14,27]}]},"favorited":false,"retweeted":false,"filter_level":"medium","lang":"und"}

View File

@@ -31,8 +31,12 @@
<artifactId>spring-integration-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-tuple</artifactId>
<groupId>org.springframework</groupId>
<artifactId>spring-tuple</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-tuple</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>

View File

@@ -42,7 +42,6 @@ import org.springframework.cloud.stream.binding.MessageChannelConfigurer;
import org.springframework.cloud.stream.binding.MessageConverterConfigurer;
import org.springframework.cloud.stream.binding.MessageHistoryTrackerConfigurer;
import org.springframework.cloud.stream.binding.OutputBindingLifecycle;
import org.springframework.cloud.stream.tuple.spel.TuplePropertyAccessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
@@ -55,6 +54,7 @@ import org.springframework.integration.support.MessageBuilderFactory;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.core.DestinationResolutionException;
import org.springframework.messaging.core.DestinationResolver;
import org.springframework.tuple.spel.TuplePropertyAccessor;
/**
* Configuration class that provides necessary beans for {@link MessageChannel} binding.

View File

@@ -20,10 +20,10 @@ import java.util.ArrayList;
import java.util.List;
import org.springframework.messaging.Message;
import org.springframework.tuple.Tuple;
import org.springframework.tuple.TupleBuilder;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
import org.springframework.cloud.stream.tuple.Tuple;
import org.springframework.cloud.stream.tuple.TupleBuilder;
/**

View File

@@ -20,10 +20,10 @@ import static org.springframework.util.MimeType.valueOf;
import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON;
import static org.springframework.util.MimeTypeUtils.APPLICATION_OCTET_STREAM;
import org.springframework.tuple.DefaultTuple;
import org.springframework.tuple.Tuple;
import org.springframework.util.ClassUtils;
import org.springframework.util.MimeType;
import org.springframework.cloud.stream.tuple.DefaultTuple;
import org.springframework.cloud.stream.tuple.Tuple;
import org.springframework.util.StringUtils;

View File

@@ -15,9 +15,9 @@
*/
package org.springframework.cloud.stream.converter;
import org.springframework.cloud.stream.tuple.Tuple;
import org.springframework.cloud.stream.tuple.TupleBuilder;
import org.springframework.messaging.Message;
import org.springframework.tuple.Tuple;
import org.springframework.tuple.TupleBuilder;
import org.springframework.util.MimeTypeUtils;

View File

@@ -20,8 +20,8 @@ import java.io.IOException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.Message;
import org.springframework.tuple.Tuple;
import org.springframework.util.MimeTypeUtils;
import org.springframework.cloud.stream.tuple.Tuple;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;