Allon Mureinik has uploaded a new change for review.

Change subject: core: Make MockConfigRule work with Versions
......................................................................

core: Make MockConfigRule work with Versions

Fixed MockConfigRule to work with the Version class so it provides a
meaningful interface instead of just passing any String which is just
implementation details in Config.

This patch contains the following:
* Fixing MockConfigRule's interface
  adjusting AddVmCommandTest, GetConfigurationValueQueryTest and
  GetDeviceListQueryTest to pass the Version they use instead of its
  text value.
* Fixing VmNicValidatorTest to send the Version used in the validator to
  MockConfigRule.

Change-Id: I9f407bc1af73e76e223a8cbb1c67009f7dd97d61
Signed-off-by: Allon Mureinik <[email protected]>
---
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVmCommandTest.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/GetConfigurationValueQueryTest.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/GetDeviceListQueryTest.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VmNicValidatorTest.java
M 
backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/MockConfigRule.java
5 files changed, 20 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/53/11353/1

diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVmCommandTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVmCommandTest.java
index ffd2cab7..ef75416 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVmCommandTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVmCommandTest.java
@@ -52,6 +52,7 @@
 import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.NGuid;
+import org.ovirt.engine.core.compat.Version;
 import org.ovirt.engine.core.dal.VdcBllMessages;
 import 
org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBaseMockUtils;
 import org.ovirt.engine.core.dao.DiskImageDAO;
@@ -477,8 +478,8 @@
     }
 
     private void mockConfig() {
-        mcr.mockConfigValue(ConfigValues.PredefinedVMProperties, "3.0", "");
-        mcr.mockConfigValue(ConfigValues.UserDefinedVMProperties, "3.0", "");
+        mcr.mockConfigValue(ConfigValues.PredefinedVMProperties, Version.v3_0, 
"");
+        mcr.mockConfigValue(ConfigValues.UserDefinedVMProperties, 
Version.v3_0, "");
         mcr.mockConfigValue(ConfigValues.InitStorageSparseSizeInGB, 1);
     }
 
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/GetConfigurationValueQueryTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/GetConfigurationValueQueryTest.java
index d2ba1fd..df60e15 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/GetConfigurationValueQueryTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/GetConfigurationValueQueryTest.java
@@ -9,6 +9,7 @@
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.queries.ConfigurationValues;
 import org.ovirt.engine.core.common.queries.GetConfigurationValueParameters;
+import org.ovirt.engine.core.compat.Version;
 import org.ovirt.engine.core.utils.MockConfigRule;
 import org.ovirt.engine.core.utils.RandomUtils;
 
