Package javax.naming.event

Examples of javax.naming.event.EventDirContext


    public void testContextClose() throws Exception
    {
        String userDn = "uid=admin,ou=system";
        TestListener listener = new TestListener();
        LdapConnection connection = getConnectionAs( getService(), userDn, "secret" );
        EventDirContext ctx = ( EventDirContext ) getSystemContext( getService() ).lookup( "" );
        ctx.addNamingListener( "", SearchControls.SUBTREE_SCOPE, listener );

        Entry testEntry = new DefaultEntry( "ou=testEntry,ou=system",
            "objectClass: top",
            "objectClass: organizationalUnit",
            "ou", "testentry" );

        connection.add( testEntry );

        //  Wait 1 second, as the process is asynchronous
        Thread.sleep( 1000 );

        assertEquals( 1, listener.getEventRecords().size() );
        EventRecord rec = ( EventRecord ) listener.getEventRecords().get( 0 );
        assertEquals( "objectAdded", rec.method );
        assertEquals( ctx, rec.event.getSource() );

        ctx.close();
        connection.delete( "ou=testentry,ou=system" );

        //  Wait 1 second, as the process is asynchronous
        Thread.sleep( 1000 );
View Full Code Here


     */
    @Test
    public void testRemoveNamingListener() throws Exception
    {
        TestListener listener = new TestListener();
        EventDirContext ctx = ( EventDirContext ) getSystemContext( getService() ).lookup( "" );
        ctx.addNamingListener( "", SearchControls.SUBTREE_SCOPE, listener );

        Attributes testEntry = LdifUtils.createJndiAttributes(
                "objectClass: top",
                "objectClass: organizationalUnit",
                "ou", "testentry");

        ctx.createSubcontext( "ou=testentry", testEntry );

        //  Wait 1 second, as the process is asynchronous
        Thread.sleep( 1000 );

        assertEquals( 1, listener.getEventRecords().size() );
        EventRecord rec = ( EventRecord ) listener.getEventRecords().get( 0 );
        assertEquals( "objectAdded", rec.method );
        assertEquals( ctx, rec.event.getSource() );

        ctx.removeNamingListener( listener );
        ctx.destroySubcontext( "ou=testentry" );

        //  Wait 1 second, as the process is asynchronous
        Thread.sleep( 1000 );

        assertEquals( 1, listener.getEventRecords().size() );
        rec = ( EventRecord ) listener.getEventRecords().get( 0 );
        assertEquals( "objectAdded", rec.method );
        assertEquals( ctx, rec.event.getSource() );

        // read the entry once again just to make sure
        ctx.createSubcontext( "ou=testentry", testEntry );
       
        //  Wait 1 second, as the process is asynchronous
        Thread.sleep( 1000 );

        assertEquals( 1, listener.getEventRecords().size() );
View Full Code Here

     */
    @Test
    public void testContextClose() throws Exception
    {
        TestListener listener = new TestListener();
        EventDirContext ctx = ( EventDirContext ) getSystemContext( getService() ).lookup( "" );
        ctx.addNamingListener( "", SearchControls.SUBTREE_SCOPE, listener );

        Attributes testEntry = LdifUtils.createJndiAttributes(
            "objectClass: top",
            "objectClass: organizationalUnit",
            "ou", "testentry" );

        ctx.createSubcontext( "ou=testentry", testEntry );

        //  Wait 1 second, as the process is asynchronous
        Thread.sleep( 1000 );

        assertEquals( 1, listener.getEventRecords().size() );
        EventRecord rec = ( EventRecord ) listener.getEventRecords().get( 0 );
        assertEquals( "objectAdded", rec.method );
        assertEquals( ctx, rec.event.getSource() );

        ctx.close();
        ctx = ( EventDirContext ) getSystemContext( getService() ).lookup( "" );
        ctx.destroySubcontext( "ou=testentry" );

        //  Wait 1 second, as the process is asynchronous
        Thread.sleep( 1000 );

        assertEquals( 1, listener.getEventRecords().size() );
        rec = ( EventRecord ) listener.getEventRecords().get( 0 );
        assertEquals( "objectAdded", rec.method );

        // readd the entry once again just to make sure
        ctx.createSubcontext( "ou=testentry", testEntry );
       
        //  Wait 1 second, as the process is asynchronous
        Thread.sleep( 1000 );

        assertEquals( 1, listener.getEventRecords().size() );
View Full Code Here

        LdapContext context = new InitialLdapContext(env, null);

        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_SEARCH_RESULT_DONE,
                new EncodableLdapResult(), null) });
        EventDirContext eventContext = (EventDirContext) context.lookup("");

        assertTrue(eventContext.targetMustExist());

        MockUnsolicitedNotificationListener listener = new MockUnsolicitedNotificationListener();

        MockLdapMessage message = new MockLdapMessage(new LdapMessage(
                LdapASN1Constant.OP_EXTENDED_RESPONSE,
                new DisconnectResponse(), null));
        message.setMessageId(0);
        server.setResponseSeq(new LdapMessage[] { message });

        eventContext.addNamingListener("", "(objectclass=cn)", new Object[0],
                new SearchControls(), listener);
        server.disconnectNotify();
        Thread.sleep(500);
        assertNull(listener.exceptionEvent);
        assertNotNull(listener.unsolicatedEvent);
