Merge pull request #10 from gregturn/DATAREDIS-190
Add alternate constructor to MessageListenerAdapter
This commit is contained in:
@@ -105,6 +105,7 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Costin Leau
|
||||
* @author Greg Turnquist
|
||||
* @see org.springframework.jms.listener.adapter.MessageListenerAdapter
|
||||
*/
|
||||
public class MessageListenerAdapter implements InitializingBean, MessageListener {
|
||||
@@ -206,6 +207,19 @@ public class MessageListenerAdapter implements InitializingBean, MessageListener
|
||||
initDefaultStrategies();
|
||||
setDelegate(delegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link MessageListenerAdapter} for the given delegate.
|
||||
*
|
||||
* @param delegate the delegate object
|
||||
* @param defaultListenerMethod method to call when a message comes
|
||||
*
|
||||
* @see #getListenerMethodName
|
||||
*/
|
||||
public MessageListenerAdapter(Object delegate, String defaultListenerMethod) {
|
||||
this(delegate);
|
||||
setDefaultListenerMethod(defaultListenerMethod);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a target object to delegate message listening to. Specified listener
|
||||
|
||||
@@ -27,17 +27,17 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.data.redis.connection.DefaultMessage;
|
||||
import org.springframework.data.redis.connection.Message;
|
||||
import org.springframework.data.redis.connection.MessageListener;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
/**
|
||||
* Unit test for MessageListenerAdapter.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
public class MessageListenerTest {
|
||||
|
||||
private static final RedisSerializer serializer = new StringRedisSerializer();
|
||||
private static final StringRedisSerializer serializer = new StringRedisSerializer();
|
||||
private static final String CHANNEL = "some::test:";
|
||||
private static final byte[] RAW_CHANNEL = serializer.serialize(CHANNEL);
|
||||
private static final String PAYLOAD = "do re mi";
|
||||
@@ -107,6 +107,16 @@ public class MessageListenerTest {
|
||||
verify(target).customMethod(PAYLOAD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomMethodWithAlternateConstructor() throws Exception {
|
||||
MessageListenerAdapter adapter = new MessageListenerAdapter(target, "customMethod");
|
||||
adapter.afterPropertiesSet();
|
||||
|
||||
adapter.onMessage(STRING_MSG, null);
|
||||
|
||||
verify(target).customMethod(PAYLOAD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomMethodWithChannel() throws Exception {
|
||||
MessageListenerAdapter adapter = new MessageListenerAdapter(target);
|
||||
@@ -118,6 +128,16 @@ public class MessageListenerTest {
|
||||
verify(target).customMethodWithChannel(PAYLOAD, CHANNEL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomMethodWithChannelAndAlternateConstructor() throws Exception {
|
||||
MessageListenerAdapter adapter = new MessageListenerAdapter(target, "customMethodWithChannel");
|
||||
adapter.afterPropertiesSet();
|
||||
|
||||
adapter.onMessage(STRING_MSG, RAW_CHANNEL);
|
||||
|
||||
verify(target).customMethodWithChannel(PAYLOAD, CHANNEL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-92
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user