/** * {@inheritDoc} */ @Override public void bind(DirContextOperations ctx) { Name dn = ctx.getDn(); if (dn != null && !ctx.isUpdateMode()) { bind(dn, ctx, null); } else { throw new IllegalStateException("The DirContextOperations instance needs to be properly initialized."); } }
/** * {@inheritDoc} */ @Override public void bind(DirContextOperations ctx) { Name dn = ctx.getDn(); if (dn != null && !ctx.isUpdateMode()) { bind(dn, ctx, null); } else { throw new IllegalStateException("The DirContextOperations instance needs to be properly initialized."); } }
/** * {@inheritDoc} */ @Override public void bind(DirContextOperations ctx) { Name dn = ctx.getDn(); if (dn != null && !ctx.isUpdateMode()) { bind(dn, ctx, null); } else { throw new IllegalStateException("The DirContextOperations instance needs to be properly initialized."); } }
/** * {@inheritDoc} */ @Override public void rebind(DirContextOperations ctx) { Name dn = ctx.getDn(); if (dn != null && !ctx.isUpdateMode()) { rebind(dn, ctx, null); } else { throw new IllegalStateException( "The DirContextOperations instance needs to be properly initialized."); } }
/** * {@inheritDoc} */ @Override public void bind(DirContextOperations ctx) { Name dn = ctx.getDn(); if (dn != null && !ctx.isUpdateMode()) { bind(dn, ctx, null); } else { throw new IllegalStateException("The DirContextOperations instance needs to be properly initialized."); } }
/** * {@inheritDoc} */ @Override public void rebind(DirContextOperations ctx) { Name dn = ctx.getDn(); if (dn != null && !ctx.isUpdateMode()) { rebind(dn, ctx, null); } else { throw new IllegalStateException( "The DirContextOperations instance needs to be properly initialized."); } }
/** * {@inheritDoc} */ @Override public void rebind(DirContextOperations ctx) { Name dn = ctx.getDn(); if (dn != null && !ctx.isUpdateMode()) { rebind(dn, ctx, null); } else { throw new IllegalStateException( "The DirContextOperations instance needs to be properly initialized."); } }
/** * {@inheritDoc} */ @Override public void rebind(DirContextOperations ctx) { Name dn = ctx.getDn(); if (dn != null && !ctx.isUpdateMode()) { rebind(dn, ctx, null); } else { throw new IllegalStateException( "The DirContextOperations instance needs to be properly initialized."); } }
/** * {@inheritDoc} */ @Override public void modifyAttributes(DirContextOperations ctx) { Name dn = ctx.getDn(); if (dn != null && ctx.isUpdateMode()) { modifyAttributes(dn, ctx.getModificationItems()); } else { throw new IllegalStateException("The DirContextOperations instance needs to be properly initialized."); } }
/** * {@inheritDoc} */ @Override public void modifyAttributes(DirContextOperations ctx) { Name dn = ctx.getDn(); if (dn != null && ctx.isUpdateMode()) { modifyAttributes(dn, ctx.getModificationItems()); } else { throw new IllegalStateException("The DirContextOperations instance needs to be properly initialized."); } }
/** * {@inheritDoc} */ @Override public void modifyAttributes(DirContextOperations ctx) { Name dn = ctx.getDn(); if (dn != null && ctx.isUpdateMode()) { modifyAttributes(dn, ctx.getModificationItems()); } else { throw new IllegalStateException("The DirContextOperations instance needs to be properly initialized."); } }
/** * {@inheritDoc} */ @Override public void modifyAttributes(DirContextOperations ctx) { Name dn = ctx.getDn(); if (dn != null && ctx.isUpdateMode()) { modifyAttributes(dn, ctx.getModificationItems()); } else { throw new IllegalStateException("The DirContextOperations instance needs to be properly initialized."); } }
@Test public void testRebindWithContext() throws Exception { expectGetReadWriteContext(); when(dirContextOperationsMock.getDn()).thenReturn(nameMock); when(dirContextOperationsMock.isUpdateMode()).thenReturn(false); tested.rebind(dirContextOperationsMock); verify(dirContextMock).rebind(nameMock, dirContextOperationsMock, null); verify(dirContextMock).close(); }
@Test public void testBindWithContext() throws Exception { expectGetReadWriteContext(); when(dirContextOperationsMock.getDn()).thenReturn(nameMock); when(dirContextOperationsMock.isUpdateMode()).thenReturn(false); tested.bind(dirContextOperationsMock); verify(dirContextMock).bind(nameMock, dirContextOperationsMock, null); verify(dirContextMock).close(); }
@Test public void testUpdateWithIdSpecified() throws NamingException { when(contextSourceMock.getReadOnlyContext()).thenReturn(dirContextMock); when(contextSourceMock.getReadWriteContext()).thenReturn(dirContextMock); LdapName expectedName = LdapUtils.newLdapName("ou=someOu"); ModificationItem[] expectedModificationItems = new ModificationItem[0]; DirContextOperations ctxMock = mock(DirContextOperations.class); when(ctxMock.getDn()).thenReturn(expectedName); when(ctxMock.isUpdateMode()).thenReturn(true); when(ctxMock.getModificationItems()).thenReturn(expectedModificationItems); Object expectedObject = new Object(); when(odmMock.getId(expectedObject)).thenReturn(expectedName); when(odmMock.getCalculatedId(expectedObject)).thenReturn(null); when(dirContextMock.lookup(expectedName)).thenReturn(ctxMock); tested.update(expectedObject); verify(odmMock, never()).setId(expectedObject, expectedName); verify(odmMock).mapToLdapDataEntry(expectedObject, ctxMock); verify(dirContextMock).modifyAttributes(expectedName, expectedModificationItems); verify(dirContextMock, times(2)).close(); }
@Test public void testModifyAttributesWithDirContextOperations() throws Exception { final ModificationItem[] expectedModifications = new ModificationItem[0]; final LdapName epectedDn = LdapUtils.emptyLdapName(); when(dirContextOperationsMock.getDn()).thenReturn(epectedDn); when(dirContextOperationsMock.isUpdateMode()).thenReturn(true); when(dirContextOperationsMock.getModificationItems()).thenReturn(expectedModifications); LdapTemplate tested = new LdapTemplate() { public void modifyAttributes(Name dn, ModificationItem[] mods) { assertThat(dn).isSameAs(epectedDn); assertThat(mods).isSameAs(expectedModifications); } }; tested.modifyAttributes(dirContextOperationsMock); }
@Test public void testUpdateWithIdCalculated() throws NamingException { when(contextSourceMock.getReadOnlyContext()).thenReturn(dirContextMock); when(contextSourceMock.getReadWriteContext()).thenReturn(dirContextMock); LdapName expectedName = LdapUtils.newLdapName("ou=someOu"); ModificationItem[] expectedModificationItems = new ModificationItem[0]; DirContextOperations ctxMock = mock(DirContextOperations.class); when(ctxMock.getDn()).thenReturn(expectedName); when(ctxMock.isUpdateMode()).thenReturn(true); when(ctxMock.getModificationItems()).thenReturn(expectedModificationItems); Object expectedObject = new Object(); when(odmMock.getId(expectedObject)).thenReturn(null); when(odmMock.getCalculatedId(expectedObject)).thenReturn(expectedName); when(dirContextMock.lookup(expectedName)).thenReturn(ctxMock); tested.update(expectedObject); verify(odmMock).setId(expectedObject, expectedName); verify(odmMock).mapToLdapDataEntry(expectedObject, ctxMock); verify(dirContextMock).modifyAttributes(expectedName, expectedModificationItems); verify(dirContextMock, times(2)).close(); }
@Test public void testModifyAttributesWithDirContextOperationsNotInitializedDn() throws Exception { when(dirContextOperationsMock.getDn()).thenReturn(LdapUtils.emptyLdapName()); when(dirContextOperationsMock.isUpdateMode()).thenReturn(false); LdapTemplate tested = new LdapTemplate() { public void modifyAttributes(Name dn, ModificationItem[] mods) { fail("The call to the base modifyAttributes should not have occured."); } }; try { tested.modifyAttributes(dirContextOperationsMock); fail("IllegalStateException expected"); } catch (IllegalStateException expected) { assertThat(true).isTrue(); } }