Laszlo Hornyak has uploaded a new change for review. Change subject: engine: minor CommandBase change for rename logging ......................................................................
engine: minor CommandBase change for rename logging - catching Exception is removed - NPE-potential equals call replaced with StringUtils.equals - added junit test for the new method Change-Id: I8b437192af2635a133d1636c2ede39eb91a51c71 Signed-off-by: Laszlo Hornyak <lhorn...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/CommandBaseTest.java 2 files changed, 54 insertions(+), 19 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/81/11981/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java index 11c1ed7..f63c645 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java @@ -543,29 +543,28 @@ setSucceeded(true); } - private void logRenamedEntity() { - try { - if (this instanceof RenamedEntityInfoProvider) { - RenamedEntityInfoProvider renameable = (RenamedEntityInfoProvider) this; - String entityType = renameable.getEntityType(); - String oldEntityName = renameable.getEntityOldName(); - String newEntityName = renameable.getEntityNewName(); - if (!oldEntityName.equals(newEntityName)) { - // log entity rename details - AuditLogableBase logable = new AuditLogableBase(); - logable.AddCustomValue("EntityType", entityType); - logable.AddCustomValue("OldEntityName", oldEntityName); - logable.AddCustomValue("NewEntityName", newEntityName); - renameable.setEntityId(logable); - AuditLogDirector.log(logable, AuditLogType.ENTITY_RENAMED); - } + void logRenamedEntity() { + if (this instanceof RenamedEntityInfoProvider) { + RenamedEntityInfoProvider renameable = (RenamedEntityInfoProvider) this; + String entityType = renameable.getEntityType(); + String oldEntityName = renameable.getEntityOldName(); + String newEntityName = renameable.getEntityNewName(); + if (!StringUtils.equals(oldEntityName, newEntityName)) { + // log entity rename details + AuditLogableBase logable = new AuditLogableBase(); + logable.AddCustomValue("EntityType", entityType); + logable.AddCustomValue("OldEntityName", oldEntityName); + logable.AddCustomValue("NewEntityName", newEntityName); + renameable.setEntityId(logable); + auditLog(logable, AuditLogType.ENTITY_RENAMED); } - } catch (Exception e) { - log.error(e.getMessage()); - log.debug("Failed to log entity rename operation.", e); } } + void auditLog(AuditLogableBase logable, AuditLogType type) { + AuditLogDirector.log(logable, type); + } + private void internalEndWithFailure() { log.errorFormat("Ending command with failure: {0}", getClass().getName()); if (hasTaskHandlers()) { diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/CommandBaseTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/CommandBaseTest.java index 9dcd77e..ffee701 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/CommandBaseTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/CommandBaseTest.java @@ -18,6 +18,7 @@ import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; +import org.mockito.Mockito; import org.ovirt.engine.core.bll.session.SessionDataContainer; import org.ovirt.engine.core.bll.tasks.SPMAsyncTaskHandler; import org.ovirt.engine.core.bll.utils.PermissionSubject; @@ -171,4 +172,39 @@ command.endActionInTransactionScope(); verify(command).endWithFailure(); } + + @Test + public void logRenamedEntityNotRename() { + CommandBase<?> command = Mockito.mock(CommandBase.class); + Mockito.doCallRealMethod().when(command).logRenamedEntity(); + command.logRenamedEntity(); + } + + @Test + public void logRenamedEntity() { + abstract class RenameCommand extends CommandBaseDummy implements RenamedEntityInfoProvider { + + private static final long serialVersionUID = 1L; + + protected RenameCommand(VdcActionParametersBase params) { + super(params); + } + + } + RenameCommand command = Mockito.mock(RenameCommand.class); + Mockito.when(command.getEntityOldName()).thenReturn(null); + Mockito.when(command.getEntityNewName()).thenReturn(null); + Mockito.doCallRealMethod().when(command).logRenamedEntity(); + command.logRenamedEntity(); + Mockito.when(command.getEntityOldName()).thenReturn("foo"); + Mockito.when(command.getEntityNewName()).thenReturn("bar"); + command.logRenamedEntity(); + Mockito.when(command.getEntityOldName()).thenReturn(null); + Mockito.when(command.getEntityNewName()).thenReturn("bar"); + command.logRenamedEntity(); + Mockito.when(command.getEntityOldName()).thenReturn("foo"); + Mockito.when(command.getEntityNewName()).thenReturn(null); + command.logRenamedEntity(); + } + } -- To view, visit http://gerrit.ovirt.org/11981 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8b437192af2635a133d1636c2ede39eb91a51c71 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Laszlo Hornyak <lhorn...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches