Search in sources :

Example 6 with LifecycleHelper

use of com.nokia.dempsy.container.internal.LifecycleHelper in project Dempsy by Dempsy.

the class TestInvocation method testActivateReturns.

@Test
public void testActivateReturns() throws Exception {
    ActivateReturns prototype = new ActivateReturns();
    LifecycleHelper invoker = new LifecycleHelper(prototype);
    ActivateReturns instance = (ActivateReturns) invoker.newInstance();
    assertNotNull("instantiation failed; null instance", instance);
    assertNotSame("instantiation failed; returned prototype", prototype, instance);
    assertFalse("instance activated before activation method called", instance.isActivated);
    assertTrue(invoker.activate(instance, null, "ABC".getBytes()));
    assertTrue("instance was not activated", instance.isActivated);
    assertEquals("ABC", instance.activationValue);
    ActivateReturns.returnValue = false;
    assertFalse(invoker.activate(instance, null, "DEF".getBytes()));
    assertEquals("DEF", instance.activationValue);
}
Also used : LifecycleHelper(com.nokia.dempsy.container.internal.LifecycleHelper) Test(org.junit.Test)

Example 7 with LifecycleHelper

use of com.nokia.dempsy.container.internal.LifecycleHelper in project Dempsy by Dempsy.

the class TestInvocation method testLifeCycleMethods.

@Test
public void testLifeCycleMethods() throws Exception {
    InvocationTestMP prototype = new InvocationTestMP();
    LifecycleHelper invoker = new LifecycleHelper(prototype);
    InvocationTestMP instance = (InvocationTestMP) invoker.newInstance();
    assertNotNull("instantiation failed; null instance", instance);
    assertNotSame("instantiation failed; returned prototype", prototype, instance);
    assertFalse("instance activated before activation method called", instance.isActivated);
    assertTrue(invoker.activate(instance, null, "ABC".getBytes()));
    assertTrue("instance was not activated", instance.isActivated);
    assertEquals("ABC", instance.activationValue);
    assertFalse("instance passivated before passivation method called", instance.isPassivated);
    byte[] data = invoker.passivate(instance);
    assertTrue("instance was not passivated", instance.isPassivated);
    assertEquals("ABC", new String(data));
}
Also used : LifecycleHelper(com.nokia.dempsy.container.internal.LifecycleHelper) Test(org.junit.Test)

Example 8 with LifecycleHelper

use of com.nokia.dempsy.container.internal.LifecycleHelper in project Dempsy by Dempsy.

the class TestInvocation method testInvocationFailureNullMessage.

@Test(expected = NullPointerException.class)
public void testInvocationFailureNullMessage() throws Exception {
    InvocationTestMP prototype = new InvocationTestMP();
    LifecycleHelper invoker = new LifecycleHelper(prototype);
    InvocationTestMP instance = (InvocationTestMP) invoker.newInstance();
    BasicStatsCollector statsCollector = new BasicStatsCollector();
    invoker.invoke(instance, null, statsCollector);
}
Also used : BasicStatsCollector(com.nokia.dempsy.monitoring.basic.BasicStatsCollector) LifecycleHelper(com.nokia.dempsy.container.internal.LifecycleHelper) Test(org.junit.Test)

Example 9 with LifecycleHelper

use of com.nokia.dempsy.container.internal.LifecycleHelper in project Dempsy by Dempsy.

the class TestInvocation method testOutput.

@Test
public void testOutput() throws Exception {
    InvocationTestMP prototype = new InvocationTestMP();
    LifecycleHelper invoker = new LifecycleHelper(prototype);
    InvocationTestMP instance = (InvocationTestMP) invoker.newInstance();
    assertFalse("instance says it did output before method called", instance.outputCalled);
    invoker.invokeOutput(instance);
    assertTrue("output method was not called", instance.outputCalled);
}
Also used : LifecycleHelper(com.nokia.dempsy.container.internal.LifecycleHelper) Test(org.junit.Test)

Example 10 with LifecycleHelper

use of com.nokia.dempsy.container.internal.LifecycleHelper in project Dempsy by Dempsy.

the class TestInvocation method testInvocationExactClass.

@Test
public void testInvocationExactClass() throws Exception {
    InvocationTestMP prototype = new InvocationTestMP();
    LifecycleHelper invoker = new LifecycleHelper(prototype);
    InvocationTestMP instance = (InvocationTestMP) invoker.newInstance();
    BasicStatsCollector statsCollector = new BasicStatsCollector();
    // pre-condition assertion
    assertNull(prototype.lastStringHandlerValue);
    assertNull(instance.lastStringHandlerValue);
    String message = "foo";
    Object o = invoker.invoke(instance, message, statsCollector);
    assertEquals(new Integer(42), o);
    // we assert that the prototype is still null to check for bad code
    assertNull(prototype.lastStringHandlerValue);
    assertEquals(message, instance.lastStringHandlerValue);
}
Also used : BasicStatsCollector(com.nokia.dempsy.monitoring.basic.BasicStatsCollector) LifecycleHelper(com.nokia.dempsy.container.internal.LifecycleHelper) Test(org.junit.Test)

Aggregations

LifecycleHelper (com.nokia.dempsy.container.internal.LifecycleHelper)10 Test (org.junit.Test)9 BasicStatsCollector (com.nokia.dempsy.monitoring.basic.BasicStatsCollector)4