Search in sources :

Example 1 with AdaptrisConnection

use of com.adaptris.core.AdaptrisConnection in project interlok by adaptris.

the class JndiHelperTest method testBindCollection.

@Test
public void testBindCollection() throws Exception {
    NullConnection connection = new NullConnection();
    connection.setUniqueId(getName());
    ArrayList<AdaptrisConnection> connectionList = new ArrayList<AdaptrisConnection>();
    connectionList.add(connection);
    InitialContext initialContext = new InitialContext(env);
    try {
        JndiHelper.bind(connectionList);
        NullConnection lookedup = (NullConnection) initialContext.lookup("adapter:comp/env/" + getName());
        assertNotNull(lookedup);
        assertTrue(lookedup instanceof NullConnection);
        assertEquals(getName(), lookedup.getUniqueId());
    } finally {
        JndiHelper.unbindQuietly(initialContext, connectionList, true);
    }
}
Also used : AdaptrisConnection(com.adaptris.core.AdaptrisConnection) ArrayList(java.util.ArrayList) NullConnection(com.adaptris.core.NullConnection) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 2 with AdaptrisConnection

use of com.adaptris.core.AdaptrisConnection in project interlok by adaptris.

the class JndiHelperTest method testUnbindCollection_Debug.

@Test
public void testUnbindCollection_Debug() throws Exception {
    NullConnection connection = new NullConnection();
    connection.setUniqueId(getName());
    ArrayList<AdaptrisConnection> connectionList = new ArrayList<AdaptrisConnection>();
    connectionList.add(connection);
    InitialContext initialContext = new InitialContext(env);
    JndiHelper.bind(connectionList);
    JndiHelper.unbind(connectionList, true);
    try {
        JndiHelper.unbind(connectionList, true);
        fail();
    } catch (CoreException expected) {
    }
}
Also used : CoreException(com.adaptris.core.CoreException) AdaptrisConnection(com.adaptris.core.AdaptrisConnection) ArrayList(java.util.ArrayList) NullConnection(com.adaptris.core.NullConnection) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 3 with AdaptrisConnection

use of com.adaptris.core.AdaptrisConnection in project interlok by adaptris.

the class JndiHelperTest method testBindCollection_Debug.

@Test
public void testBindCollection_Debug() throws Exception {
    NullConnection connection = new NullConnection();
    connection.setUniqueId(getName());
    ArrayList<AdaptrisConnection> connectionList = new ArrayList<AdaptrisConnection>();
    connectionList.add(connection);
    InitialContext initialContext = new InitialContext(env);
    try {
        JndiHelper.bind(connectionList, true);
        NullConnection lookedup = (NullConnection) initialContext.lookup("adapter:comp/env/" + getName());
        assertNotNull(lookedup);
        assertTrue(lookedup instanceof NullConnection);
        assertEquals(getName(), lookedup.getUniqueId());
    } finally {
        JndiHelper.unbindQuietly(initialContext, connectionList, true);
    }
}
Also used : AdaptrisConnection(com.adaptris.core.AdaptrisConnection) ArrayList(java.util.ArrayList) NullConnection(com.adaptris.core.NullConnection) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 4 with AdaptrisConnection

use of com.adaptris.core.AdaptrisConnection in project interlok by adaptris.

the class JndiHelperTest method testUnbindCollection_WithContext.

@Test
public void testUnbindCollection_WithContext() throws Exception {
    NullConnection connection = new NullConnection();
    connection.setUniqueId(getName());
    ArrayList<AdaptrisConnection> connectionList = new ArrayList<AdaptrisConnection>();
    connectionList.add(connection);
    InitialContext initialContext = new InitialContext(env);
    JndiHelper.bind(initialContext, connectionList, true);
    JndiHelper.unbind(initialContext, connectionList, true);
    try {
        JndiHelper.unbind(initialContext, connectionList, true);
        fail();
    } catch (CoreException expected) {
    }
}
Also used : CoreException(com.adaptris.core.CoreException) AdaptrisConnection(com.adaptris.core.AdaptrisConnection) ArrayList(java.util.ArrayList) NullConnection(com.adaptris.core.NullConnection) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 5 with AdaptrisConnection

use of com.adaptris.core.AdaptrisConnection in project interlok by adaptris.

the class AdapterManager method addAndBindSharedConnection.

@Override
public boolean addAndBindSharedConnection(String xmlString) throws CoreException, IllegalStateException {
    ensureState(StartedState.getInstance(), InitialisedState.getInstance(), StoppedState.getInstance());
    AdaptrisConnection comp = (AdaptrisConnection) DefaultMarshaller.getDefaultMarshaller().unmarshal(xmlString);
    boolean result = getWrappedComponent().getSharedComponents().addConnection(comp);
    if (result) {
        getWrappedComponent().getSharedComponents().bindJNDI(comp.getUniqueId());
        marshalAndSendNotification();
    }
    return result;
}
Also used : AdaptrisConnection(com.adaptris.core.AdaptrisConnection)

Aggregations

AdaptrisConnection (com.adaptris.core.AdaptrisConnection)15 ArrayList (java.util.ArrayList)9 NullConnection (com.adaptris.core.NullConnection)6 Test (org.junit.Test)6 InitialContext (javax.naming.InitialContext)5 CoreException (com.adaptris.core.CoreException)4 Pattern (java.util.regex.Pattern)2 AllowsRetriesConnection (com.adaptris.core.AllowsRetriesConnection)1 ServiceException (com.adaptris.core.ServiceException)1 DatabaseConnection (com.adaptris.core.jdbc.DatabaseConnection)1 Connection (java.sql.Connection)1