View Full Code Here

        }

        // register persistent search event listener
        if (searchEventListener) {
            LOG.info("registering persistent search listener...");
            EventDirContext eventContext = (EventDirContext) context.lookup("");
            eventContext.addNamingListener(base, searchFilter, searchControls, this);
        } else { // otherwise close context (i.e. connection as it is no longer needed)
            context.close();
        }
    }
View Full Code Here

        }

        // register persistent search event listener
        if (searchEventListener) {
            LOG.info("registering persistent search listener...");
            EventDirContext eventContext = (EventDirContext) context.lookup("");
            eventContext.addNamingListener(base, searchFilter, searchControls, this);
        } else { // otherwise close context (i.e. connection as it is no longer needed)
            context.close();
        }
    }
View Full Code Here

     */
    @Test
    public void testRemoveNamingListener() throws Exception
    {
        TestListener listener = new TestListener();
        EventDirContext ctx = ( EventDirContext ) getSystemContext( getService() ).lookup( "" );
        ctx.addNamingListener( "", SearchControls.SUBTREE_SCOPE, listener );

        Attributes testEntry = LdifUtils.createJndiAttributes(
            "objectClass: top",
            "objectClass: organizationalUnit",
            "ou", "testentry" );

        ctx.createSubcontext( "ou=testentry", testEntry );

        //  Wait 1 second, as the process is asynchronous
        Thread.sleep( 1000 );

        assertEquals( 1, listener.getEventRecords().size() );
        EventRecord rec = ( EventRecord ) listener.getEventRecords().get( 0 );
        assertEquals( "objectAdded", rec.method );
        assertEquals( ctx, rec.event.getSource() );

        ctx.removeNamingListener( listener );
        ctx.destroySubcontext( "ou=testentry" );

        //  Wait 1 second, as the process is asynchronous
        Thread.sleep( 1000 );

        assertEquals( 1, listener.getEventRecords().size() );
        rec = ( EventRecord ) listener.getEventRecords().get( 0 );
        assertEquals( "objectAdded", rec.method );
        assertEquals( ctx, rec.event.getSource() );

        // read the entry once again just to make sure
        ctx.createSubcontext( "ou=testentry", testEntry );

        //  Wait 1 second, as the process is asynchronous
        Thread.sleep( 1000 );

        assertEquals( 1, listener.getEventRecords().size() );
View Full Code Here

     */
    @Test
    public void testContextClose() throws Exception
    {
        TestListener listener = new TestListener();
        EventDirContext ctx = ( EventDirContext ) getSystemContext( getService() ).lookup( "" );
        ctx.addNamingListener( "", SearchControls.SUBTREE_SCOPE, listener );

        Attributes testEntry = LdifUtils.createJndiAttributes(
            "objectClass: top",
            "objectClass: organizationalUnit",
            "ou", "testentry" );

        ctx.createSubcontext( "ou=testentry", testEntry );

        //  Wait 1 second, as the process is asynchronous
        Thread.sleep( 1000 );

        assertEquals( 1, listener.getEventRecords().size() );
        EventRecord rec = ( EventRecord ) listener.getEventRecords().get( 0 );
        assertEquals( "objectAdded", rec.method );
        assertEquals( ctx, rec.event.getSource() );

        ctx.close();
        ctx = ( EventDirContext ) getSystemContext( getService() ).lookup( "" );
        ctx.destroySubcontext( "ou=testentry" );

        //  Wait 1 second, as the process is asynchronous
        Thread.sleep( 1000 );

        assertEquals( 1, listener.getEventRecords().size() );
        rec = ( EventRecord ) listener.getEventRecords().get( 0 );
        assertEquals( "objectAdded", rec.method );

        // readd the entry once again just to make sure
        ctx.createSubcontext( "ou=testentry", testEntry );

        //  Wait 1 second, as the process is asynchronous
        Thread.sleep( 1000 );

        assertEquals( 1, listener.getEventRecords().size() );
View Full Code Here

TOP

Related Classes of javax.naming.event.EventDirContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.