Search in sources :

Example 1 with MockService

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

the class WorkflowWithObjectPoolTest method testPopulatePool_FailToInit.

@Test(expected = CoreException.class)
public void testPopulatePool_FailToInit() throws Exception {
    setMinIdle(10);
    setServiceCollection(new ServiceList(new MockService(MockService.FailureCondition.Lifecycle)));
    setInitWaitTime(new TimeInterval(1L, TimeUnit.SECONDS));
    GenericObjectPool<Worker> pool = (GenericObjectPool<Worker>) createObjectPool();
    try {
        populatePool(pool);
    } finally {
        Closer.closeQuietly(pool);
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) MockService(com.adaptris.core.stubs.MockService) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) Test(org.junit.Test)

Example 2 with MockService

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

the class SharedComponentListTest method testRemoveService_unbindsJNDI.

@Test
public void testRemoveService_unbindsJNDI() throws Exception {
    Adapter adapter = new Adapter();
    adapter.setUniqueId(getName());
    MockService mockService = new MockService();
    adapter.getSharedComponents().addService(mockService);
    Properties env = new Properties();
    env.put(Context.INITIAL_CONTEXT_FACTORY, JndiContextFactory.class.getName());
    InitialContext initialContext = new InitialContext(env);
    try {
        start(adapter);
        Service lookedup = (Service) initialContext.lookup("adapter:comp/env/" + mockService.getUniqueId());
        assertNotNull(lookedup);
        assertEquals(mockService.getUniqueId(), lookedup.getUniqueId());
        adapter.getSharedComponents().removeService(mockService.getUniqueId());
        try {
            initialContext.lookup("adapter:comp/env/" + mockService.getUniqueId());
            fail();
        } catch (NamingException expected) {
        }
    } finally {
        stop(adapter);
    }
}
Also used : MockService(com.adaptris.core.stubs.MockService) MockService(com.adaptris.core.stubs.MockService) LogMessageService(com.adaptris.core.services.LogMessageService) NamingException(javax.naming.NamingException) Properties(java.util.Properties) PooledConnectionProperties(com.adaptris.core.jdbc.PooledConnectionProperties) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 3 with MockService

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

the class ServiceWorkerPoolTest method testWarmup_WithException.

@Test
public void testWarmup_WithException() throws Exception {
    GenericObjectPool<ServiceWorkerPool.Worker> objPool = null;
    try {
        ServiceWorkerPool worker = new ServiceWorkerPool(new MockService(FailureCondition.Lifecycle), null, 10);
        objPool = worker.createCommonsObjectPool();
        worker.warmup(objPool);
        fail();
    } catch (CoreException expected) {
    } finally {
        Closer.closeQuietly(objPool);
    }
}
Also used : CoreException(com.adaptris.core.CoreException) MockService(com.adaptris.core.stubs.MockService) Test(org.junit.Test)

Example 4 with MockService

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

the class SharedServiceTest method testDoService.

@Test
public void testDoService() throws Exception {
    MockService mockService = new MockService(getName());
    SharedService sharedService = new SharedService(getName());
    Adapter adapter = createAdapterForSharedService(sharedService, mockService);
    try {
        LifecycleHelper.initAndStart(adapter);
        AdaptrisMessage msg = DefaultMessageFactory.getDefaultInstance().newMessage();
        sharedService.doService(msg);
        assertEquals(1, ((MockService) sharedService.getClonedService()).callCount);
        MleMarker marker = msg.getMessageLifecycleEvent().getMleMarkers().get(0);
        assertEquals(MockService.class.getName(), marker.getName());
        assertEquals(getName(), marker.getQualifier());
        assertEquals(true, marker.getWasSuccessful());
    } finally {
        LifecycleHelper.stopAndClose(adapter);
    }
}
Also used : MockService(com.adaptris.core.stubs.MockService) Test(org.junit.Test)

Example 5 with MockService

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

the class SharedComponentListTest method testAddServices.

@Test
public void testAddServices() throws Exception {
    SharedComponentList list = new SharedComponentList();
    try {
        list.addServices(null);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    assertEquals(0, list.getConnections().size());
    // This is valid, we don't check for duplicates until later.
    MockService service1 = new MockService();
    MockService service2 = new MockService();
    service2.setUniqueId(service1.getUniqueId());
    Collection<Service> rejected = list.addServices(Arrays.asList(new Service[] { service1, service2 }));
    assertEquals(1, list.getServices().size());
    assertEquals(1, rejected.size());
}
Also used : MockService(com.adaptris.core.stubs.MockService) MockService(com.adaptris.core.stubs.MockService) LogMessageService(com.adaptris.core.services.LogMessageService) Test(org.junit.Test)

Aggregations

MockService (com.adaptris.core.stubs.MockService)7 Test (org.junit.Test)7 LogMessageService (com.adaptris.core.services.LogMessageService)3 PooledConnectionProperties (com.adaptris.core.jdbc.PooledConnectionProperties)2 Properties (java.util.Properties)2 InitialContext (javax.naming.InitialContext)2 CoreException (com.adaptris.core.CoreException)1 TimeInterval (com.adaptris.util.TimeInterval)1 NamingException (javax.naming.NamingException)1 GenericObjectPool (org.apache.commons.pool2.impl.GenericObjectPool)1