use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.
the class RedisStoreWritingMessageHandlerTests method testListWithMapKeyExpression.
@Test(expected = IllegalStateException.class)
@RedisAvailable
public void testListWithMapKeyExpression() {
RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
String key = "foo";
RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(jcf);
handler.setKey(key);
handler.setMapKeyExpression(new LiteralExpression(key));
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
}
use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.
the class RedisStoreWritingMessageHandlerTests method testZsetWithListPayloadParsedAndProvidedKeyDefault.
@Test
@RedisAvailable
public void testZsetWithListPayloadParsedAndProvidedKeyDefault() {
RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
this.deleteKey(jcf, "foo");
String key = "foo";
RedisZSet<String> redisZset = new DefaultRedisZSet<String>(key, this.initTemplate(jcf, new StringRedisTemplate()));
assertEquals(0, redisZset.size());
RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(jcf);
handler.setKey(key);
handler.setCollectionType(CollectionType.ZSET);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
List<String> list = new ArrayList<String>();
list.add("Manny");
list.add("Moe");
list.add("Jack");
Message<List<String>> message = MessageBuilder.withPayload(list).setHeader(RedisHeaders.ZSET_INCREMENT_SCORE, true).build();
handler.handleMessage(message);
assertEquals(3, redisZset.size());
Set<TypedTuple<String>> pepboys = redisZset.rangeByScoreWithScores(1, 1);
for (TypedTuple<String> pepboy : pepboys) {
assertTrue(pepboy.getScore() == 1);
}
handler.handleMessage(message);
assertEquals(3, redisZset.size());
pepboys = redisZset.rangeByScoreWithScores(1, 2);
// should have incremented by 1
for (TypedTuple<String> pepboy : pepboys) {
assertEquals(Double.valueOf(2), pepboy.getScore());
}
this.deleteKey(jcf, "foo");
}
use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.
the class RedisStoreWritingMessageHandlerTests method testListWithListPayloadParsedAndProvidedKeyAsHeader.
@Test
@RedisAvailable
public void testListWithListPayloadParsedAndProvidedKeyAsHeader() {
RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
this.deleteKey(jcf, "foo");
String key = "foo";
RedisList<String> redisList = new DefaultRedisList<String>(key, this.initTemplate(jcf, new StringRedisTemplate()));
assertEquals(0, redisList.size());
RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(jcf);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
List<String> list = new ArrayList<String>();
list.add("Manny");
list.add("Moe");
list.add("Jack");
Message<List<String>> message = MessageBuilder.withPayload(list).setHeader("redis_key", key).build();
handler.handleMessage(message);
assertEquals(3, redisList.size());
assertEquals("Manny", redisList.get(0));
assertEquals("Moe", redisList.get(1));
assertEquals("Jack", redisList.get(2));
this.deleteKey(jcf, "foo");
}
use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.
the class RedisStoreWritingMessageHandlerTests method testListWithListPayloadParsedAndProvidedKey.
@Test
@RedisAvailable
public void testListWithListPayloadParsedAndProvidedKey() {
RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
this.deleteKey(jcf, "foo");
String key = "foo";
RedisList<String> redisList = new DefaultRedisList<String>(key, this.initTemplate(jcf, new StringRedisTemplate()));
assertEquals(0, redisList.size());
RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(jcf);
handler.setKey(key);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
List<String> list = new ArrayList<String>();
list.add("Manny");
list.add("Moe");
list.add("Jack");
Message<List<String>> message = new GenericMessage<List<String>>(list);
handler.handleMessage(message);
assertEquals(3, redisList.size());
assertEquals("Manny", redisList.get(0));
assertEquals("Moe", redisList.get(1));
assertEquals("Jack", redisList.get(2));
this.deleteKey(jcf, "foo");
}
use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.
the class RedisStoreWritingMessageHandlerTests method testListWithListPayloadAsSingleEntry.
@Test
@RedisAvailable
public void testListWithListPayloadAsSingleEntry() {
RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
this.deleteKey(jcf, "foo");
String key = "foo";
RedisList<List<String>> redisList = new DefaultRedisList<List<String>>(key, this.initTemplate(jcf, new RedisTemplate<String, List<String>>()));
assertEquals(0, redisList.size());
RedisTemplate<String, List<String>> template = this.initTemplate(jcf, new RedisTemplate<String, List<String>>());
RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(template);
handler.setKey(key);
handler.setExtractPayloadElements(false);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
List<String> list = new ArrayList<String>();
list.add("Manny");
list.add("Moe");
list.add("Jack");
Message<List<String>> message = new GenericMessage<List<String>>(list);
handler.handleMessage(message);
assertEquals(1, redisList.size());
List<String> resultList = redisList.get(0);
assertEquals("Manny", resultList.get(0));
assertEquals("Moe", resultList.get(1));
assertEquals("Jack", resultList.get(2));
this.deleteKey(jcf, "foo");
}
Aggregations