Java Code Examples for org.springframework.scripting.Messenger#getMessage()
The following examples show how to use
org.springframework.scripting.Messenger#getMessage() .
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: 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 2
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 3
Source File: AdvisedJRubyScriptFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testAdviseWithProxyFactoryBean() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(FACTORYBEAN_CONTEXT, CLASS); try { Messenger bean = (Messenger) ctx.getBean("messenger"); assertTrue("Bean is not a proxy", AopUtils.isAopProxy(bean)); assertTrue("Bean is not an Advised object", bean instanceof Advised); CountingBeforeAdvice advice = (CountingBeforeAdvice) ctx.getBean("advice"); assertEquals(0, advice.getCalls()); bean.getMessage(); assertEquals(1, advice.getCalls()); } finally { ctx.close(); } }
Example 4
Source File: AdvisedJRubyScriptFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testAdviseWithBeanNameAutoProxyCreator() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(APC_CONTEXT, CLASS); try { Messenger bean = (Messenger) ctx.getBean("messenger"); assertTrue("Bean is not a proxy", AopUtils.isAopProxy(bean)); assertTrue("Bean is not an Advised object", bean instanceof Advised); CountingBeforeAdvice advice = (CountingBeforeAdvice) ctx.getBean("advice"); assertEquals(0, advice.getCalls()); bean.getMessage(); assertEquals(1, advice.getCalls()); } finally { ctx.close(); } }
Example 5
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 6
Source File: ScriptFactoryPostProcessorTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testForRefreshedScriptHavingErrorPickedUpOnFirstCall() throws Exception { BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(true); BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean(); BeanDefinitionBuilder collaboratorBuilder = BeanDefinitionBuilder.rootBeanDefinition(DefaultMessengerService.class); collaboratorBuilder.addPropertyReference(MESSENGER_BEAN_NAME, MESSENGER_BEAN_NAME); GenericApplicationContext ctx = new GenericApplicationContext(); ctx.registerBeanDefinition(PROCESSOR_BEAN_NAME, processorBeanDefinition); ctx.registerBeanDefinition(MESSENGER_BEAN_NAME, scriptedBeanDefinition); final String collaboratorBeanName = "collaborator"; ctx.registerBeanDefinition(collaboratorBeanName, collaboratorBuilder.getBeanDefinition()); ctx.refresh(); Messenger messenger = (Messenger) ctx.getBean(MESSENGER_BEAN_NAME); assertEquals(MESSAGE_TEXT, messenger.getMessage()); // cool; now let's change the script and check the refresh behaviour... pauseToLetRefreshDelayKickIn(DEFAULT_SECONDS_TO_PAUSE); StaticScriptSource source = getScriptSource(ctx); // needs The Sundays compiler; must NOT throw any exception here... source.setScript("I keep hoping you are the same as me, and I'll send you letters and come to your house for tea"); Messenger refreshedMessenger = (Messenger) ctx.getBean(MESSENGER_BEAN_NAME); try { refreshedMessenger.getMessage(); fail("Must have thrown an Exception (invalid script)"); } catch (FatalBeanException expected) { assertTrue(expected.contains(ScriptCompilationException.class)); } }
Example 7
Source File: ScriptFactoryPostProcessorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testForRefreshedScriptHavingErrorPickedUpOnFirstCall() throws Exception { BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(true); BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean(); BeanDefinitionBuilder collaboratorBuilder = BeanDefinitionBuilder.rootBeanDefinition(DefaultMessengerService.class); collaboratorBuilder.addPropertyReference(MESSENGER_BEAN_NAME, MESSENGER_BEAN_NAME); GenericApplicationContext ctx = new GenericApplicationContext(); ctx.registerBeanDefinition(PROCESSOR_BEAN_NAME, processorBeanDefinition); ctx.registerBeanDefinition(MESSENGER_BEAN_NAME, scriptedBeanDefinition); final String collaboratorBeanName = "collaborator"; ctx.registerBeanDefinition(collaboratorBeanName, collaboratorBuilder.getBeanDefinition()); ctx.refresh(); Messenger messenger = (Messenger) ctx.getBean(MESSENGER_BEAN_NAME); assertEquals(MESSAGE_TEXT, messenger.getMessage()); // cool; now let's change the script and check the refresh behaviour... pauseToLetRefreshDelayKickIn(DEFAULT_SECONDS_TO_PAUSE); StaticScriptSource source = getScriptSource(ctx); // needs The Sundays compiler; must NOT throw any exception here... source.setScript("I keep hoping you are the same as me, and I'll send you letters and come to your house for tea"); Messenger refreshedMessenger = (Messenger) ctx.getBean(MESSENGER_BEAN_NAME); try { refreshedMessenger.getMessage(); fail("Must have thrown an Exception (invalid script)"); } catch (FatalBeanException expected) { assertTrue(expected.contains(ScriptCompilationException.class)); } }
Example 8
Source File: ScriptFactoryPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testForRefreshedScriptHavingErrorPickedUpOnFirstCall() throws Exception { BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(true); BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean(); BeanDefinitionBuilder collaboratorBuilder = BeanDefinitionBuilder.rootBeanDefinition(DefaultMessengerService.class); collaboratorBuilder.addPropertyReference(MESSENGER_BEAN_NAME, MESSENGER_BEAN_NAME); GenericApplicationContext ctx = new GenericApplicationContext(); ctx.registerBeanDefinition(PROCESSOR_BEAN_NAME, processorBeanDefinition); ctx.registerBeanDefinition(MESSENGER_BEAN_NAME, scriptedBeanDefinition); final String collaboratorBeanName = "collaborator"; ctx.registerBeanDefinition(collaboratorBeanName, collaboratorBuilder.getBeanDefinition()); ctx.refresh(); Messenger messenger = (Messenger) ctx.getBean(MESSENGER_BEAN_NAME); assertEquals(MESSAGE_TEXT, messenger.getMessage()); // cool; now let's change the script and check the refresh behaviour... pauseToLetRefreshDelayKickIn(DEFAULT_SECONDS_TO_PAUSE); StaticScriptSource source = getScriptSource(ctx); // needs The Sundays compiler; must NOT throw any exception here... source.setScript("I keep hoping you are the same as me, and I'll send you letters and come to your house for tea"); Messenger refreshedMessenger = (Messenger) ctx.getBean(MESSENGER_BEAN_NAME); try { refreshedMessenger.getMessage(); fail("Must have thrown an Exception (invalid script)"); } catch (FatalBeanException expected) { assertTrue(expected.contains(ScriptCompilationException.class)); } }