Package org.springframework.scripting

Examples of org.springframework.scripting.Messenger


    assertEquals("Byebye World!", messenger2.getMessage());
  }

  public void testNonStaticScript() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("bshRefreshableContext.xml", getClass());
    Messenger messenger = (Messenger) ctx.getBean("messenger");

    assertTrue("Should be a proxy for refreshable scripts", AopUtils.isAopProxy(messenger));
    assertTrue("Should be an instance of Refreshable", messenger instanceof Refreshable);

    String desiredMessage = "Hello World!";
    assertEquals("Message is incorrect", desiredMessage, messenger.getMessage());

    Refreshable refreshable = (Refreshable) messenger;
    refreshable.refresh();

    assertEquals("Message is incorrect after refresh", desiredMessage, messenger.getMessage());
    assertEquals("Incorrect refresh count", 2, refreshable.getRefreshCount());
  }
View Full Code Here


    mock.replay();
    BshScriptFactory factory = new BshScriptFactory(
        ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript,
        new Class[] {Messenger.class});
    try {
      Messenger messenger = (Messenger) factory.getScriptedObject(script, new Class[]{Messenger.class});
      messenger.getMessage();
      fail("Must have thrown a BshScriptUtils.BshExecutionException.");
    }
    catch (BshScriptUtils.BshExecutionException expected) {
    }
    mock.verify();
View Full Code Here

    Collection beanNames = Arrays.asList(ctx.getBeanNamesForType(Messenger.class));
    assertTrue(beanNames.contains("messenger"));
    assertTrue(beanNames.contains("messengerImpl"));
    assertTrue(beanNames.contains("messengerInstance"));

    Messenger messenger = (Messenger) ctx.getBean("messenger");
    assertEquals("Hello World!", messenger.getMessage());
    assertFalse(messenger instanceof Refreshable);

    Messenger messengerImpl = (Messenger) ctx.getBean("messengerImpl");
    assertEquals("Hello World!", messengerImpl.getMessage());

    Messenger messengerInstance = (Messenger) ctx.getBean("messengerInstance");
    assertEquals("Hello World!", messengerInstance.getMessage());

    TestBeanAwareMessenger messengerByType = (TestBeanAwareMessenger) ctx.getBean("messengerByType");
    assertEquals(testBean, messengerByType.getTestBean());

    TestBeanAwareMessenger messengerByName = (TestBeanAwareMessenger) ctx.getBean("messengerByName");
    assertEquals(testBean, messengerByName.getTestBean());

    Collection beans = ctx.getBeansOfType(Messenger.class).values();
    assertTrue(beans.contains(messenger));
    assertTrue(beans.contains(messengerImpl));
    assertTrue(beans.contains(messengerInstance));
    assertTrue(beans.contains(messengerByType));
    assertTrue(beans.contains(messengerByName));

    ctx.close();
    assertNull(messenger.getMessage());
    assertNull(messengerImpl.getMessage());
    assertNull(messengerInstance.getMessage());
  }
View Full Code Here

    assertFalse(calculator instanceof Refreshable);
  }

  public void testRefreshableFromTag() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
    Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");
    assertEquals("Hello World!", messenger.getMessage());
    assertTrue("Messenger should be Refreshable", messenger instanceof Refreshable);
  }
View Full Code Here

    GenericApplicationContext ctx = new GenericApplicationContext();
    ctx.registerBeanDefinition(PROCESSOR_BEAN_NAME, processorBeanDefinition);
    ctx.registerBeanDefinition(MESSENGER_BEAN_NAME, scriptedBeanDefinition);
    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);
    source.setScript(CHANGED_SCRIPT);
    Messenger refreshedMessenger = (Messenger) ctx.getBean(MESSENGER_BEAN_NAME);
    // the updated script surrounds the message in quotes before returning...
    assertEquals(EXPECTED_CHANGED_MESSAGE_TEXT, refreshedMessenger.getMessage());
  }
View Full Code Here

    GenericApplicationContext ctx = new GenericApplicationContext();
    ctx.registerBeanDefinition(PROCESSOR_BEAN_NAME, processorBeanDefinition);
    ctx.registerBeanDefinition(MESSENGER_BEAN_NAME, scriptedBeanDefinition);
    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);
    source.setScript(CHANGED_SCRIPT);
    Messenger refreshedMessenger = (Messenger) ctx.getBean(MESSENGER_BEAN_NAME);
    assertEquals("Script seems to have been refreshed (must not be as no refreshCheckDelay set on ScriptFactoryPostProcessor)",
        MESSAGE_TEXT, refreshedMessenger.getMessage());
  }
View Full Code Here

    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);
    source.setScript(CHANGED_SCRIPT);
    Messenger refreshedMessenger = (Messenger) ctx.getBean(MESSENGER_BEAN_NAME);
    // the updated script surrounds the message in quotes before returning...
    assertEquals(EXPECTED_CHANGED_MESSAGE_TEXT, refreshedMessenger.getMessage());
    // ok, is this change reflected in the reference that the collaborator has?
    DefaultMessengerService collaborator = (DefaultMessengerService) ctx.getBean(collaboratorBeanName);
    assertEquals(EXPECTED_CHANGED_MESSAGE_TEXT, collaborator.getMessage());
  }
View Full Code Here

    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));
    }
View Full Code Here

    final String BEAN_WITH_DEPENDENCY_NAME = "needsMessenger";
    ctx.registerBeanDefinition(BEAN_WITH_DEPENDENCY_NAME, scriptedBeanBuilder.getBeanDefinition());
    ctx.registerBeanDefinition("scriptProcessor", createScriptFactoryPostProcessor(true));
    ctx.refresh();
   
    Messenger messenger1 = (Messenger) ctx.getBean(BEAN_WITH_DEPENDENCY_NAME);
    Messenger messenger2 = (Messenger) ctx.getBean(BEAN_WITH_DEPENDENCY_NAME);
    assertNotSame(messenger1, messenger2);
  }
View Full Code Here


  public void testStaticScript() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("jrubyContext.xml", getClass());
    Calculator calc = (Calculator) ctx.getBean("calculator");
    Messenger messenger = (Messenger) ctx.getBean("messenger");

    assertFalse("Scripted object should not be instance of Refreshable", calc instanceof Refreshable);
    assertFalse("Scripted object should not be instance of Refreshable", messenger instanceof Refreshable);

    assertEquals(calc, calc);
    assertEquals(messenger, messenger);
    assertTrue(!messenger.equals(calc));
    assertTrue(messenger.hashCode() != calc.hashCode());
    assertTrue(!messenger.toString().equals(calc.toString()));

    String desiredMessage = "Hello World!";
    assertEquals("Message is incorrect", desiredMessage, messenger.getMessage());
  }
View Full Code Here

TOP

Related Classes of org.springframework.scripting.Messenger

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.