Spring Framework StaticScriptSource - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework StaticScriptSource class.

This code example shows how to use the following methods:setScript
 */ 
public class DefaultRedisScriptTests { 
 
	@Test
	public void testGetSha1() { 
		StaticScriptSource script = new StaticScriptSource("return KEYS[1]");
		DefaultRedisScript<String> redisScript = new DefaultRedisScript<String>();
		redisScript.setScriptSource(script);
		redisScript.setResultType(String.class);
		String sha1 = redisScript.getSha1();
		// Ensure multiple calls return same sha 
		assertEquals(sha1, redisScript.getSha1());
		script.setScript("return KEYS[2]");
		// Sha should now be different as script text has changed 
		assertFalse(sha1.equals(redisScript.getSha1()));
	} 
 
	@Test
	public void testGetScriptAsString() { 
		DefaultRedisScript<String> redisScript = new DefaultRedisScript<String>();
6
CodeRank
This code example shows how to use the following methods:
		assertEquals(2,obj);
	} 
 
	@Test
	public void test2() { 
		Object obj =  executor.executeScript(new StaticScriptSource("def foo(y):\n\tx=y\n\treturn y\nz=foo(2)") );
		assertEquals(2,obj);
	} 
 
	@Test
	public void test3() { 
		ScriptSource source =
			new ResourceScriptSource(new ClassPathResource("/org/springframework/integration/scripting/jsr223/test3.py"));
		Object obj =  executor.executeScript(source);
		PyTuple tuple = (PyTuple) obj;
		assertEquals(1, tuple.get(0));
	} 
 
	@Test
	public void testEmbeddedVariable() { 
6
CodeRank
This code example shows how to use the following methods:
	} 
 
	@Test
	public void testPython() { 
		ScriptExecutor executor = ScriptExecutorFactory.getScriptExecutor("python");
		Object obj = executor.executeScript(new StaticScriptSource("x=2") );
		assertEquals(2,obj);
 
		obj =  executor.executeScript(new StaticScriptSource("def foo(y):\n\tx=y\n\treturn y\nz=foo(2)") );
		assertEquals(2,obj);
	} 
 
	@Test(expected = ScriptingException.class)
	public void testInvalidLanguageThrowsScriptingException() { 
		ScriptExecutor executor = ScriptExecutorFactory.getScriptExecutor("foo");
		executor.executeScript(new StaticScriptSource("x=2"));
	} 
} 
6
CodeRank
This code example shows how to use the following methods:
	@Override 
	protected ScriptSource getScriptSource(Message<?> message) {
		Object payload = message.getPayload();
		Assert.isInstanceOf(String.class, payload, "Payload must be a String containing a Groovy script.");
		String className = generateScriptName(message);
		return new StaticScriptSource((String) payload, className);
	} 
 
	@Override 
	protected Object executeScript(ScriptSource scriptSource, Map<String, Object> variables) throws Exception {
		Assert.notNull(scriptSource, "scriptSource must not be null");
		VariableBindingGroovyObjectCustomizerDecorator customizerDecorator = this.binding != null
				? new BindingOverwriteGroovyObjectCustomizerDecorator(this.binding)
				: new VariableBindingGroovyObjectCustomizerDecorator(); 
		if (this.customizer != null) {
			customizerDecorator.setCustomizer(this.customizer);
		} 
		if (!CollectionUtils.isEmpty(variables)) {
			customizerDecorator.setVariables(variables);
		} 
5
CodeRank
This code example shows how to use the following methods:
 */ 
public class ScriptProcess extends ProcessSkeleton { 
 
    public ScriptProcess(Processor p) { 
        super(p); 
        StaticScriptSource script = new StaticScriptSource("test script"); 
 
    } 
 
} 
5
CodeRank
This code example shows how to use the following methods:
 
	/** 
	 * @param script The script text 
	 */ 
	public void setScriptText(String scriptText) {
		this.scriptSource = new StaticScriptSource(scriptText);
	} 
 
	/** 
	 * @param scriptLocation The location of the script 
	 */ 
	public void setLocation(Resource scriptLocation) {
		this.scriptSource = new ResourceScriptSource(scriptLocation);
	} 
 
	/** 
	 * @param scriptSource A @{link {@link ScriptSource} pointing to the script 
	 */ 
	public void setScriptSource(ScriptSource scriptSource) {
		this.scriptSource = scriptSource;
5
CodeRank
This code example shows how to use the following methods:
		ctx.getBean("distcp");
	} 
 
	@Test
	public void testNullCfg() throws Exception {
		ScriptSource script = new StaticScriptSource("null");
		 
		HdfsScriptRunner hsfb = new HdfsScriptRunner();
		GenericApplicationContext gac = new GenericApplicationContext();
		gac.refresh();
		hsfb.setApplicationContext(gac);
		hsfb.setScriptSource(script);
		hsfb.setLanguage("javascript");
		hsfb.afterPropertiesSet();
		 
		assertNull(hsfb.call());
	} 
} 
4
CodeRank
See Code Examples for Spring Framework StaticScriptSource Methods: