Search in sources :

Example 61 with Context

use of javax.naming.Context in project spring-framework by spring-projects.

the class SimpleRemoteSlsbInvokerInterceptorTests method testInvokesMethodOnEjbInstanceWithBusinessInterface.

@Test
public void testInvokesMethodOnEjbInstanceWithBusinessInterface() throws Exception {
    Object retVal = new Object();
    final RemoteInterface ejb = mock(RemoteInterface.class);
    given(ejb.targetMethod()).willReturn(retVal);
    final String jndiName = "foobar";
    Context mockContext = mockContext(jndiName, ejb);
    SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
    BusinessInterface target = (BusinessInterface) configuredProxy(si, BusinessInterface.class);
    assertTrue(target.targetMethod() == retVal);
    verify(mockContext).close();
    verify(ejb).remove();
}
Also used : Context(javax.naming.Context) EJBObject(javax.ejb.EJBObject) Test(org.junit.Test)

Example 62 with Context

use of javax.naming.Context in project spring-framework by spring-projects.

the class SimpleRemoteSlsbInvokerInterceptorTests method testInvokesMethodOnEjbInstanceWithHomeInterface.

@Test
public void testInvokesMethodOnEjbInstanceWithHomeInterface() throws Exception {
    Object retVal = new Object();
    final RemoteInterface ejb = mock(RemoteInterface.class);
    given(ejb.targetMethod()).willReturn(retVal);
    final String jndiName = "foobar";
    Context mockContext = mockContext(jndiName, ejb);
    SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
    si.setHomeInterface(SlsbHome.class);
    RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class);
    assertTrue(target.targetMethod() == retVal);
    verify(mockContext).close();
    verify(ejb).remove();
}
Also used : Context(javax.naming.Context) EJBObject(javax.ejb.EJBObject) Test(org.junit.Test)

Example 63 with Context

use of javax.naming.Context in project spring-framework by spring-projects.

the class SimpleRemoteSlsbInvokerInterceptorTests method testInvokesMethodOnEjbInstanceWithBusinessInterfaceWithRemoteException.

@Test
public void testInvokesMethodOnEjbInstanceWithBusinessInterfaceWithRemoteException() throws Exception {
    final RemoteInterface ejb = mock(RemoteInterface.class);
    given(ejb.targetMethod()).willThrow(new RemoteException());
    final String jndiName = "foobar";
    Context mockContext = mockContext(jndiName, ejb);
    SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
    BusinessInterface target = (BusinessInterface) configuredProxy(si, BusinessInterface.class);
    try {
        target.targetMethod();
        fail("Should have thrown RemoteAccessException");
    } catch (RemoteAccessException ex) {
    // expected
    }
    verify(mockContext).close();
    verify(ejb).remove();
}
Also used : Context(javax.naming.Context) RemoteAccessException(org.springframework.remoting.RemoteAccessException) RemoteException(java.rmi.RemoteException) Test(org.junit.Test)

Example 64 with Context

use of javax.naming.Context in project spring-framework by spring-projects.

the class JndiTemplateTests method testLookupReturnsNull.

@Test
public void testLookupReturnsNull() throws Exception {
    String name = "foo";
    final Context context = mock(Context.class);
    given(context.lookup(name)).willReturn(null);
    JndiTemplate jt = new JndiTemplate() {

        @Override
        protected Context createInitialContext() {
            return context;
        }
    };
    try {
        jt.lookup(name);
        fail("Should have thrown NamingException");
    } catch (NameNotFoundException ex) {
    // Ok
    }
    verify(context).close();
}
Also used : Context(javax.naming.Context) NameNotFoundException(javax.naming.NameNotFoundException) Test(org.junit.Test)

Example 65 with Context

use of javax.naming.Context in project spring-framework by spring-projects.

the class JndiTemplateTests method testLookupSucceeds.

@Test
public void testLookupSucceeds() throws Exception {
    Object o = new Object();
    String name = "foo";
    final Context context = mock(Context.class);
    given(context.lookup(name)).willReturn(o);
    JndiTemplate jt = new JndiTemplate() {

        @Override
        protected Context createInitialContext() {
            return context;
        }
    };
    Object o2 = jt.lookup(name);
    assertEquals(o, o2);
    verify(context).close();
}
Also used : Context(javax.naming.Context) Test(org.junit.Test)

Aggregations

Context (javax.naming.Context)507 InitialContext (javax.naming.InitialContext)250 Test (org.junit.Test)173 NamingException (javax.naming.NamingException)156 DataSource (javax.sql.DataSource)72 Properties (java.util.Properties)67 Connection (java.sql.Connection)62 NameNotFoundException (javax.naming.NameNotFoundException)52 UserTransaction (javax.transaction.UserTransaction)48 SQLException (java.sql.SQLException)46 IOException (java.io.IOException)44 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)44 Statement (java.sql.Statement)42 Name (javax.naming.Name)38 Hashtable (java.util.Hashtable)35 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)27 BeanContext (org.apache.openejb.BeanContext)27 Binding (javax.naming.Binding)25 Reference (javax.naming.Reference)25 NotContextException (javax.naming.NotContextException)23