Hi,

We propose some patches to avoid the junit testsuite to depend on
Cobbler. With those, we are able to run all the tests using only a
database instance seeded with the latest schema version. Details:

- patch 17 calls setupTestConfiguration() on KickstartDataTest before
calling other members of the same class which, as far as I understand,
is the correct approach here;
- patch 18 does the same in SystemHandlerTest, which also used other
methods from KickstartDataTest;
- patch 19 adds code to mock the Cobbler connection in SystemManagerTest.

About patch 19: we noticed that most tests where Cobbler was required
were failing because they called SystemManager.deleteServer(). That
method used to remove a system from the database only, but later (in
2011) a patch was added to call Cobbler to delete the system from there
as well. Test code was never updated for Cobbler so it only checks
database and objects, so I think it makes sense to just use a mocked
connection to avoid the Cobbler exception on a test system that will
never be in Cobbler anyway.

Comments welcome!

Regards,
-- 
Silvio Moioli
SUSE LINUX Products GmbH
Maxfeldstraße 5, 90409 Nürnberg Germany


>From 0351959bb8c0398b1243fa045caa2eb580b8ad4a Mon Sep 17 00:00:00 2001
From: Silvio Moioli <smoi...@suse.de>
Date: Wed, 11 Sep 2013 14:28:05 +0200
Subject: [PATCH 17/22] ActionManagerTest: do not rely on Cobbler, mock the
 connection

---
 java/code/src/com/redhat/rhn/manager/action/test/ActionManagerTest.java | 1 +
 1 file changed, 1 insertion(+)

diff --git a/java/code/src/com/redhat/rhn/manager/action/test/ActionManagerTest.java b/java/code/src/com/redhat/rhn/manager/action/test/ActionManagerTest.java
index c80b5c3..e0094c3 100644
--- a/java/code/src/com/redhat/rhn/manager/action/test/ActionManagerTest.java
+++ b/java/code/src/com/redhat/rhn/manager/action/test/ActionManagerTest.java
@@ -332,6 +332,7 @@ public class ActionManagerTest extends RhnBaseTestCase {
             .getServer();
         ActionFactory.save(parentAction);
 
+        KickstartDataTest.setupTestConfiguration(user);
         KickstartData ksData = KickstartDataTest.createKickstartWithOptions(user.getOrg());
         KickstartSession ksSession = KickstartSessionTest.createKickstartSession(server,
                 ksData, user, parentAction);
-- 
1.8.1.4



>From df48d9e1b93a028c91ac4537ac26518857d630b7 Mon Sep 17 00:00:00 2001
From: Silvio Moioli <smoi...@suse.de>
Date: Wed, 11 Sep 2013 14:39:44 +0200
Subject: [PATCH 18/22] SystemHandlerTest: do not rely on Cobbler, use mock the
 connection

---
 .../com/redhat/rhn/frontend/xmlrpc/system/test/SystemHandlerTest.java   | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/test/SystemHandlerTest.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/test/SystemHandlerTest.java
index 69d199a..2bdf677 100644
--- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/test/SystemHandlerTest.java
+++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/test/SystemHandlerTest.java
@@ -718,6 +718,7 @@ public class SystemHandlerTest extends BaseHandlerTestCase {
         Long sid = server.getId();
         ClientCertificate cert = SystemManager.createClientCertificate(server);
         cert.validate(server.getSecret());
+        KickstartDataTest.setupTestConfiguration(admin);
         assertEquals(1, handler.deleteSystem(cert.toString()));
         assertNull(ServerFactory.lookupById(sid));
     }
@@ -753,6 +754,7 @@ public class SystemHandlerTest extends BaseHandlerTestCase {
         server.setBaseEntitlement(EntitlementManager.MANAGEMENT);
         TestUtils.saveAndFlush(server);
         server = (Server) reload(server);
+        KickstartDataTest.setupTestConfiguration(admin);
         KickstartData k = KickstartDataTest.createKickstartWithProfile(admin);
         KickstartDataTest.addCommand(admin, k, "url", "--url http://cascade.sfbay.redhat."; +
         "com/rhn/kickstart/ks-rhel-i386-server-5");
-- 
1.8.1.4


>From a2d6170e1d9692b81a9eaba3fa6bbb5e46cb9021 Mon Sep 17 00:00:00 2001
From: Silvio Moioli <smoi...@suse.de>
Date: Wed, 11 Sep 2013 15:12:42 +0200
Subject: [PATCH 19/22] SystemManagerTest: do not rely on Cobbler, mock the
 connection

---
 .../redhat/rhn/manager/system/test/SystemManagerTest.java    | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/java/code/src/com/redhat/rhn/manager/system/test/SystemManagerTest.java b/java/code/src/com/redhat/rhn/manager/system/test/SystemManagerTest.java
index 956d77e..ea745ec 100644
--- a/java/code/src/com/redhat/rhn/manager/system/test/SystemManagerTest.java
+++ b/java/code/src/com/redhat/rhn/manager/system/test/SystemManagerTest.java
@@ -14,6 +14,7 @@
  */
 package com.redhat.rhn.manager.system.test;
 
+import com.redhat.rhn.common.conf.Config;
 import com.redhat.rhn.common.conf.ConfigDefaults;
 import com.redhat.rhn.common.db.datasource.DataResult;
 import com.redhat.rhn.common.db.datasource.ModeFactory;
@@ -66,6 +67,8 @@ import com.redhat.rhn.frontend.dto.SystemOverview;
 import com.redhat.rhn.frontend.listview.PageControl;
 import com.redhat.rhn.manager.entitlement.EntitlementManager;
 import com.redhat.rhn.manager.errata.cache.ErrataCacheManager;
+import com.redhat.rhn.manager.kickstart.cobbler.CobblerXMLRPCHelper;
+import com.redhat.rhn.manager.kickstart.cobbler.test.MockXMLRPCInvoker;
 import com.redhat.rhn.manager.rhnpackage.test.PackageManagerTest;
 import com.redhat.rhn.manager.rhnset.RhnSetDecl;
 import com.redhat.rhn.manager.rhnset.RhnSetManager;
@@ -79,6 +82,7 @@ import com.redhat.rhn.testing.TestStatics;
 import com.redhat.rhn.testing.TestUtils;
 import com.redhat.rhn.testing.UserTestUtils;
 
+import org.cobbler.test.MockConnection;
 import org.hibernate.Hibernate;
 import org.hibernate.Session;
 
@@ -101,6 +105,14 @@ public class SystemManagerTest extends RhnBaseTestCase {
     public static final int HOST_RAM_MB = 2048;
     public static final int HOST_SWAP_MB = 1024;
 
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        Config.get().setString(CobblerXMLRPCHelper.class.getName(),
+                MockXMLRPCInvoker.class.getName());
+        MockConnection.clear();
+    }
+
     public void testSnapshotServer() throws Exception {
         User user = UserTestUtils.findNewUser("testUser",
                 "testOrg" + this.getClass().getSimpleName());
-- 
1.8.1.4


_______________________________________________
Spacewalk-devel mailing list
Spacewalk-devel@redhat.com
https://www.redhat.com/mailman/listinfo/spacewalk-devel

Reply via email to