Package org.springframework.scripting

Examples of org.springframework.scripting.Messenger


  }

  @Test
  public void testRefreshableFromTag() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("jruby-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


    assertTrue("Messenger should be Refreshable", messenger instanceof Refreshable);
  }

  public void testThatMultipleScriptInterfacesAreSupported() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("jruby-with-xsd.xml", getClass());
    Messenger messenger = (Messenger) ctx.getBean("calculatingMessenger");
    assertEquals("Hello World!", messenger.getMessage());

    // cool, now check that the Calculator interface is also exposed
    Calculator calc = (Calculator) messenger;
    assertEquals(0, calc.add(2, -2));
  }
View Full Code Here

  }

  @Test
  public void testAop() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("jruby-aop.xml", getClass());
    Messenger messenger = (Messenger) ctx.getBean("messenger");
    assertEquals(new StringBuffer("Hello World!").reverse().toString(), messenger.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);
    // 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

    assertTrue(Arrays.asList(ctx.getBeanNamesForType(Calculator.class)).contains("calculator"));
    assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messenger"));

    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()));

    assertEquals(5, calc.add(2, 3));

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

    assertTrue(ctx.getBeansOfType(Calculator.class).values().contains(calc));
    assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
  }
View Full Code Here

  public void testStaticWithScriptReturningInstance() throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
    assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerInstance"));

    Messenger messenger = (Messenger) ctx.getBean("messengerInstance");
    String desiredMessage = "Hello World!";
    assertEquals("Message is incorrect", desiredMessage, messenger.getMessage());
    assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));

    ctx.close();
    assertNull(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.