Package org.apache.harmony.jndi.provider.ldap.mock

Examples of org.apache.harmony.jndi.provider.ldap.mock.BindResponse


    }

    public void testSearchReferralFollow() throws Exception {
        env.put(Context.REFERRAL, "follow");
        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
        DirContext context = new InitialDirContext(env);

        final MockLdapServer referralServer = new MockLdapServer();
        referralServer.start();

        ASN1Encodable ref = new ASN1Encodable() {

            public void encodeValues(Object[] values) {
                List<byte[]> list = new ArrayList<byte[]>();
                list.add(Utils.getBytes(referralServer.getURL()));
                values[0] = list;
            }

        };

        server.setResponseSeq(new LdapMessage[] {
                new LdapMessage(LdapASN1Constant.OP_SEARCH_RESULT_REF, ref,
                        null),
                new LdapMessage(LdapASN1Constant.OP_SEARCH_RESULT_DONE,
                        new EncodableLdapResult(), null) });

        referralServer.setResponseSeq(new LdapMessage[] {
                new LdapMessage(LdapASN1Constant.OP_BIND_RESPONSE,
                        new BindResponse(), null),
                new LdapMessage(LdapASN1Constant.OP_SEARCH_RESULT_DONE,
                        new EncodableLdapResult(), null) });

        context.search("cn=test", null);
       
View Full Code Here


    }

    public void testReferralFollow() throws Exception {
        env.put(Context.REFERRAL, "follow");
        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
        DirContext context = new InitialDirContext(env);

        MockLdapServer referralServer = new MockLdapServer();
        referralServer.start();

        EncodableLdapResult result = new EncodableLdapResult(
                LdapResult.REFERRAL, "", "", new String[] { referralServer
                        .getURL() });

        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_SEARCH_RESULT_DONE, result, null) });

        referralServer.setResponseSeq(new LdapMessage[] {
                new LdapMessage(LdapASN1Constant.OP_BIND_RESPONSE,
                        new BindResponse(), null),
                new LdapMessage(LdapASN1Constant.OP_SEARCH_RESULT_DONE,
                        new EncodableLdapResult(), null) });

        context.getAttributes("cn=test");
View Full Code Here

        referralServer.stop();
    }

    public void testAddToEnvironment() throws Exception {
        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });

        assertNull(env.get(Context.REFERRAL));

        InitialDirContext initialDirContext = new InitialDirContext(env);

        // Context.REFERRAL changed doesn't cause re-bind operation
        initialDirContext.addToEnvironment(Context.REFERRAL, "ignore");

        assertEquals("ignore", initialDirContext.getEnvironment().get(
                Context.REFERRAL));

        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_DEL_RESPONSE, new EncodableLdapResult(),
                null) });

        initialDirContext.destroySubcontext("cn=test");

        /*
         * Context.SECURITY_AUTHENTICATION will case re-bind when invoke context
         * methods at first time
         */
        Object preValue = initialDirContext.addToEnvironment(
                Context.SECURITY_AUTHENTICATION, "none");
        assertFalse("none".equals(preValue));

        server.setResponseSeq(new LdapMessage[] {
                new LdapMessage(LdapASN1Constant.OP_BIND_RESPONSE,
                        new BindResponse(), null),
                new LdapMessage(LdapASN1Constant.OP_SEARCH_RESULT_DONE,
                        new EncodableLdapResult(), null) });

        initialDirContext.lookup("");

        preValue = initialDirContext.addToEnvironment(
                Context.SECURITY_AUTHENTICATION, "simple");
        assertFalse("simple".equals(preValue));

        // initialDirContext is shared connection, will create new connection
        server = new MockLdapServer(server);
        server.start();
        server.setResponseSeq(new LdapMessage[] {
                new LdapMessage(LdapASN1Constant.OP_BIND_RESPONSE,
                        new BindResponse(), null),
                new LdapMessage(LdapASN1Constant.OP_SEARCH_RESULT_DONE,
                        new EncodableLdapResult(), null) });

        initialDirContext.lookup("");

