Search in sources :

Example 86 with Context

use of javax.naming.Context in project aries by apache.

the class ContextManagerService method getInitialContext.

private Context getInitialContext(Map<?, ?> environment) throws NamingException {
    Hashtable<?, ?> env = Utils.toHashtable(environment);
    Context context = ContextHelper.getInitialContext(callerContext, env);
    contexts.add(context);
    return context;
}
Also used : DirContext(javax.naming.directory.DirContext) Context(javax.naming.Context) BundleContext(org.osgi.framework.BundleContext)

Example 87 with Context

use of javax.naming.Context in project aries by apache.

the class InitialContextTest method testURLContextErrorPropagation.

@Test
public void testURLContextErrorPropagation() throws Exception {
    ObjectFactory of = new ObjectFactory() {

        public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
            throw new Exception("doh");
        }
    };
    registerURLObjectFactory(of, "test");
    ic = initialContext();
    try {
        ic.lookup("test:something");
        Assert.fail("Expected NamingException");
    } catch (NamingException ne) {
        assertNotNull(ne.getCause());
        assertEquals("doh", ne.getCause().getMessage());
    }
}
Also used : InitialLdapContext(javax.naming.ldap.InitialLdapContext) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) BundleContext(org.osgi.framework.BundleContext) LdapContext(javax.naming.ldap.LdapContext) ObjectFactory(javax.naming.spi.ObjectFactory) Hashtable(java.util.Hashtable) NamingException(javax.naming.NamingException) NoInitialContextException(javax.naming.NoInitialContextException) NamingException(javax.naming.NamingException) Name(javax.naming.Name) Test(org.junit.Test)

Example 88 with Context

use of javax.naming.Context in project aries by apache.

the class InitialContextTest method dummyContext.

/**
   * Creates a context that always returns the given object
   * @param toReturn
   * @return
   */
private Context dummyContext(Object toReturn) {
    Context ctx = Skeleton.newMock(Context.class);
    Skeleton.getSkeleton(ctx).setReturnValue(new MethodCall(Context.class, "lookup", String.class), toReturn);
    Skeleton.getSkeleton(ctx).setReturnValue(new MethodCall(Context.class, "lookup", Name.class), toReturn);
    return ctx;
}
Also used : InitialLdapContext(javax.naming.ldap.InitialLdapContext) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) BundleContext(org.osgi.framework.BundleContext) LdapContext(javax.naming.ldap.LdapContext) MethodCall(org.apache.aries.unittest.mocks.MethodCall) Name(javax.naming.Name)

Example 89 with Context

use of javax.naming.Context in project aries by apache.

the class ObjectFactoryTest method testFactoriesThatDoUnsafeCastsAreIgnored.

@Test
public void testFactoriesThatDoUnsafeCastsAreIgnored() throws Exception {
    Hashtable<String, Object> props = new Hashtable<String, Object>();
    props.put("aries.object.factory.requires.reference", Boolean.TRUE);
    bc.registerService(ObjectFactory.class.getName(), new ObjectFactory() {

        public Object getObjectInstance(Object arg0, Name arg1, Context arg2, Hashtable<?, ?> arg3) throws Exception {
            return (Reference) arg0;
        }
    }, props);
    NamingManager.getObjectInstance("Some dummy data", null, null, env);
}
Also used : BundleContext(org.osgi.framework.BundleContext) Context(javax.naming.Context) ObjectFactory(javax.naming.spi.ObjectFactory) Hashtable(java.util.Hashtable) Name(javax.naming.Name) Test(org.junit.Test)

Example 90 with Context

use of javax.naming.Context in project geode by apache.

the class QueryAndJtaJUnitTest method testFailedIndexUpdateOnCommitForPut.

@Test
public void testFailedIndexUpdateOnCommitForPut() throws Exception {
    Person.THROW_ON_INDEX = true;
    AttributesFactory af = new AttributesFactory();
    af.setDataPolicy(DataPolicy.REPLICATE);
    SimpleListener sl = new SimpleListener();
    af.setCacheListener(sl);
    Region region = cache.createRegion("sample", af.create());
    qs.createIndex("foo", IndexType.FUNCTIONAL, "index", "/sample");
    Context ctx = cache.getJNDIContext();
    Integer x = new Integer(0);
    region.getCache().getCacheTransactionManager().begin();
    region.create(x, new Person("xyz", 45));
    try {
        region.getCache().getCacheTransactionManager().commit();
        fail("commit should have thrown an exception because the index maintenance threw");
    } catch (org.apache.geode.cache.query.IndexMaintenanceException ie) {
    // this is the desired case
    }
    Person p = (Person) region.get(x);
    assertEquals("object shouldn't have made it into region", null, p);
    assertEquals(0, sl.creates);
    assertEquals(0, sl.updates);
}
Also used : Context(javax.naming.Context) AttributesFactory(org.apache.geode.cache.AttributesFactory) Region(org.apache.geode.cache.Region) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

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