Search in sources :

Example 31 with MockConnection

use of com.adaptris.core.stubs.MockConnection in project interlok by adaptris.

the class InitialisedStateTest method testInitialised_To_Initialised.

@Test
public void testInitialised_To_Initialised() throws Exception {
    MockConnection component = new MockConnection();
    component.requestInit();
    InitialisedState state = InitialisedState.getInstance();
    state.requestInit(component);
    assertEquals(InitialisedState.getInstance(), component.retrieveComponentState());
    assertEquals(1, component.getInitCount());
}
Also used : MockConnection(com.adaptris.core.stubs.MockConnection) Test(org.junit.Test)

Example 32 with MockConnection

use of com.adaptris.core.stubs.MockConnection in project interlok by adaptris.

the class FilteredSharedComponentStartTest method testFilteredStart_Excludes.

@Test
public void testFilteredStart_Excludes() throws Exception {
    Adapter adapter = new Adapter();
    adapter.setUniqueId(getName());
    MockConnection sc1 = new MockConnection(getName() + "_1");
    MockConnection sc2 = new MockConnection(getName() + "_2");
    MockConnection sc3 = new MockConnection(getClass().getSimpleName() + "_1");
    MockConnection sc4 = new MockConnection(getClass().getSimpleName() + "_2");
    MockConnection sc5 = new MockConnection(getClass().getSimpleName() + "_3");
    try {
        adapter.getSharedComponents().addConnection(sc1);
        adapter.getSharedComponents().addConnection(sc2);
        adapter.getSharedComponents().addConnection(sc3);
        adapter.getSharedComponents().addConnection(sc4);
        adapter.getSharedComponents().addConnection(sc5);
        assertEquals(5, adapter.getSharedComponents().getConnections().size());
        FilteredSharedComponentStart starter = new FilteredSharedComponentStart();
        starter.addExclude(".*" + getClass().getSimpleName() + ".*");
        adapter.getSharedComponents().setLifecycleStrategy(starter);
        adapter.requestInit();
        assertEquals(InitialisedState.getInstance(), adapter.retrieveComponentState());
        assertEquals(InitialisedState.getInstance(), sc1.retrieveComponentState());
        assertEquals(InitialisedState.getInstance(), sc2.retrieveComponentState());
        assertEquals(ClosedState.getInstance(), sc3.retrieveComponentState());
        assertEquals(ClosedState.getInstance(), sc4.retrieveComponentState());
        assertEquals(ClosedState.getInstance(), sc5.retrieveComponentState());
        adapter.requestStart();
        assertEquals(StartedState.getInstance(), adapter.retrieveComponentState());
        assertEquals(StartedState.getInstance(), sc1.retrieveComponentState());
        assertEquals(StartedState.getInstance(), sc2.retrieveComponentState());
        assertEquals(ClosedState.getInstance(), sc3.retrieveComponentState());
        assertEquals(ClosedState.getInstance(), sc4.retrieveComponentState());
        assertEquals(ClosedState.getInstance(), sc5.retrieveComponentState());
    } finally {
        stop(adapter);
    }
}
Also used : Adapter(com.adaptris.core.Adapter) MockConnection(com.adaptris.core.stubs.MockConnection) Test(org.junit.Test)

Example 33 with MockConnection

use of com.adaptris.core.stubs.MockConnection in project interlok by adaptris.

the class FilteredSharedComponentStartTest method testFilteredStart_Includes.

