use of org.forgerock.openam.sm.datalayer.api.LdapOperationFailedException in project OpenAM by OpenRock.
the class LdapAdapter method update.
/**
* Update the Token based on whether there were any changes between the two.
*
* @param connection The non null connection to perform this call against.
* @param previous The non null previous Token to check against.
* @param updated The non null Token to update with.
* @return True if the token was updated, or false if there were no changes detected.
* @throws org.forgerock.openam.sm.datalayer.api.LdapOperationFailedException If the operation failed for a known reason.
*/
public boolean update(Connection connection, Token previous, Token updated) throws LdapOperationFailedException {
Entry currentEntry = conversion.getEntry(updated);
LdapTokenAttributeConversion.stripObjectClass(currentEntry);
Entry previousEntry = conversion.getEntry(previous);
LdapTokenAttributeConversion.stripObjectClass(previousEntry);
ModifyRequest request = Entries.diffEntries(previousEntry, currentEntry);
request.addControl(TransactionIdControl.newControl(AuditRequestContext.createSubTransactionIdValue()));
// Test to see if there are any modifications
if (request.getModifications().isEmpty()) {
return false;
}
try {
processResult(connection.modify(request));
} catch (LdapException e) {
throw new LdapOperationFailedException(e.getResult());
}
return true;
}
use of org.forgerock.openam.sm.datalayer.api.LdapOperationFailedException in project OpenAM by OpenRock.
the class CreateTaskTest method shouldHandleException.
@Test(expectedExceptions = DataLayerException.class)
public void shouldHandleException() throws Exception {
doThrow(new LdapOperationFailedException("test")).when(mockAdapter).create(any(Connection.class), any(Token.class));
task.execute(mockConnection, mockAdapter);
verify(mockHandler).processError(any(CoreTokenException.class));
}
use of org.forgerock.openam.sm.datalayer.api.LdapOperationFailedException in project OpenAM by OpenRock.
the class LdapAdapterTest method shouldThrowAllOtherExceptionsDuringDelete.
@Test
public void shouldThrowAllOtherExceptionsDuringDelete() throws Exception {
// Given
String tokenId = "badger";
DN testDN = DN.rootDN();
LdapException exception = LdapException.newLdapException(ResultCode.OTHER);
given(mockConnection.delete(any(DeleteRequest.class))).willThrow(exception);
given(mockConversion.generateTokenDN(anyString())).willReturn(testDN);
// When / Then
try {
adapter.delete(mockConnection, tokenId);
fail();
} catch (LdapOperationFailedException e) {
}
}
use of org.forgerock.openam.sm.datalayer.api.LdapOperationFailedException in project OpenAM by OpenRock.
the class DeleteTaskTest method shouldHandleException.
@Test(expectedExceptions = DataLayerException.class)
public void shouldHandleException() throws Exception {
doThrow(new LdapOperationFailedException("test")).when(mockAdapter).delete(any(Connection.class), anyString());
task.execute(mockConnection, mockAdapter);
verify(mockResultHandler).processError(any(CoreTokenException.class));
}
Aggregations