Skip to content

Commit

Permalink
AMQP-360 Update Versions; Align with SI/SF 4
Browse files Browse the repository at this point in the history
JIRA: https://jira.springsource.org/browse/AMQP-360

Note: The changes to the RabbitBrokerAdmin test rules are simply
to make them work with junit 4.11 - these tests (controlled by
a System property) currently do no run and will be addressed by
a separate JIRA.

RabbitBrokerAdmin is not part of the main Spring-AMQP runtime.
  • Loading branch information
garyrussell authored and Artem Bilan committed Mar 3, 2014
1 parent fe88307 commit d5494f4
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 116 deletions.
24 changes: 14 additions & 10 deletions build.gradle
Expand Up @@ -57,17 +57,20 @@ subprojects { subproject ->
targetCompatibility=1.6

ext {
cglibVersion = '2.2'
commonsIoVersion = '1.4'
erlangOtpVersion = '1.5.3'
jacksonVersion = '1.4.3'
jackson2Version = '2.0.1'
junitVersion = '4.8.2'
log4jVersion = '1.2.15'
mockitoVersion = '1.8.4'
rabbitmqVersion = '3.2.2'
cglibVersion = '3.1'
commonsIoVersion = '2.4'
erlangOtpVersion = '1.5.6'
hamcrestVersion = '1.3'
jacksonVersion = '1.9.13'
jackson2Version = '2.3.1'
junitVersion = '4.11'
log4jVersion = '1.2.17'
mockitoVersion = '1.9.5'
rabbitmqVersion = '3.2.3'

springVersion = project.hasProperty('springVersion') ? project.springVersion : '3.2.7.RELEASE'

springRetryVersion = '1.0.3.RELEASE'
}

eclipse {
Expand All @@ -92,6 +95,7 @@ subprojects { subproject ->
exclude group: 'com.sun.jmx', module: 'jmxri'
}

testCompile "org.hamcrest:hamcrest-all:$hamcrestVersion"
testCompile "org.mockito:mockito-all:$mockitoVersion"
testCompile "org.springframework:spring-test:$springVersion"

Expand Down Expand Up @@ -194,7 +198,7 @@ project('spring-rabbit') {
compile "org.springframework:spring-context:$springVersion"
compile "org.springframework:spring-tx:$springVersion"

compile ("org.springframework.retry:spring-retry:1.0.3.RELEASE", optional)
compile ("org.springframework.retry:spring-retry:$springRetryVersion", optional)

testCompile "commons-cli:commons-cli:1.2"

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors. Licensed under the Apache License, Version 2.0 (the "License");
* Copyright 2002-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,
Expand All @@ -8,27 +8,26 @@
*/
package org.springframework.amqp.support.converter;

import static org.codehaus.jackson.map.type.TypeFactory.collectionType;
import static org.codehaus.jackson.map.type.TypeFactory.mapType;
import static org.codehaus.jackson.map.type.TypeFactory.type;

import java.util.Collection;
import java.util.Map;

import org.codehaus.jackson.map.type.CollectionType;
import org.codehaus.jackson.map.type.MapType;
import org.codehaus.jackson.map.type.TypeFactory;
import org.codehaus.jackson.type.JavaType;

import org.springframework.amqp.core.MessageProperties;
import org.springframework.util.ClassUtils;



/**
* @author Mark Pollack
* @author Sam Nelson
* @author Andreas Asplund
* @author Artem Bilan
* @author Gary Russell
*/
public class DefaultJavaTypeMapper extends AbstractJavaTypeMapper implements JavaTypeMapper, ClassMapper {

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public JavaType toJavaType(MessageProperties properties) {
JavaType classType = getClassIdType(retrieveHeader(properties,
getClassIdFieldName()));
Expand All @@ -39,26 +38,26 @@ public JavaType toJavaType(MessageProperties properties) {
JavaType contentClassType = getClassIdType(retrieveHeader(properties,
getContentClassIdFieldName()));
if (classType.getKeyType() == null) {
return collectionType(
(Class<? extends Collection>) classType.getRawClass(),
return CollectionType.construct(
classType.getRawClass(),
contentClassType);
}

JavaType keyClassType = getClassIdType(retrieveHeader(properties,
getKeyClassIdFieldName()));
return mapType(
(Class<? extends Map>) classType.getRawClass(), keyClassType,
return MapType.construct(
classType.getRawClass(), keyClassType,
contentClassType);

}

private JavaType getClassIdType(String classId) {
if (getIdClassMapping().containsKey(classId)) {
return type(getIdClassMapping().get(classId));
return TypeFactory.defaultInstance().constructType(getIdClassMapping().get(classId));
}

try {
return type(ClassUtils.forName(classId, getClass()
return TypeFactory.defaultInstance().constructType(ClassUtils.forName(classId, getClass()
.getClassLoader()));
}
catch (ClassNotFoundException e) {
Expand All @@ -73,6 +72,7 @@ private JavaType getClassIdType(String classId) {
}
}

@Override
public void fromJavaType(JavaType javaType, MessageProperties properties) {
addHeader(properties, getClassIdFieldName(),
javaType.getRawClass());
Expand All @@ -88,11 +88,13 @@ public void fromJavaType(JavaType javaType, MessageProperties properties) {
}
}

@Override
public void fromClass(Class<?> clazz, MessageProperties properties) {
fromJavaType(type(clazz), properties);
fromJavaType(TypeFactory.defaultInstance().constructType(clazz), properties);

}

@Override
public Class<?> toClass(MessageProperties properties) {
return toJavaType(properties).getRawClass();
}
Expand Down
Expand Up @@ -9,8 +9,6 @@

package org.springframework.amqp.support.converter;

import static org.codehaus.jackson.map.type.TypeFactory.type;

import java.io.IOException;

import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -130,7 +128,7 @@ private Object convertBytesToObject(byte[] body, String encoding,
Class<?> targetClass) throws JsonParseException,
JsonMappingException, IOException {
String contentAsString = new String(body, encoding);
return jsonObjectMapper.readValue(contentAsString, type(targetClass));
return jsonObjectMapper.readValue(contentAsString, jsonObjectMapper.constructType(targetClass));
}

@Override
Expand All @@ -154,7 +152,7 @@ protected Message createMessage(Object objectToConvert,
}

if (getClassMapper() == null) {
getJavaTypeMapper().fromJavaType(type(objectToConvert.getClass()),
getJavaTypeMapper().fromJavaType(jsonObjectMapper.constructType(objectToConvert.getClass()),
messageProperties);

}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-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.
Expand All @@ -17,8 +17,8 @@
package org.springframework.amqp.core;

import static org.junit.Assert.assertEquals;
import junit.framework.Assert;

import org.junit.Assert;
import org.junit.Test;

/**
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-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
Expand All @@ -13,10 +13,10 @@
package org.springframework.amqp.support.converter;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.containsString;
import static org.mockito.BDDMockito.given;

import java.util.HashMap;
Expand All @@ -28,6 +28,7 @@
import org.junit.runner.RunWith;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;

import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.support.converter.JsonMessageConverterTests.Foo;

Expand All @@ -47,7 +48,8 @@ public class DefaultClassMapperTest {
public void shouldThrowAnExceptionWhenClassIdNotPresent() {
try {
classMapper.toClass(props);
} catch (MessageConversionException e) {
}
catch (MessageConversionException e) {
String classIdFieldName = classMapper.getClassIdFieldName();
assertThat(e.getMessage(), containsString("Could not resolve "
+ classIdFieldName + " in header"));
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors. Licensed under the Apache License, Version 2.0 (the "License");
* Copyright 2002-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,
Expand All @@ -8,25 +8,29 @@
*/
package org.springframework.amqp.support.converter;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.CollectionType;
import com.fasterxml.jackson.databind.type.MapType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.BDDMockito.given;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.junit.Test;
import static org.junit.matchers.JUnitMatchers.containsString;
import org.junit.runner.RunWith;
import static org.mockito.BDDMockito.given;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;

import org.springframework.amqp.core.MessageProperties;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.CollectionType;
import com.fasterxml.jackson.databind.type.MapType;
import com.fasterxml.jackson.databind.type.TypeFactory;

/**
* @author James Carr
* @author Sam Nelson
Expand All @@ -40,10 +44,10 @@ public class DefaultJackson2JavaTypeMapperTest {
private final MessageProperties properties = new MessageProperties();

@SuppressWarnings("rawtypes")
private Class<ArrayList> containerClass = ArrayList.class;
private final Class<ArrayList> containerClass = ArrayList.class;

@SuppressWarnings("rawtypes")
private Class<HashMap> mapClass = HashMap.class;
private final Class<HashMap> mapClass = HashMap.class;

@Test
public void shouldThrowAnExceptionWhenClassIdNotPresent() {
Expand Down

0 comments on commit d5494f4

Please sign in to comment.