Package org.springframework.scripting

Examples of org.springframework.scripting.Messenger


    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("Shouldn't get proxy when refresh is disabled", AopUtils.isAopProxy(calc));
    assertFalse("Shouldn't get proxy when refresh is disabled", AopUtils.isAopProxy(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());

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


  }

  public void testStaticScriptWithInstance() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyContext.xml", getClass());
    assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerInstance"));
    Messenger messenger = (Messenger) ctx.getBean("messengerInstance");

    assertFalse("Shouldn't get proxy when refresh is disabled", AopUtils.isAopProxy(messenger));
    assertFalse("Scripted object should not be instance of Refreshable", messenger instanceof Refreshable);

    String desiredMessage = "Hello World!";
    assertEquals("Message is incorrect", desiredMessage, messenger.getMessage());
    assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
  }
View Full Code Here

  }

  public void testStaticScriptWithInlineDefinedInstance() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyContext.xml", getClass());
    assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerInstanceInline"));
    Messenger messenger = (Messenger) ctx.getBean("messengerInstanceInline");

    assertFalse("Shouldn't get proxy when refresh is disabled", AopUtils.isAopProxy(messenger));
    assertFalse("Scripted object should not be instance of Refreshable", messenger instanceof Refreshable);

    String desiredMessage = "Hello World!";
    assertEquals("Message is incorrect", desiredMessage, messenger.getMessage());
    assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
  }
View Full Code Here

    assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
  }

  public void testNonStaticScript() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyRefreshableContext.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.verify();
  }

  public void testWithTwoClassesDefinedInTheOneGroovyFile_CorrectClassFirst() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("twoClassesCorrectOneFirst.xml", getClass());
    Messenger messenger = (Messenger) ctx.getBean("messenger");
    assertNotNull(messenger);
    assertEquals("Hello World!", messenger.getMessage());

    // Check can cast to GroovyObject
    GroovyObject goo = (GroovyObject) messenger;
  }
View Full Code Here

    }
  }

  public void testResourceScriptFromTag() throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd.xml", getClass());
    Messenger messenger = (Messenger) ctx.getBean("messenger");
    CallCounter countingAspect = (CallCounter) ctx.getBean("getMessageAspect");

    assertTrue(AopUtils.isAopProxy(messenger));
    assertFalse(messenger instanceof Refreshable);
    assertEquals(0, countingAspect.getCalls());
    assertEquals("Hello World!", messenger.getMessage());
    assertEquals(1, countingAspect.getCalls());

    ctx.close();
    assertEquals(-200, countingAspect.getCalls());
  }
View Full Code Here

  public void testRefreshableFromTag() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd.xml", getClass());
    assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("refreshableMessenger"));

    Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");
    CallCounter countingAspect = (CallCounter) ctx.getBean("getMessageAspect");

    assertTrue(AopUtils.isAopProxy(messenger));
    assertTrue(messenger instanceof Refreshable);
    assertEquals(0, countingAspect.getCalls());
    assertEquals("Hello World!", messenger.getMessage());
    assertEquals(1, countingAspect.getCalls());

    assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
  }
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

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

    Messenger messenger = (Messenger) ctx.getBean("messengerImpl");
    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.