Java 类javax.naming.ldap.UnsolicitedNotification 实例源码

项目:cn1    文件:UnsolicitedNotificationEventTest.java   
public void testConstructor_simple() {
    NamingException exception = new NamingException(
            "MockUnsolicitedNotification: naming exception");
    String[] referral = { "Red", "Blue", };
    UnsolicitedNotification notification = new MockUnsolicitedNotification(
            referral, exception);
    Object src = "source";
    UnsolicitedNotificationEvent event = new UnsolicitedNotificationEvent(
            src, notification);

    assertEquals(src, event.getSource());
    assertEquals(notification, event.getNotification());

    assertSame(notification, event.getNotification());
    assertSame(src, event.getSource());
}
项目:freeVM    文件:UnsolicitedNotificationEventTest.java   
public void testConstructor_simple() {
    NamingException exception = new NamingException(
            "MockUnsolicitedNotification: naming exception");
    String[] referral = { "Red", "Blue", };
    UnsolicitedNotification notification = new MockUnsolicitedNotification(
            referral, exception);
    Object src = "source";
    UnsolicitedNotificationEvent event = new UnsolicitedNotificationEvent(
            src, notification);

    assertEquals(src, event.getSource());
    assertEquals(notification, event.getNotification());

    assertSame(notification, event.getNotification());
    assertSame(src, event.getSource());
}
项目:freeVM    文件:UnsolicitedNotificationEventTest.java   
public void testConstructor_simple() {
    NamingException exception = new NamingException(
            "MockUnsolicitedNotification: naming exception");
    String[] referral = { "Red", "Blue", };
    UnsolicitedNotification notification = new MockUnsolicitedNotification(
            referral, exception);
    Object src = "source";
    UnsolicitedNotificationEvent event = new UnsolicitedNotificationEvent(
            src, notification);

    assertEquals(src, event.getSource());
    assertEquals(notification, event.getNotification());

    assertSame(notification, event.getNotification());
    assertSame(src, event.getSource());
}
项目:cn1    文件:UnsolicitedNotificationEventTest.java   
public void testConstructor_src_null() {
    NamingException exception = new NamingException(
            "MockUnsolicitedNotification: naming exception");
    String[] referral = { "Red", "Blue", };
    UnsolicitedNotification notification = new MockUnsolicitedNotification(
            referral, exception);
    Object src = null;
    try {
        new UnsolicitedNotificationEvent(
                src, notification);
    } catch (IllegalArgumentException e) {
    }
}
项目:cn1    文件:UnsolicitedNotificationEventTest.java   
public void testDispatch() {
    NamingException exception = new NamingException(
            "MockUnsolicitedNotification: naming exception");
    String[] referral = { "Red", "Blue", };
    UnsolicitedNotification notification = new MockUnsolicitedNotification(
            referral, exception);
    Object src = "source";
    UnsolicitedNotificationEvent event = new UnsolicitedNotificationEvent(
            src, notification);
    MockUnsolicitedNotificationListener listener = new MockUnsolicitedNotificationListener();
    event.dispatch(listener);
    assertTrue(listener.hasEvent(event));
}
项目:cn1    文件:LdapContextServerMockedTest.java   
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) });
    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);
    assertTrue(listener.unsolicatedEvent.getSource() instanceof LdapContext);
    UnsolicitedNotification notification = listener.unsolicatedEvent
            .getNotification();
    assertNotNull(notification);
    assertEquals(DisconnectResponse.oid, notification.getID());
    assertNull(notification.getControls());
    assertNull(notification.getException());
    assertNull(notification.getReferrals());
    assertNull(notification.getEncodedValue());
}
项目:freeVM    文件:UnsolicitedNotificationEventTest.java   
public void testConstructor_src_null() {
    NamingException exception = new NamingException(
            "MockUnsolicitedNotification: naming exception");
    String[] referral = { "Red", "Blue", };
    UnsolicitedNotification notification = new MockUnsolicitedNotification(
            referral, exception);
    Object src = null;
    try {
        new UnsolicitedNotificationEvent(
                src, notification);
    } catch (IllegalArgumentException e) {
    }
}
项目:freeVM    文件:UnsolicitedNotificationEventTest.java   
public void testDispatch() {
    NamingException exception = new NamingException(
            "MockUnsolicitedNotification: naming exception");
    String[] referral = { "Red", "Blue", };
    UnsolicitedNotification notification = new MockUnsolicitedNotification(
            referral, exception);
    Object src = "source";
    UnsolicitedNotificationEvent event = new UnsolicitedNotificationEvent(
            src, notification);
    MockUnsolicitedNotificationListener listener = new MockUnsolicitedNotificationListener();
    event.dispatch(listener);
    assertTrue(listener.hasEvent(event));
}
项目:freeVM    文件:UnsolicitedNotificationEventTest.java   
public void testConstructor_src_null() {
    NamingException exception = new NamingException(
            "MockUnsolicitedNotification: naming exception");
    String[] referral = { "Red", "Blue", };
    UnsolicitedNotification notification = new MockUnsolicitedNotification(
            referral, exception);
    Object src = null;
    try {
        new UnsolicitedNotificationEvent(
                src, notification);
    } catch (IllegalArgumentException e) {
    }
}
项目:freeVM    文件:UnsolicitedNotificationEventTest.java   
public void testDispatch() {
    NamingException exception = new NamingException(
            "MockUnsolicitedNotification: naming exception");
    String[] referral = { "Red", "Blue", };
    UnsolicitedNotification notification = new MockUnsolicitedNotification(
            referral, exception);
    Object src = "source";
    UnsolicitedNotificationEvent event = new UnsolicitedNotificationEvent(
            src, notification);
    MockUnsolicitedNotificationListener listener = new MockUnsolicitedNotificationListener();
    event.dispatch(listener);
    assertTrue(listener.hasEvent(event));
}
项目:freeVM    文件:LdapContextServerMockedTest.java   
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) });
    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);
    assertTrue(listener.unsolicatedEvent.getSource() instanceof LdapContext);
    UnsolicitedNotification notification = listener.unsolicatedEvent
            .getNotification();
    assertNotNull(notification);
    assertEquals(DisconnectResponse.oid, notification.getID());
    assertNull(notification.getControls());
    assertNull(notification.getException());
    assertNull(notification.getReferrals());
    assertNull(notification.getEncodedValue());
}