@Test public void testWithNoVars() { ScriptSource scriptSource = new ResourceScriptSource( new ClassPathResource( "/org/springframework/integration/scripting/jsr223/print_message.rb")); ScriptExecutingMessageProcessor messageProcessor = new ScriptExecutingMessageProcessor(scriptSource, executor); messageProcessor.setBeanFactory(Mockito.mock(BeanFactory.class)); Message<?> message = new GenericMessage<String>("hello"); Object obj = messageProcessor.processMessage(message); assertEquals("hello modified", obj.toString().substring(0, "hello modified".length())); }
@Test public void testExecuteWithVariables() { Map<String, Object> vars = new HashMap<String, Object>(); vars.put("one", 1); vars.put("two", "two"); vars.put("three", 3); ScriptSource scriptSource = new ResourceScriptSource( new ClassPathResource( "/org/springframework/integration/scripting/jsr223/print_message.rb")); ScriptExecutingMessageProcessor messageProcessor = new ScriptExecutingMessageProcessor(scriptSource, executor, vars); messageProcessor.setBeanFactory(Mockito.mock(BeanFactory.class)); Message<?> message = new GenericMessage<String>("hello"); Object obj = messageProcessor.processMessage(message); assertEquals("hello modified", obj.toString().substring(0, "hello modified".length())); }