@Test public void testGetValue() throws Exception { LiteralExpression lEx = new LiteralExpression("somevalue"); checkString("somevalue", lEx.getValue()); checkString("somevalue", lEx.getValue(String.class)); EvaluationContext ctx = new StandardEvaluationContext(); checkString("somevalue", lEx.getValue(ctx)); checkString("somevalue", lEx.getValue(ctx, String.class)); checkString("somevalue", lEx.getValue(new Rooty())); checkString("somevalue", lEx.getValue(new Rooty(), String.class)); checkString("somevalue", lEx.getValue(ctx, new Rooty())); checkString("somevalue", lEx.getValue(ctx, new Rooty(),String.class)); assertEquals("somevalue", lEx.getExpressionString()); assertFalse(lEx.isWritable(new StandardEvaluationContext())); assertFalse(lEx.isWritable(new Rooty())); assertFalse(lEx.isWritable(new StandardEvaluationContext(), new Rooty())); }
@Test public void validateWithExternalTemplate() { RedisStoreWritingMessageHandler withExternalTemplate = TestUtils.getPropertyValue(context.getBean("withExternalTemplate.adapter"), "handler", RedisStoreWritingMessageHandler.class); assertEquals("pepboys", ((LiteralExpression) TestUtils.getPropertyValue(withExternalTemplate, "keyExpression")).getExpressionString()); assertEquals("PROPERTIES", (TestUtils.getPropertyValue(withExternalTemplate, "collectionType")).toString()); assertSame(redisTemplate, TestUtils.getPropertyValue(withExternalTemplate, "redisTemplate")); }
@Test @RedisAvailable public void testMapToMapWithProvidedKey() { RedisMap<String, String> redisMap = new DefaultRedisMap<String, String>("pepboys", this.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.mapToMapAChannel.send(message); assertEquals("Manny", redisMap.get("1")); assertEquals("Moe", redisMap.get("2")); assertEquals("Jack", redisMap.get("3")); RedisStoreWritingMessageHandler handler = this.beanFactory.getBean("mapToMapA.handler", RedisStoreWritingMessageHandler.class); assertEquals("pepboys", TestUtils.getPropertyValue(handler, "keyExpression", LiteralExpression.class).getExpressionString()); assertEquals("'foo'", TestUtils.getPropertyValue(handler, "mapKeyExpression", SpelExpression.class).getExpressionString()); }
@Test public void validateWithStringTemplate() throws Exception { RedisStoreWritingMessageHandler withStringTemplate = context.getBean("withStringTemplate.handler", RedisStoreWritingMessageHandler.class); assertEquals("pepboys", ((LiteralExpression) TestUtils.getPropertyValue(withStringTemplate, "keyExpression")).getExpressionString()); assertEquals("PROPERTIES", (TestUtils.getPropertyValue(withStringTemplate, "collectionType")).toString()); assertTrue(TestUtils.getPropertyValue(withStringTemplate, "redisTemplate") instanceof StringRedisTemplate); Object handler = TestUtils.getPropertyValue(context.getBean("withStringTemplate.adapter"), "handler"); assertTrue(AopUtils.isAopProxy(handler)); assertSame(((Advised) handler).getTargetSource().getTarget(), withStringTemplate); assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors[0].advice"), Matchers.instanceOf(RequestHandlerRetryAdvice.class)); assertEquals("true", TestUtils.getPropertyValue(withStringTemplate, "zsetIncrementScoreExpression", Expression.class).getExpressionString()); }
@Test public void validateWithStringObjectTemplate() { RedisStoreWritingMessageHandler withStringObjectTemplate = TestUtils.getPropertyValue(context.getBean("withStringObjectTemplate.adapter"), "handler", RedisStoreWritingMessageHandler.class); assertEquals("pepboys", ((LiteralExpression) TestUtils.getPropertyValue(withStringObjectTemplate, "keyExpression")).getExpressionString()); assertEquals("PROPERTIES", (TestUtils.getPropertyValue(withStringObjectTemplate, "collectionType")).toString()); assertFalse(TestUtils.getPropertyValue(withStringObjectTemplate, "redisTemplate") instanceof StringRedisTemplate); assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate, "redisTemplate.keySerializer") instanceof StringRedisSerializer); assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate, "redisTemplate.hashKeySerializer") instanceof StringRedisSerializer); assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate, "redisTemplate.valueSerializer") instanceof JdkSerializationRedisSerializer); assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate, "redisTemplate.hashValueSerializer") instanceof JdkSerializationRedisSerializer); }