Search in sources :

Example 1 with DefaultRedisMap

use of org.springframework.data.redis.support.collections.DefaultRedisMap in project spring-integration by spring-projects.

the class RedisStoreOutboundChannelAdapterIntegrationTests method testMapToMapNoKey.

// key is not provided
@Test(expected = MessageHandlingException.class)
@RedisAvailable
public void testMapToMapNoKey() {
    RedisTemplate<String, Map<String, Map<String, String>>> redisTemplate = new RedisTemplate<String, Map<String, Map<String, String>>>();
    redisTemplate.setKeySerializer(new StringRedisSerializer());
    redisTemplate.setHashKeySerializer(new StringRedisSerializer());
    redisTemplate.setConnectionFactory(getConnectionFactoryForTest());
    redisTemplate.afterPropertiesSet();
    RedisMap<String, Map<String, String>> redisMap = new DefaultRedisMap<String, Map<String, String>>("pepboys", redisTemplate);
    assertEquals(0, redisMap.size());
    Map<String, String> pepboys = new HashMap<String, String>();
    pepboys.put("1", "Manny");
    pepboys.put("2", "Moe");
    pepboys.put("3", "Jack");
    Message<Map<String, String>> message = MessageBuilder.withPayload(pepboys).build();
    this.mapToMapBChannel.send(message);
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) HashMap(java.util.HashMap) DefaultRedisMap(org.springframework.data.redis.support.collections.DefaultRedisMap) HashMap(java.util.HashMap) Map(java.util.Map) RedisMap(org.springframework.data.redis.support.collections.RedisMap) DefaultRedisMap(org.springframework.data.redis.support.collections.DefaultRedisMap) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 2 with DefaultRedisMap

use of org.springframework.data.redis.support.collections.DefaultRedisMap in project spring-integration by spring-projects.

the class RedisStoreOutboundChannelAdapterIntegrationTests method testMapToMapAsSingleEntryWithKeyAsHeader.

@Test
@RedisAvailable
public void testMapToMapAsSingleEntryWithKeyAsHeader() {
    RedisTemplate<String, Map<String, Map<String, String>>> redisTemplate = new RedisTemplate<String, Map<String, Map<String, String>>>();
    redisTemplate.setKeySerializer(new StringRedisSerializer());
    redisTemplate.setHashKeySerializer(new StringRedisSerializer());
    redisTemplate.setConnectionFactory(getConnectionFactoryForTest());
    redisTemplate.afterPropertiesSet();
    RedisMap<String, Map<String, String>> redisMap = new DefaultRedisMap<String, Map<String, String>>("pepboys", redisTemplate);
    assertEquals(0, redisMap.size());
    Map<String, String> pepboys = new HashMap<String, String>();
    pepboys.put("1", "Manny");
    pepboys.put("2", "Moe");
    pepboys.put("3", "Jack");
    Message<Map<String, String>> message = MessageBuilder.withPayload(pepboys).setHeader(RedisHeaders.KEY, "pepboys").setHeader(RedisHeaders.MAP_KEY, "foo").build();
    this.mapToMapBChannel.send(message);
    Map<String, String> pepboyz = redisMap.get("foo");
    assertEquals("Manny", pepboyz.get("1"));
    assertEquals("Moe", pepboyz.get("2"));
    assertEquals("Jack", pepboyz.get("3"));
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) HashMap(java.util.HashMap) DefaultRedisMap(org.springframework.data.redis.support.collections.DefaultRedisMap) HashMap(java.util.HashMap) Map(java.util.Map) RedisMap(org.springframework.data.redis.support.collections.RedisMap) DefaultRedisMap(org.springframework.data.redis.support.collections.DefaultRedisMap) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.junit.Test)2 RedisTemplate (org.springframework.data.redis.core.RedisTemplate)2 StringRedisTemplate (org.springframework.data.redis.core.StringRedisTemplate)2 StringRedisSerializer (org.springframework.data.redis.serializer.StringRedisSerializer)2 DefaultRedisMap (org.springframework.data.redis.support.collections.DefaultRedisMap)2 RedisMap (org.springframework.data.redis.support.collections.RedisMap)2 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)2