View Full Code Here

        Control[] expected = new Control[] { new PagedResultsControl(10,
                Control.NONCRITICAL) };
        env.put("java.naming.ldap.control.connect", expected);

        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
        LdapContext context = new InitialLdapContext(env, null);

        Control[] controls = context.getConnectControls();
        assertNotNull(controls);
        assertNotSame(expected, controls);

        Control c = controls[0];
        assertTrue(c instanceof PagedResultsControl);
        assertEquals(Control.NONCRITICAL, ((PagedResultsControl) c)
                .isCritical());
        assertEquals(expected[0], c);

        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });

        expected = new Control[] { new SortControl("", Control.NONCRITICAL) };
        context.reconnect(expected);

        controls = context.getConnectControls();
        assertNotNull(controls);
        assertEquals(1, controls.length);
        c = controls[0];
        assertTrue(c instanceof SortControl);
        assertEquals(Control.NONCRITICAL, ((SortControl) c).isCritical());
        assertNotSame(expected, controls);
        assertEquals(expected[0], c);

        expected[0] = new PagedResultsControl(10, Control.NONCRITICAL);
        controls = context.getConnectControls();
        assertNotNull(controls);
        assertEquals(1, controls.length);
        c = controls[0];
        assertTrue(c instanceof SortControl);
        assertEquals(Control.NONCRITICAL, ((SortControl) c).isCritical());

        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
        context.reconnect(null);

        assertNull(context.getConnectControls());
    }
View Full Code Here

    }

    public void testReconnect_share_connection() throws Exception {

        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
        LdapContext context = new InitialLdapContext(env, null);

        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });

        // doesn't create new connection
        context.reconnect(null);

        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_SEARCH_RESULT_DONE,
                new EncodableLdapResult(), null) });
        // another and context share the same connection now
        LdapContext another = (LdapContext) context.lookup("");

        MockLdapServer one = new MockLdapServer(server);
        one.start();

        one.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
        // create new connection
        context.reconnect(null);

        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
        // use original connection
        another.reconnect(null);
    }
View Full Code Here

        another.reconnect(null);
    }

    public void testFederation() throws Exception {
        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
        LdapContext context = new InitialLdapContext(env, null);

        /*
         * test invalid name 'test'
         */
 
View Full Code Here

            assertEquals("nns", addr.getType());
        }
    }
    public void testUnsolicitedNotification() throws Exception {
        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
        LdapContext context = new InitialLdapContext(env, null);

        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_SEARCH_RESULT_DONE,
                new EncodableLdapResult(), null) });
View Full Code Here

        referrals, env);

    assertEquals(referrals[0], ex.getReferralInfo());

    server.setResponseSeq(new LdapMessage[] { new LdapMessage(
        LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });

    Context refContext = ex.getReferralContext();

    Hashtable<Object, Object> refEnv = (Hashtable<Object, Object>) refContext
        .getEnvironment();
View Full Code Here

    env.put(Context.REFERRAL, "follow");
    env.put("test.getReferralContext", "changed");

    server.setResponseSeq(new LdapMessage[] { new LdapMessage(
        LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });

    assertEquals(referrals[0], ex.getReferralInfo());
    Context refContext = ex.getReferralContext(env);

    Hashtable<Object, Object> refEnv = (Hashtable<Object, Object>) refContext
View Full Code Here

    }

    public void testRequestControls() throws Exception {

        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });

        InitialLdapContext initialContext = new InitialLdapContext(env, null);

        Control[] reqCtls = initialContext.getRequestControls();
        assertEquals(1, reqCtls.length);
        assertEquals("2.16.840.1.113730.3.4.2", reqCtls[0].getID());
        assertEquals(Control.NONCRITICAL, reqCtls[0].isCritical());

        initialContext.setRequestControls(new Control[] { new SortControl("",
                Control.NONCRITICAL) });

        reqCtls = initialContext.getRequestControls();
        assertEquals(2, reqCtls.length);
        Control control = reqCtls[0];
        if (control instanceof SortControl) {
            assertEquals(Control.NONCRITICAL, reqCtls[0].isCritical());
            assertEquals("2.16.840.1.113730.3.4.2", reqCtls[1].getID());
            assertEquals(Control.NONCRITICAL, reqCtls[1].isCritical());
        } else {
            assertEquals("2.16.840.1.113730.3.4.2", control.getID());
            assertEquals(Control.NONCRITICAL, control.isCritical());
            assertTrue(reqCtls[1] instanceof SortControl);
            assertEquals(Control.NONCRITICAL, reqCtls[1].isCritical());
        }

        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_SEARCH_RESULT_DONE,
                new EncodableLdapResult(), null) });

        LdapContext context = (LdapContext) initialContext.lookup("");
        // request controls are not inherited
        reqCtls = context.getRequestControls();
        assertEquals(1, reqCtls.length);
        assertEquals("2.16.840.1.113730.3.4.2", reqCtls[0].getID());
        assertEquals(Control.NONCRITICAL, reqCtls[0].isCritical());

        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
        context = context.newInstance(new Control[] { new SortControl("",
                Control.NONCRITICAL) });
        reqCtls = context.getRequestControls();

        assertEquals(2, reqCtls.length);
View Full Code Here

TOP

Related Classes of org.apache.harmony.jndi.provider.ldap.mock.BindResponse

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.