Ori Liel has uploaded a new change for review. Change subject: restapi: VmMapper test - Move mock to class level ......................................................................
restapi: VmMapper test - Move mock to class level When mapping OsType, the code references a service which is currently mocked. But it's not mocked everywhere it should be, and the result is a strange behavior: when all the test method in VmMapperTest are run sequentially, one after the other - they pass. But if only 'testRoundTrip()' is run - it fails. The current change takes the necessary mocking up to the class level. The mocking is static and should only happen once - that's why the class level is the right place. And this way all test methods benefit from the mocking. Change-Id: Iaa9794a268551461263ff0aecb12a12cda279bd1 Signed-off-by: Ori Liel <[email protected]> --- M backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/VmMapperTest.java 1 file changed, 6 insertions(+), 4 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/77/19777/1 diff --git a/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/VmMapperTest.java b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/VmMapperTest.java index f6e5540..25bbb38 100644 --- a/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/VmMapperTest.java +++ b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/VmMapperTest.java @@ -2,6 +2,7 @@ import junit.framework.Assert; +import org.junit.BeforeClass; import org.junit.Test; import org.ovirt.engine.api.model.Boot; import org.ovirt.engine.api.model.BootDevice; @@ -34,6 +35,11 @@ public VmMapperTest() { super(VM.class, VmStatic.class, org.ovirt.engine.core.common.businessentities.VM.class); + } + + @BeforeClass + public static void beforeClass() { + OsTypeMockUtils.mockOsTypes(); } @Override @@ -158,7 +164,6 @@ vmDynamic.setStatus(VMStatus.Up); vmDynamic.setVmIp("2.2.2.2"); vm.setDynamicData(vmDynamic); - OsTypeMockUtils.mockOsTypes(); VM map = VmMapper.map(vm, null); assertNotNull(map.getGuestInfo().getIps().getIPs().get(0)); assertEquals(map.getGuestInfo().getIps().getIPs().get(0).getAddress(), "2.2.2.2"); @@ -171,7 +176,6 @@ vmDynamic.setStatus(VMStatus.Up); vmDynamic.setVmFQDN("localhost.localdomain"); vm.setDynamicData(vmDynamic); - OsTypeMockUtils.mockOsTypes(); VM map = VmMapper.map(vm, null); assertNotNull(map.getGuestInfo().getFqdn()); assertEquals(map.getGuestInfo().getFqdn(), "localhost.localdomain"); @@ -183,7 +187,6 @@ vmDynamic.setStatus(VMStatus.Up); vmDynamic.setVmIp("2.2.2.2 2.2.2.3 2.2.2.4"); vm.setDynamicData(vmDynamic); - OsTypeMockUtils.mockOsTypes(); VM map = VmMapper.map(vm, null); assertNotNull(map.getGuestInfo().getIps().getIPs().get(0)); assertEquals(map.getGuestInfo().getIps().getIPs().get(0).getAddress(), "2.2.2.2"); @@ -231,7 +234,6 @@ entity.setStatus(VMStatus.Up); Guid guid = Guid.newGuid(); entity.setRunOnVds(guid); - OsTypeMockUtils.mockOsTypes(); VM model = VmMapper.map(entity, null); assertEquals(guid.toString(), model.getHost().getId()); } -- To view, visit http://gerrit.ovirt.org/19777 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iaa9794a268551461263ff0aecb12a12cda279bd1 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Ori Liel <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
