Laszlo Hornyak has uploaded a new change for review. Change subject: WIP: some test for AddVdsCommand ......................................................................
WIP: some test for AddVdsCommand It will need a little change in the command code so that I can at least mock it. Without that it is quite hopeless. Change-Id: Iaa8b31e3bb4f96e34d7ea7e97ec8c4c5b1f19984 Signed-off-by: Laszlo Hornyak <lhorn...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java A backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVdsCommandTest.java 2 files changed, 51 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/93/12193/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java index 2f0c01c..ddd605a 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java @@ -189,7 +189,7 @@ } } - private boolean isGlusterSupportEnabled() { + boolean isGlusterSupportEnabled() { return getVdsGroup().supportsGlusterService() && getParameters().isGlusterPeerProbeNeeded(); } diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVdsCommandTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVdsCommandTest.java new file mode 100644 index 0000000..1bacde6 --- /dev/null +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVdsCommandTest.java @@ -0,0 +1,50 @@ +package org.ovirt.engine.core.bll; + +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; +import org.ovirt.engine.core.common.action.AddVdsActionParameters; +import org.ovirt.engine.core.common.businessentities.VDS; +import org.ovirt.engine.core.common.businessentities.VDSGroup; +import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.compat.Version; +import org.ovirt.engine.core.dao.VdsDAO; +import org.ovirt.engine.core.dao.VdsGroupDAO; + +public class AddVdsCommandTest { + private VDS makeTestVds(Guid vdsId) { + VDS newVdsData = new VDS(); + newVdsData.setHostName("BUZZ"); + newVdsData.setVdsName("BAR"); + newVdsData.setVdsGroupCompatibilityVersion(new Version("1.2.3")); + newVdsData.setVdsGroupId(new Guid()); + newVdsData.setId(vdsId); + return newVdsData; + } + + @Test + public void canDoAction() { + AddVdsActionParameters parameters = new AddVdsActionParameters(); + + VdsGroupDAO groupDAOMock = Mockito.mock(VdsGroupDAO.class); + + Guid vdsId = new Guid(); + VDS newVds = makeTestVds(vdsId); + parameters.setvds(newVds); + @SuppressWarnings("unchecked") + AddVdsCommand<AddVdsActionParameters> commandMock = Mockito.mock(AddVdsCommand.class); + Mockito.when(commandMock.canDoAction()).thenCallRealMethod(); + Mockito.when(commandMock.getParameters()).thenReturn(parameters); + + Mockito.when(commandMock.isGlusterSupportEnabled()).thenReturn(false); + Mockito.when(commandMock.getVdsGroupDAO()).thenReturn(groupDAOMock); + + VdsDAO vdsDaoMock = Mockito.mock(VdsDAO.class); + Mockito.when(vdsDaoMock.get(vdsId)).thenReturn(null); + //Mockito.when(vdsDaoMock.get(vdsId)).thenReturn(null); + Mockito.when(commandMock.getVdsDAO()).thenReturn(vdsDaoMock); + + Assert.assertTrue(commandMock.canDoAction()); + Assert.assertTrue(commandMock.getReturnValue().getCanDoActionMessages().isEmpty()); + } +} -- To view, visit http://gerrit.ovirt.org/12193 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iaa8b31e3bb4f96e34d7ea7e97ec8c4c5b1f19984 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