@@ -39,8 +40,8 @@
 
     private void assertQueryExecution(ConfigurationValues configValue, boolean 
isFiltered, boolean shouldSucceed) {
         // Mock the parameters
-        String version = RandomUtils.instance().nextNumericString(2);
-        when(getQueryParameters().getVersion()).thenReturn(version);
+        Version version = RandomUtils.instance().pickRandom(Version.ALL);
+        when(getQueryParameters().getVersion()).thenReturn(version.toString());
         when(getQueryParameters().getConfigValue()).thenReturn(configValue);
         when(getQueryParameters().isFiltered()).thenReturn(isFiltered);
 
@@ -62,7 +63,7 @@
      * Mocks a call to {@link Config#GetValue(ConfigValues)) and returns the 
value it should return.
      * @return The mocked value
      */
-    private static String mockConfig(String version, ConfigurationValues 
configurationValues) {
+    private static String mockConfig(Version version, ConfigurationValues 
configurationValues) {
         String returnValue = RandomUtils.instance().nextString(10, true);
 
         ConfigValues configValues = 
ConfigValues.valueOf(configurationValues.name());
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/GetDeviceListQueryTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/GetDeviceListQueryTest.java
index 88c1547..fe8b8a1 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/GetDeviceListQueryTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/GetDeviceListQueryTest.java
@@ -62,7 +62,7 @@
      * Test query execution when LUNs filtering is enabled
      */
     public void testExecuteQueryWithFilteringLUNsEnabled() {
-        mcr.mockConfigValue(ConfigValues.FilteringLUNsEnabled, 
Version.v3_1.toString(), true);
+        mcr.mockConfigValue(ConfigValues.FilteringLUNsEnabled, Version.v3_1, 
true);
 
         // Create expected result
         lunsExpected = Collections.emptyList();
@@ -75,7 +75,7 @@
      * Test query execution when LUNs filtering is disabled
      */
     public void testExecuteQueryWithFilteringLUNsDisabled() {
-        mcr.mockConfigValue(ConfigValues.FilteringLUNsEnabled, 
Version.v3_1.toString(), false);
+        mcr.mockConfigValue(ConfigValues.FilteringLUNsEnabled, Version.v3_1, 
false);
 
         // Create expected result
         lunsExpected = lunsInput;
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VmNicValidatorTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VmNicValidatorTest.java
index 9b3b522..264430c 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VmNicValidatorTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VmNicValidatorTest.java
@@ -1,7 +1,6 @@
 package org.ovirt.engine.core.bll.validator;
 
 import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import org.junit.Before;
@@ -26,11 +25,13 @@
     @Mock
     private VmNetworkInterface nic;
 
+    @Mock
+    private Version version;
+
     private VmNicValidator validator;
 
     @Before
     public void setup() {
-        Version version = mock(Version.class);
         when(version.getValue()).thenReturn(null);
 
         validator = new VmNicValidator(nic, version);
@@ -97,14 +98,14 @@
     }
 
     private void unlinkingTest(ValidationResult expected, boolean 
networkLinkingSupported, boolean nicLinked) {
-        mockConfigRule.mockConfigValue(ConfigValues.NetworkLinkingSupported, 
null, networkLinkingSupported);
+        mockConfigRule.mockConfigValue(ConfigValues.NetworkLinkingSupported, 
version, networkLinkingSupported);
         when(nic.isLinked()).thenReturn(nicLinked);
 
         assertEquals(expected, validator.linkedCorrectly());
     }
 
     private void networkNameTest(ValidationResult expected, boolean 
networkLinkingSupported, String networkName) {
-        mockConfigRule.mockConfigValue(ConfigValues.NetworkLinkingSupported, 
null, networkLinkingSupported);
+        mockConfigRule.mockConfigValue(ConfigValues.NetworkLinkingSupported, 
version, networkLinkingSupported);
         when(nic.getNetworkName()).thenReturn(networkName);
 
         assertEquals(expected, validator.networkNameValid());
diff --git 
a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/MockConfigRule.java
 
b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/MockConfigRule.java
index 9779185..fe3da03 100644
--- 
a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/MockConfigRule.java
+++ 
b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/MockConfigRule.java
@@ -14,6 +14,7 @@
 import org.ovirt.engine.core.common.config.ConfigCommon;
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.config.IConfigUtilsInterface;
+import org.ovirt.engine.core.compat.Version;
 
 /**
  * This rule is used to mock {@link Config} values in an easy fashion, without 
having to resort to Power Mocking.
@@ -81,7 +82,11 @@
         mockConfigValue(value, ConfigCommon.defaultConfigurationVersion, 
returnValue);
     }
 
-    public <T> void mockConfigValue(ConfigValues value, String version, T 
returnValue) {
+    public <T> void mockConfigValue(ConfigValues value, Version version, T 
returnValue) {
+        mockConfigValue(value, version.getValue(), returnValue);
+    }
+
+    private static <T> void mockConfigValue(ConfigValues value, String 
version, T returnValue) {
         when(Config.getConfigUtils().GetValue(value, 
version)).thenReturn(returnValue);
     }
 


--
To view, visit http://gerrit.ovirt.org/11353
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9f407bc1af73e76e223a8cbb1c67009f7dd97d61
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Allon Mureinik <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to