Java 8 InitialContextFactory - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 InitialContextFactory class.

This code example shows how to use the following methods:getInitialContext
 
        Context context = mock(Context.class);
        when(context.lookup(NAME)).thenReturn(RESOLVED_NAME);
 
        InitialContextFactory jndiContextFactory = mock(InitialContextFactory.class);
        when(jndiContextFactory.getInitialContext(any(Hashtable.class))).thenReturn(context);
 
        CachedJndiNameResolver jndiNameResolver = new CachedJndiNameResolver();
        jndiNameResolver.setContextFactory(jndiContextFactory);
        jndiNameResolver.setJndiInitialFactory("initialFactory");
        jndiNameResolver.initialise();
 
        // First lookup should use the context, second should use the cache 
        assertEquals(RESOLVED_NAME, jndiNameResolver.lookup(NAME));
        assertEquals(RESOLVED_NAME, jndiNameResolver.lookup(NAME));
 
        Mockito.verify(context, times(1)).lookup(NAME);
    } 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getInitialContext
        super.setUp(); 
 
        configureEnvironment(); 
 
        InitialContextFactory factory = new ActiveMQInitialContextFactory();
        context = factory.getInitialContext(environment);
        assertTrue("No context created", context != null);
    } 
 
    /** 
     * Stops all existing ActiveMQConnectionFactory in Context. 
     * 
     * @throws javax.naming.NamingException 
     */ 
    @Override 
    protected void tearDown() throws NamingException, JMSException {
        NamingEnumeration<Binding> iter = context.listBindings("");
        while (iter.hasMore()) {
            Binding binding = iter.next();
            Object connFactory = binding.getObject();
5
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Java 8 InitialContextFactory Methods: