File Cleanup - Scripting to Twitter

This commit is contained in:
Gary Russell
2016-06-04 12:36:10 -04:00
parent 6016a70cd5
commit dd1d2ecab4
35 changed files with 123 additions and 244 deletions

View File

@@ -16,6 +16,8 @@
package org.springframework.integration.scripting.config.jsr223;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
@@ -26,18 +28,17 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.scripting.ScriptVariableGenerator;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -132,13 +133,13 @@ public class Jsr223ServiceActivatorTests {
}
String payload = (String) replyChannel.receive(0).getPayload();
assertThat(payload, Matchers.startsWith("inline-test-1 - FOO"));
assertThat(payload, startsWith("inline-test-1 - FOO"));
payload = (String) replyChannel.receive(0).getPayload();
assertThat(payload, Matchers.startsWith("inline-test-2 - FOO"));
assertThat(payload, startsWith("inline-test-2 - FOO"));
payload = (String) replyChannel.receive(0).getPayload();
assertThat(payload, Matchers.startsWith("inline-test-3 - FOO"));
assertThat(payload, startsWith("inline-test-3 - FOO"));
assertTrue(payload.substring(payload.indexOf(":") + 1).matches(".+\\d{2}:\\d{2}:\\d{2}.+"));
assertNull(replyChannel.receive(0));
@@ -148,26 +149,30 @@ public class Jsr223ServiceActivatorTests {
@Test
public void variablesAndScriptVariableGenerator() throws Exception {
try {
new ClassPathXmlApplicationContext("Jsr223ServiceActivatorTests-fail-withgenerator-context.xml", this.getClass());
new ClassPathXmlApplicationContext("Jsr223ServiceActivatorTests-fail-withgenerator-context.xml",
this.getClass()).close();
fail("BeansException expected.");
}
catch (BeansException e) {
assertThat(e.getMessage(), Matchers.containsString("'script-variable-generator' and 'variable' sub-elements are mutually exclusive."));
assertThat(e.getMessage(),
containsString("'script-variable-generator' and 'variable' sub-elements are mutually exclusive."));
}
}
@Test
public void testDuplicateVariable() throws Exception {
try {
new ClassPathXmlApplicationContext("Jsr223ServiceActivatorTests-fail-duplicated-variable-context.xml", this.getClass());
new ClassPathXmlApplicationContext("Jsr223ServiceActivatorTests-fail-duplicated-variable-context.xml",
this.getClass()).close();
fail("BeansException expected.");
}
catch (BeansException e) {
assertThat(e.getMessage(), Matchers.containsString("Duplicated variable: foo"));
assertThat(e.getMessage(), containsString("Duplicated variable: foo"));
}
}
public static class SampleScriptVariSource implements ScriptVariableGenerator {
@Override
public Map<String, Object> generateScriptVariables(Message<?> message) {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("foo", "foo");

View File

@@ -1 +1 @@
"ruby-#{payload}-#{foo} - #{bar} - #{date}"
"ruby-#{payload}-#{foo} - #{bar} - #{date}"

View File

@@ -4,4 +4,4 @@ class Transformer
end
end
Transformer.new.transform(payload)
Transformer.new.transform(payload)

View File

@@ -6,4 +6,4 @@ class RubyHello
"hello,world"
end
end
RubyHello.new
RubyHello.new

View File

@@ -9,4 +9,4 @@ if headers
headers.each {|key, value| puts "#{key} is #{value}" }
end
puts "#{$one} #{$two} #{$three}"
payload
payload