@Test public void shouldNoNothingIfNoModificaitonsOnUpdate() throws LDAPOperationFailedException, ErrorResultException { String tokenId = "badger"; Token first = new Token(tokenId, TokenType.OAUTH); Token second = new Token(tokenId, TokenType.OAUTH); Connection mockConnection = mock(Connection.class); LDAPConfig constants = new LDAPConfig(""); LDAPDataConversion dataConversion = new LDAPDataConversion(); TokenAttributeConversion conversion = new TokenAttributeConversion(constants, dataConversion); LDAPAdapter adapter = new LDAPAdapter(conversion); adapter.update(mockConnection, first, second); verify(mockConnection, never()).modify(any(ModifyRequest.class)); }
public boolean update(Connection connection, Token previous, Token updated) throws ErrorResultException, LDAPOperationFailedException { Entry currentEntry = conversion.getEntry(updated); TokenAttributeConversion.stripObjectClass(currentEntry); Entry previousEntry = conversion.getEntry(previous); TokenAttributeConversion.stripObjectClass(previousEntry); ModifyRequest request = Entries.diffEntries(previousEntry, currentEntry); if (request.getModifications().isEmpty()) { return false; } processResult(connection.modify(request)); return true; }
LDAPAdapter { public boolean update(Connection connection, Token previous, Token updated) throws ErrorResultException, LDAPOperationFailedException { Entry currentEntry = conversion.getEntry(updated); TokenAttributeConversion.stripObjectClass(currentEntry); Entry previousEntry = conversion.getEntry(previous); TokenAttributeConversion.stripObjectClass(previousEntry); ModifyRequest request = Entries.diffEntries(previousEntry, currentEntry); if (request.getModifications().isEmpty()) { return false; } processResult(connection.modify(request)); return true; } }
LDAPAdapter { public boolean update(Connection connection, Token previous, Token updated) throws ErrorResultException, LDAPOperationFailedException { Entry currentEntry = conversion.getEntry(updated); TokenAttributeConversion.stripObjectClass(currentEntry); Entry previousEntry = conversion.getEntry(previous); TokenAttributeConversion.stripObjectClass(previousEntry); ModifyRequest request = Entries.diffEntries(previousEntry, currentEntry); if (request.getModifications().isEmpty()) { return false; } processResult(connection.modify(request)); return true; } @Inject  LDAPAdapter(TokenAttributeConversion conversion); }
LDAPAdapter { public boolean update(Connection connection, Token previous, Token updated) throws ErrorResultException, LDAPOperationFailedException { Entry currentEntry = conversion.getEntry(updated); TokenAttributeConversion.stripObjectClass(currentEntry); Entry previousEntry = conversion.getEntry(previous); TokenAttributeConversion.stripObjectClass(previousEntry); ModifyRequest request = Entries.diffEntries(previousEntry, currentEntry); if (request.getModifications().isEmpty()) { return false; } processResult(connection.modify(request)); return true; } @Inject  LDAPAdapter(TokenAttributeConversion conversion); void create(Connection connection, Token token); Token read(Connection connection,  String tokenId); boolean update(Connection connection, Token previous, Token updated); void delete(Connection connection, String tokenId); void deleteAsync(Connection connection, String tokenId, ResultHandler<Result> handler); }
LDAPAdapter { public boolean update(Connection connection, Token previous, Token updated) throws ErrorResultException, LDAPOperationFailedException { Entry currentEntry = conversion.getEntry(updated); TokenAttributeConversion.stripObjectClass(currentEntry); Entry previousEntry = conversion.getEntry(previous); TokenAttributeConversion.stripObjectClass(previousEntry); ModifyRequest request = Entries.diffEntries(previousEntry, currentEntry); if (request.getModifications().isEmpty()) { return false; } processResult(connection.modify(request)); return true; } @Inject  LDAPAdapter(TokenAttributeConversion conversion); void create(Connection connection, Token token); Token read(Connection connection,  String tokenId); boolean update(Connection connection, Token previous, Token updated); void delete(Connection connection, String tokenId); void deleteAsync(Connection connection, String tokenId, ResultHandler<Result> handler);  }