Shireesh Anjal has uploaded a new change for review. Change subject: engine: New test method in DBConfigUtilsTest ......................................................................
engine: New test method in DBConfigUtilsTest There seems to be a perception in the community that there is some bug in the config framework because of which the api returns a null value if there is no entry in vdc_options for a given config. This patch attempts to add a new test case that verifies that this is not the case, and if entry is missing in vdc_options, value returned is from the @DefaultValueAttribute annotation in ConfigValues enum. For this purpose, - Modified DBConfigUtilsTest to extend from BaseDAOTestCase, so that fixtures.xml can be used to insert entries in vdc_options - Modified fixtures.xml to insert two entries in vdc_options for the config NonVmNetworkSupported for version 3.0 and 3.2 - Renamed DBConfigUtils#RefreshVdcOptionCache to refreshVdcOptionCache and made it protected so that it can be called from test class passing the test dbFacade - Added new test method testGetValue() to verify that default value is returned if entry is not present in vdc_options Change-Id: Ia736419e766bc6ce2e82158f775817e885b90dfd Signed-off-by: Shireesh Anjal <[email protected]> --- M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/generic/DBConfigUtils.java M backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/dbbroker/generic/DBConfigUtilsTest.java M backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdcOptionDAOTest.java M backend/manager/modules/dal/src/test/resources/fixtures.xml 4 files changed, 35 insertions(+), 5 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/87/13787/1 diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/generic/DBConfigUtils.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/generic/DBConfigUtils.java index 53d406b..9df8c0d 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/generic/DBConfigUtils.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/generic/DBConfigUtils.java @@ -28,7 +28,7 @@ /** * Refreshes the VDC option cache. */ - private static void RefreshVdcOptionCache(DbFacade db) { + protected static void refreshVdcOptionCache(DbFacade db) { _vdcOptionCache.clear(); List<VdcOption> list = db.getVdcOptionDao().getAll(); for (VdcOption option : list) { @@ -169,7 +169,7 @@ public DBConfigUtils(boolean initDB) { if (initDB) { dbfacade = DbFacade.getInstance(); - RefreshVdcOptionCache(dbfacade); + refreshVdcOptionCache(dbfacade); } } diff --git a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/dbbroker/generic/DBConfigUtilsTest.java b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/dbbroker/generic/DBConfigUtilsTest.java index ba57dfb..bff79f8 100644 --- a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/dbbroker/generic/DBConfigUtilsTest.java +++ b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/dbbroker/generic/DBConfigUtilsTest.java @@ -7,18 +7,23 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigCommon; import org.ovirt.engine.core.common.config.ConfigValues; import org.ovirt.engine.core.common.config.OptionBehaviour; import org.ovirt.engine.core.common.config.OptionBehaviourAttribute; import org.ovirt.engine.core.common.config.TypeConverterAttribute; +import org.ovirt.engine.core.dao.BaseDAOTestCase; -public class DBConfigUtilsTest { +public class DBConfigUtilsTest extends BaseDAOTestCase { private DBConfigUtils config; + @Override @Before - public void setup() { + public void setUp() throws Exception { + super.setUp(); config = new DBConfigUtils(false); + config.refreshVdcOptionCache(dbFacade); } @Test @@ -57,4 +62,19 @@ c.isInstance(obj)); } } + + @Test + public void testGetValue() { + // Verify that values for 3.0 and 3.2 are from DB (since the entries are present in fixtures.xml) + // and for 3.1, it's the default value from annotation in ConfigValues. + // 3.0 -> false, 3.1 -> true, 3.2 -> true + Assert.assertFalse((Boolean)config.GetValue(ConfigValues.NonVmNetworkSupported, "3.0")); + Assert.assertFalse(Config.<Boolean> GetValue(ConfigValues.NonVmNetworkSupported, "3.0")); + + Assert.assertTrue((Boolean)config.GetValue(ConfigValues.NonVmNetworkSupported, "3.1")); + Assert.assertTrue(Config.<Boolean> GetValue(ConfigValues.NonVmNetworkSupported, "3.1")); + + Assert.assertTrue((Boolean)config.GetValue(ConfigValues.NonVmNetworkSupported, "3.2")); + Assert.assertTrue(Config.<Boolean> GetValue(ConfigValues.NonVmNetworkSupported, "3.2")); + } } diff --git a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdcOptionDAOTest.java b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdcOptionDAOTest.java index 158630e..4f7fae1 100644 --- a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdcOptionDAOTest.java +++ b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdcOptionDAOTest.java @@ -9,7 +9,7 @@ import org.ovirt.engine.core.common.businessentities.VdcOption; public class VdcOptionDAOTest extends BaseDAOTestCase { - private static final int OPTION_COUNT = 5; + private static final int OPTION_COUNT = 7; private VdcOptionDAO dao; private VdcOption existingOption; private VdcOption newOption; diff --git a/backend/manager/modules/dal/src/test/resources/fixtures.xml b/backend/manager/modules/dal/src/test/resources/fixtures.xml index 050ef7a..d43b1a2 100644 --- a/backend/manager/modules/dal/src/test/resources/fixtures.xml +++ b/backend/manager/modules/dal/src/test/resources/fixtures.xml @@ -28,6 +28,16 @@ <value></value> <value>general</value> </row> + <row> + <value>NonVmNetworkSupported</value> + <value>false</value> + <value>3.0</value> + </row> + <row> + <value>NonVmNetworkSupported</value> + <value>true</value> + <value>3.2</value> + </row> </table> -- To view, visit http://gerrit.ovirt.org/13787 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia736419e766bc6ce2e82158f775817e885b90dfd Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Shireesh Anjal <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
