org.springframework.scripting.support.ScriptFactoryPostProcessor Java Examples
The following examples show how to use
org.springframework.scripting.support.ScriptFactoryPostProcessor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GroovyScriptFactoryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testScriptedClassThatDoesNotHaveANoArgCtor() throws Exception { ScriptSource script = mock(ScriptSource.class); String badScript = "class Foo { public Foo(String foo) {}}"; given(script.getScriptAsString()).willReturn(badScript); given(script.suggestedClassName()).willReturn("someName"); GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript); try { factory.getScriptedObject(script); fail("Must have thrown a ScriptCompilationException (no public no-arg ctor in scripted class)."); } catch (ScriptCompilationException expected) { assertTrue(expected.contains(NoSuchMethodException.class)); } }
Example #2
Source File: BshScriptFactoryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void scriptThatCompilesButIsJustPlainBad() throws IOException { ScriptSource script = mock(ScriptSource.class); final String badScript = "String getMessage() { throw new IllegalArgumentException(); }"; given(script.getScriptAsString()).willReturn(badScript); given(script.isModified()).willReturn(true); BshScriptFactory factory = new BshScriptFactory( ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript, Messenger.class); try { Messenger messenger = (Messenger) factory.getScriptedObject(script, Messenger.class); messenger.getMessage(); fail("Must have thrown a BshScriptUtils.BshExecutionException."); } catch (BshScriptUtils.BshExecutionException expected) { } }
Example #3
Source File: GroovyScriptFactoryTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testScriptedClassThatDoesNotHaveANoArgCtor() throws Exception { ScriptSource script = mock(ScriptSource.class); String badScript = "class Foo { public Foo(String foo) {}}"; given(script.getScriptAsString()).willReturn(badScript); given(script.suggestedClassName()).willReturn("someName"); GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript); try { factory.getScriptedObject(script); fail("Must have thrown a ScriptCompilationException (no public no-arg ctor in scripted class)."); } catch (ScriptCompilationException expected) { assertTrue(expected.contains(NoSuchMethodException.class)); } }
Example #4
Source File: BshScriptFactoryTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void scriptThatCompilesButIsJustPlainBad() throws IOException { ScriptSource script = mock(ScriptSource.class); final String badScript = "String getMessage() { throw new IllegalArgumentException(); }"; given(script.getScriptAsString()).willReturn(badScript); given(script.isModified()).willReturn(true); BshScriptFactory factory = new BshScriptFactory( ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript, Messenger.class); try { Messenger messenger = (Messenger) factory.getScriptedObject(script, Messenger.class); messenger.getMessage(); fail("Must have thrown a BshScriptUtils.BshExecutionException."); } catch (BshScriptUtils.BshExecutionException expected) { } }
Example #5
Source File: GroovyScriptFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testScriptedClassThatDoesNotHaveANoArgCtor() throws Exception { ScriptSource script = mock(ScriptSource.class); final String badScript = "class Foo { public Foo(String foo) {}}"; given(script.getScriptAsString()).willReturn(badScript); given(script.suggestedClassName()).willReturn("someName"); GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript); try { factory.getScriptedObject(script); fail("Must have thrown a ScriptCompilationException (no public no-arg ctor in scripted class)."); } catch (ScriptCompilationException expected) { assertTrue(expected.contains(InstantiationException.class)); } }
Example #6
Source File: GroovyScriptFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testScriptedClassThatHasNoPublicNoArgCtor() throws Exception { ScriptSource script = mock(ScriptSource.class); final String badScript = "class Foo { protected Foo() {}}"; given(script.getScriptAsString()).willReturn(badScript); given(script.suggestedClassName()).willReturn("someName"); GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript); try { factory.getScriptedObject(script); fail("Must have thrown a ScriptCompilationException (no oublic no-arg ctor in scripted class)."); } catch (ScriptCompilationException expected) { assertTrue(expected.contains(IllegalAccessException.class)); } }
Example #7
Source File: BshScriptFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void scriptThatCompilesButIsJustPlainBad() throws Exception { ScriptSource script = mock(ScriptSource.class); final String badScript = "String getMessage() { throw new IllegalArgumentException(); }"; given(script.getScriptAsString()).willReturn(badScript); given(script.isModified()).willReturn(true); BshScriptFactory factory = new BshScriptFactory( ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript, Messenger.class); try { Messenger messenger = (Messenger) factory.getScriptedObject(script, Messenger.class); messenger.getMessage(); fail("Must have thrown a BshScriptUtils.BshExecutionException."); } catch (BshScriptUtils.BshExecutionException expected) { } }
Example #8
Source File: GroovyScriptFactoryTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testScriptedClassThatHasNoPublicNoArgCtor() throws Exception { ScriptSource script = mock(ScriptSource.class); String badScript = "class Foo { protected Foo() {} \n String toString() { 'X' }}"; given(script.getScriptAsString()).willReturn(badScript); given(script.suggestedClassName()).willReturn("someName"); GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript); assertEquals("X", factory.getScriptedObject(script).toString()); }
Example #9
Source File: GroovyScriptFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testScriptedClassThatHasNoPublicNoArgCtor() throws Exception { ScriptSource script = mock(ScriptSource.class); String badScript = "class Foo { protected Foo() {} \n String toString() { 'X' }}"; given(script.getScriptAsString()).willReturn(badScript); given(script.suggestedClassName()).willReturn("someName"); GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript); assertEquals("X", factory.getScriptedObject(script).toString()); }