use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.
the class RedisStoreWritingMessageHandlerTests method testMapWithMapKeyExpression.
@Test
@RedisAvailable
public void testMapWithMapKeyExpression() {
RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
this.deleteKey(jcf, "foo");
String key = "foo";
RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(jcf);
handler.setKey(key);
handler.setCollectionType(CollectionType.MAP);
handler.setMapKeyExpression(new LiteralExpression(key));
handler.setBeanFactory(mock(BeanFactory.class));
try {
handler.afterPropertiesSet();
} catch (Exception e) {
fail("No exception expected:" + e.getMessage());
}
this.deleteKey(jcf, "foo");
}
use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.
the class RedisStoreWritingMessageHandlerTests method testZsetWithMapPayloadPojoAsSingleEntryHeaderKey.
@Test
@RedisAvailable
public void testZsetWithMapPayloadPojoAsSingleEntryHeaderKey() {
RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
this.deletePresidents(jcf);
String key = "presidents";
RedisZSet<Map<President, Double>> redisZset = new DefaultRedisZSet<Map<President, Double>>(key, this.initTemplate(jcf, new RedisTemplate<String, Map<President, Double>>()));
assertEquals(0, redisZset.size());
RedisTemplate<String, Map<President, Double>> template = this.initTemplate(jcf, new RedisTemplate<String, Map<President, Double>>());
RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(template);
handler.setKey(key);
handler.setCollectionType(CollectionType.ZSET);
handler.setExtractPayloadElements(false);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
Map<President, Double> presidents = new HashMap<President, Double>();
presidents.put(new President("John Adams"), 18D);
presidents.put(new President("Barack Obama"), 21D);
presidents.put(new President("Thomas Jefferson"), 19D);
Message<Map<President, Double>> message = MessageBuilder.withPayload(presidents).setHeader("redis_key", key).build();
handler.handleMessage(message);
assertEquals(1, redisZset.size());
this.deletePresidents(jcf);
}
use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.
the class RedisMessageGroupStoreTests method testRemoveNonExistingMessageFromNonExistingTheGroup.
@Test
@RedisAvailable
public void testRemoveNonExistingMessageFromNonExistingTheGroup() {
RedisConnectionFactory jcf = getConnectionFactoryForTest();
RedisMessageStore store = new RedisMessageStore(jcf);
store.removeMessagesFromGroup(this.groupId, new GenericMessage<>("2"));
}
use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.
the class RedisMessageGroupStoreTests method testCompleteMessageGroup.
@Test
@RedisAvailable
public void testCompleteMessageGroup() {
RedisConnectionFactory jcf = getConnectionFactoryForTest();
RedisMessageStore store = new RedisMessageStore(jcf);
MessageGroup messageGroup = store.getMessageGroup(this.groupId);
Message<?> message = new GenericMessage<>("Hello");
messageGroup = store.addMessageToGroup(messageGroup.getGroupId(), message);
store.completeGroup(messageGroup.getGroupId());
messageGroup = store.getMessageGroup(this.groupId);
assertTrue(messageGroup.isComplete());
}
use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.
the class RedisMessageGroupStoreTests method testJsonSerialization.
@Test
@RedisAvailable
public void testJsonSerialization() {
RedisConnectionFactory jcf = getConnectionFactoryForTest();
RedisMessageStore store = new RedisMessageStore(jcf);
ObjectMapper mapper = JacksonJsonUtils.messagingAwareMapper();
GenericJackson2JsonRedisSerializer serializer = new GenericJackson2JsonRedisSerializer(mapper);
store.setValueSerializer(serializer);
Message<?> genericMessage = new GenericMessage<>(new Date());
Message<?> mutableMessage = new MutableMessage<>(UUID.randomUUID());
Message<?> adviceMessage = new AdviceMessage<>("foo", genericMessage);
ErrorMessage errorMessage = new ErrorMessage(new RuntimeException("test exception"), mutableMessage);
store.addMessagesToGroup(this.groupId, genericMessage, mutableMessage, adviceMessage, errorMessage);
MessageGroup messageGroup = store.getMessageGroup(this.groupId);
assertEquals(4, messageGroup.size());
List<Message<?>> messages = new ArrayList<>(messageGroup.getMessages());
assertEquals(genericMessage, messages.get(0));
assertEquals(mutableMessage, messages.get(1));
assertEquals(adviceMessage, messages.get(2));
Message<?> errorMessageResult = messages.get(3);
assertEquals(errorMessage.getHeaders(), errorMessageResult.getHeaders());
assertThat(errorMessageResult, instanceOf(ErrorMessage.class));
assertEquals(errorMessage.getOriginalMessage(), ((ErrorMessage) errorMessageResult).getOriginalMessage());
assertEquals(errorMessage.getPayload().getMessage(), ((ErrorMessage) errorMessageResult).getPayload().getMessage());
Message<Foo> fooMessage = new GenericMessage<>(new Foo("foo"));
try {
store.addMessageToGroup(this.groupId, fooMessage).getMessages().iterator().next();
fail("SerializationException expected");
} catch (Exception e) {
assertThat(e.getCause().getCause(), instanceOf(IllegalArgumentException.class));
assertThat(e.getMessage(), containsString("The class with " + "org.springframework.integration.redis.store.RedisMessageGroupStoreTests$Foo and name of " + "org.springframework.integration.redis.store.RedisMessageGroupStoreTests$Foo " + "is not in the trusted packages:"));
}
mapper = JacksonJsonUtils.messagingAwareMapper(getClass().getPackage().getName());
serializer = new GenericJackson2JsonRedisSerializer(mapper);
store.setValueSerializer(serializer);
store.removeMessageGroup(this.groupId);
messageGroup = store.addMessageToGroup(this.groupId, fooMessage);
assertEquals(1, messageGroup.size());
assertEquals(fooMessage, messageGroup.getMessages().iterator().next());
mapper = JacksonJsonUtils.messagingAwareMapper("*");
serializer = new GenericJackson2JsonRedisSerializer(mapper);
store.setValueSerializer(serializer);
store.removeMessageGroup(this.groupId);
messageGroup = store.addMessageToGroup(this.groupId, fooMessage);
assertEquals(1, messageGroup.size());
assertEquals(fooMessage, messageGroup.getMessages().iterator().next());
}
Aggregations