Allon Mureinik has uploaded a new change for review.

Change subject: core: Clean up query test conf mocking
......................................................................

core: Clean up query test conf mocking

Previously, AbstractQueryTest defined a @ClassRule for mocking Config
values. Since @ClassRules are hidden, not inherited, if any descending
class wished to have it's own MockConfigRule, the mocking from the base
class had to be copied to the descending class in order not to lose it.
This approach is both error prone and conceptually lacking, as it forces
the descendant classes to know details about the parent's
implementation.

This patch attempts to improve the situation by have AbstractQueryTest
define the getExtraCofigDescriptors() method. This allows each
inheriting class to specify which Config values it wishes to add to the
mocking, while leaving the actual mocking to the base class.

Change-Id: I1d511b1f67e842a64b7c9322a0d526e717f4a601
Signed-off-by: Allon Mureinik <amure...@redhat.com>
---
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AbstractQueryTest.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AbstractSysprepQueryTest.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQueryTest.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/GetDeviceListQueryTest.java
M 
backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/MockConfigRule.java
5 files changed, 30 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/00/36800/1

diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AbstractQueryTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AbstractQueryTest.java
index a009a6a..65cfcad 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AbstractQueryTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AbstractQueryTest.java
@@ -5,11 +5,14 @@
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.when;
+import static org.ovirt.engine.core.utils.MockConfigRule.MockConfigDescriptor;
 import static org.ovirt.engine.core.utils.MockConfigRule.mockConfig;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.ParameterizedType;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Set;
 
 import org.junit.Before;
 import org.junit.ClassRule;
@@ -42,6 +45,13 @@
     public void setUp() throws Exception {
         setUpMockQueryParameters();
         setUpSpyQuery();
+        for (MockConfigDescriptor<?> mcd : getExtraConfigDescriptors()) {
+            mcr.mockConfigValue(mcd);
+        }
+    }
+
+    public <T> Set<MockConfigDescriptor<T>> getExtraConfigDescriptors() {
+        return Collections.emptySet();
     }
 
     /** Sets up a mock for {@link #params} */
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AbstractSysprepQueryTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AbstractSysprepQueryTest.java
index fb609ec..6b63f2f 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AbstractSysprepQueryTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AbstractSysprepQueryTest.java
@@ -1,11 +1,12 @@
 package org.ovirt.engine.core.bll;
 
 import static org.ovirt.engine.core.utils.MockConfigRule.mockConfig;
+import static org.ovirt.engine.core.utils.MockConfigRule.MockConfigDescriptor;
 
-import org.junit.ClassRule;
+import java.util.Collections;
+import java.util.Set;
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.queries.VdcQueryParametersBase;
-import org.ovirt.engine.core.utils.MockConfigRule;
 
 /**
  * An abstract class for setting up tests for queries using Sysprep.
@@ -13,7 +14,8 @@
  */
 public abstract class AbstractSysprepQueryTest<P extends 
VdcQueryParametersBase, Q extends QueriesCommandBase<? extends P>> extends 
AbstractUserQueryTest<P, Q> {
 
-    @ClassRule
-    public static MockConfigRule mcr = new 
MockConfigRule(mockConfig(ConfigValues.AdUserName, ""),
-            mockConfig(ConfigValues.UserSessionTimeOutInterval, 60));
+    @Override
+    public Set<MockConfigDescriptor<String>> getExtraConfigDescriptors() {
+        return Collections.singleton(mockConfig(ConfigValues.AdUserName, ""));
+    }
 }
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQueryTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQueryTest.java
index f60bfe2..83dfc09 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQueryTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQueryTest.java
@@ -11,12 +11,14 @@
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Test;
 import org.ovirt.engine.core.bll.AbstractQueryTest;
 import org.ovirt.engine.core.bll.context.EngineContext;
@@ -64,11 +66,12 @@
     private static final Guid server_id3 = new 
Guid("7a797a38-cb32-4399-b6fb-21c79c03a1d6");
     private static final String serverKeyFingerprint = "fingerprint";
 
-    @ClassRule
-    public static MockConfigRule mcr = new MockConfigRule(
-            mockConfig(ConfigValues.GlusterHostUUIDSupport, 
Version.v3_2.toString(), false),
-            mockConfig(ConfigValues.GlusterHostUUIDSupport, 
Version.v3_3.toString(), true),
-            mockConfig(ConfigValues.UserSessionTimeOutInterval, 60));
+    @Override
+    public Set<MockConfigRule.MockConfigDescriptor<Boolean>> 
getExtraConfigDescriptors() {
+        return new HashSet<>(Arrays.asList(
+                mockConfig(ConfigValues.GlusterHostUUIDSupport, 
Version.v3_2.toString(), false),
+                mockConfig(ConfigValues.GlusterHostUUIDSupport, 
Version.v3_3.toString(), true)));
+    }
 
     private VDSGroup getVdsGroup(Version ver) {
         VDSGroup vdsGroup = new VDSGroup();
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 198db7a..d5c623a 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
@@ -6,14 +6,12 @@
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
-import static org.ovirt.engine.core.utils.MockConfigRule.mockConfig;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Test;
 import org.ovirt.engine.core.bll.AbstractQueryTest;
 import org.ovirt.engine.core.common.businessentities.LUNs;
@@ -32,14 +30,8 @@
 import org.ovirt.engine.core.dao.LunDAO;
 import org.ovirt.engine.core.dao.StorageDomainDAO;
 import org.ovirt.engine.core.dao.VdsDAO;
-import org.ovirt.engine.core.utils.MockConfigRule;
 
 public class GetDeviceListQueryTest extends 
AbstractQueryTest<GetDeviceListQueryParameters, 
GetDeviceListQuery<GetDeviceListQueryParameters>> {
-
-    @ClassRule
-    public static final MockConfigRule mcr = new MockConfigRule(
-            mockConfig(ConfigValues.UserSessionTimeOutInterval, 60));
-
     private DbFacade dbFacadeMock;
     private LunDAO lunDAOMock;
     private VdsDAO vdsDAOMock;
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 1a3c63a..d43f80a 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
@@ -86,6 +86,10 @@
         mockConfigValue(value, version.getValue(), returnValue);
     }
 
+    public <T> void mockConfigValue(MockConfigDescriptor<T> mcd) {
+        mockConfigValue(mcd.getValue(), mcd.getVersion(), 
mcd.getReturnValue());
+    }
+
     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/36800
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1d511b1f67e842a64b7c9322a0d526e717f4a601
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.5
Gerrit-Owner: Allon Mureinik <amure...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to