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()); }
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) { } }
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)); }
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()); }