@Test
public void testFilteredStart_Includes() throws Exception {
    Adapter adapter = new Adapter();
    adapter.setUniqueId(getName());
    MockConnection sc1 = new MockConnection(getName() + "_1");
    MockConnection sc2 = new MockConnection(getName() + "_2");
    MockConnection sc3 = new MockConnection(getClass().getSimpleName() + "_1");
    MockConnection sc4 = new MockConnection(getClass().getSimpleName() + "_2");
    MockConnection sc5 = new MockConnection(getClass().getSimpleName() + "_3");
    try {
        adapter.getSharedComponents().addConnection(sc1);
        adapter.getSharedComponents().addConnection(sc2);
        adapter.getSharedComponents().addConnection(sc3);
        adapter.getSharedComponents().addConnection(sc4);
        adapter.getSharedComponents().addConnection(sc5);
        assertEquals(5, adapter.getSharedComponents().getConnections().size());
        FilteredSharedComponentStart starter = new FilteredSharedComponentStart();
        starter.addInclude(".*" + getName() + ".*");
        adapter.getSharedComponents().setLifecycleStrategy(starter);
        adapter.requestInit();
        assertEquals(InitialisedState.getInstance(), adapter.retrieveComponentState());
        assertEquals(InitialisedState.getInstance(), sc1.retrieveComponentState());
        assertEquals(InitialisedState.getInstance(), sc2.retrieveComponentState());
        assertEquals(ClosedState.getInstance(), sc3.retrieveComponentState());
        assertEquals(ClosedState.getInstance(), sc4.retrieveComponentState());
        assertEquals(ClosedState.getInstance(), sc5.retrieveComponentState());
        adapter.requestStart();
        assertEquals(StartedState.getInstance(), adapter.retrieveComponentState());
        assertEquals(StartedState.getInstance(), sc1.retrieveComponentState());
        assertEquals(StartedState.getInstance(), sc2.retrieveComponentState());
        assertEquals(ClosedState.getInstance(), sc3.retrieveComponentState());
        assertEquals(ClosedState.getInstance(), sc4.retrieveComponentState());
        assertEquals(ClosedState.getInstance(), sc5.retrieveComponentState());
    } finally {
        stop(adapter);
    }
}
Also used : Adapter(com.adaptris.core.Adapter) MockConnection(com.adaptris.core.stubs.MockConnection) Test(org.junit.Test)

Example 34 with MockConnection

use of com.adaptris.core.stubs.MockConnection in project interlok by adaptris.

the class StartedStateTest method testStarted_To_Started.

@Test
public void testStarted_To_Started() throws Exception {
    MockConnection component = new MockConnection();
    component.requestStart();
    StartedState state = StartedState.getInstance();
    state.requestStart(component);
    // This will do nothing.
    assertEquals(StartedState.getInstance(), component.retrieveComponentState());
    assertEquals(1, component.getInitCount());
    assertEquals(1, component.getStartCount());
    assertEquals(0, component.getStopCount());
    assertEquals(0, component.getCloseCount());
}
Also used : MockConnection(com.adaptris.core.stubs.MockConnection) Test(org.junit.Test)

Example 35 with MockConnection

use of com.adaptris.core.stubs.MockConnection in project interlok by adaptris.

the class StartedStateTest method testStarted_To_Closed.

@Test
public void testStarted_To_Closed() throws Exception {
    MockConnection component = new MockConnection();
    component.requestStart();
    StartedState state = StartedState.getInstance();
    state.requestClose(component);
    assertEquals(ClosedState.getInstance(), component.retrieveComponentState());
    assertEquals(1, component.getInitCount());
    assertEquals(1, component.getStartCount());
    assertEquals(1, component.getStopCount());
    assertEquals(1, component.getCloseCount());
}
Also used : MockConnection(com.adaptris.core.stubs.MockConnection) Test(org.junit.Test)

Aggregations

MockConnection (com.adaptris.core.stubs.MockConnection)49 Test (org.junit.Test)49 Adapter (com.adaptris.core.Adapter)7 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)5 TimeInterval (com.adaptris.util.TimeInterval)5 TimeoutException (java.util.concurrent.TimeoutException)5 ObjectName (javax.management.ObjectName)5 MockMessageConsumer (com.adaptris.core.stubs.MockMessageConsumer)3 FilteredSharedComponentStart (com.adaptris.core.lifecycle.FilteredSharedComponentStart)1 ChannelRestartConnectionErrorHandler (com.adaptris.core.stubs.ChannelRestartConnectionErrorHandler)1 FailFirstMockMessageProducer (com.adaptris.core.stubs.FailFirstMockMessageProducer)1 MockChannel (com.adaptris.core.stubs.MockChannel)1 SimpleIdGenerator (com.adaptris.util.SimpleIdGenerator)1