From 48b7b490e93f89da90a5adf40aa5c91a62a86cc3 Mon Sep 17 00:00:00 2001
From: Ondrej Holecek <oholecek@suse.com>
Date: Mon, 10 Feb 2025 14:19:42 +0100
Subject: [PATCH] Add baseChannel to the provisioning test data

---
 .../test/SystemHandlerProvisioningTest.java   | 34 +++++++++++--------
 1 file changed, 20 insertions(+), 14 deletions(-)
#L3PD: bsc#1237544

diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/test/SystemHandlerProvisioningTest.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/test/SystemHandlerProvisioningTest.java
index dae69329d62..2b9071d2e75 100644
--- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/test/SystemHandlerProvisioningTest.java
+++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/test/SystemHandlerProvisioningTest.java
@@ -24,13 +24,14 @@
 import com.redhat.rhn.domain.action.ActionFactory;
 import com.redhat.rhn.domain.action.kickstart.KickstartActionDetails;
 import com.redhat.rhn.domain.action.kickstart.KickstartInitiateAction;
+import com.redhat.rhn.domain.channel.Channel;
+import com.redhat.rhn.domain.channel.test.ChannelFactoryTest;
 import com.redhat.rhn.domain.kickstart.KickstartData;
 import com.redhat.rhn.domain.kickstart.KickstartFactory;
 import com.redhat.rhn.domain.kickstart.KickstartSession;
 import com.redhat.rhn.domain.kickstart.test.KickstartDataTest;
 import com.redhat.rhn.domain.rhnpackage.Package;
 import com.redhat.rhn.domain.rhnpackage.test.PackageTest;
-import com.redhat.rhn.domain.server.MinionServer;
 import com.redhat.rhn.domain.server.Server;
 import com.redhat.rhn.domain.server.ServerFactory;
 import com.redhat.rhn.domain.server.ServerGroupFactory;
@@ -38,7 +39,6 @@
 import com.redhat.rhn.frontend.xmlrpc.system.SystemHandler;
 import com.redhat.rhn.frontend.xmlrpc.system.XmlRpcSystemHelper;
 import com.redhat.rhn.frontend.xmlrpc.test.BaseHandlerTestCase;
-import com.redhat.rhn.manager.entitlement.EntitlementManager;
 import com.redhat.rhn.manager.formula.FormulaMonitoringManager;
 import com.redhat.rhn.manager.rhnpackage.test.PackageManagerTest;
 import com.redhat.rhn.manager.system.ServerGroupManager;
@@ -48,7 +48,6 @@
 import com.redhat.rhn.manager.system.entitling.SystemUnentitler;
 import com.redhat.rhn.taskomatic.TaskomaticApi;
 import com.redhat.rhn.testing.RhnMockHttpServletRequest;
-import com.redhat.rhn.testing.ServerTestUtils;
 import com.redhat.rhn.testing.TestUtils;
 
 import com.suse.cloud.CloudPaygManager;
@@ -81,10 +80,12 @@ public class SystemHandlerProvisioningTest extends BaseHandlerTestCase {
         private final SystemQuery systemQuery = new TestSystemQuery();
         private final SaltApi saltApi = new TestSaltApi();
         private final CloudPaygManager paygManager = new CloudPaygManager();
+
         private RegularMinionBootstrapper regularMinionBootstrapper =
                 new RegularMinionBootstrapper(systemQuery, saltApi, paygManager);
         private SSHMinionBootstrapper sshMinionBootstrapper = new SSHMinionBootstrapper(systemQuery, saltApi,
                 paygManager);
+
         private XmlRpcSystemHelper xmlRpcSystemHelper = new XmlRpcSystemHelper(
                 regularMinionBootstrapper,
                 sshMinionBootstrapper
@@ -98,6 +99,7 @@ public class SystemHandlerProvisioningTest extends BaseHandlerTestCase {
         );
         private SystemManager systemManager =
                 new SystemManager(ServerFactory.SINGLETON, ServerGroupFactory.SINGLETON, saltApi);
+
         private SystemHandler handler =
                 new SystemHandler(taskomaticApi, xmlRpcSystemHelper, systemEntitlementManager, systemManager,
                         serverGroupManager, new CloudPaygManager());
@@ -118,13 +120,15 @@ public void setUp() throws Exception {
 
         @Test
         public void testProvisionSystem() throws Exception {
-                MinionServer server = MinionServerFactoryTest.createTestMinionServer(admin);
-                systemEntitlementManager.setBaseEntitlement(server, EntitlementManager.SALT);
+                Server server = MinionServerFactoryTest.createTestMinionServer(admin);
                 TestUtils.saveAndFlush(server);
                 server = reload(server);
 
+                Channel baseChannel = ChannelFactoryTest.createTestChannel(admin);
                 // salt-minion package has to be added to pass Kickstart validator
                 Package testPackage = PackageTest.createTestPackage(admin.getOrg(), "salt-minion");
+                baseChannel.getPackages().add(testPackage);
+                server = SystemManager.subscribeServerToChannel(admin, server, baseChannel);
                 PackageManagerTest.associateSystemToPackage(server, testPackage);
 
                 KickstartDataTest.setupTestConfiguration(admin);
@@ -155,22 +159,22 @@ public void testProvisionSystem() throws Exception {
                 KickstartInitiateAction kia = (KickstartInitiateAction) actions.get(0);
                 KickstartActionDetails kad = kia.getKickstartActionDetails();
                 assertEquals(ConfigDefaults.get().getHostname(), kad.getKickstartHost());
-
         }
 
         @Test
         public void testProvisionSystemFromProxy() throws Exception {
-                MinionServer server = MinionServerFactoryTest.createTestMinionServer(admin);
-                systemEntitlementManager.setBaseEntitlement(server, EntitlementManager.SALT);
+                Server server = MinionServerFactoryTest.createTestMinionServer(admin);
                 TestUtils.saveAndFlush(server);
                 server = reload(server);
 
+                Channel baseChannel = ChannelFactoryTest.createTestChannel(admin);
                 // salt-minion package has to be added to pass Kickstart validator
                 Package testPackage = PackageTest.createTestPackage(admin.getOrg(), "salt-minion");
+                baseChannel.getPackages().add(testPackage);
+                server = SystemManager.subscribeServerToChannel(admin, server, baseChannel);
                 PackageManagerTest.associateSystemToPackage(server, testPackage);
 
-                Server proxy = ServerTestUtils.createTestSystem(admin);
-                systemEntitlementManager.setBaseEntitlement(server, EntitlementManager.SALT);
+                Server proxy = MinionServerFactoryTest.createTestMinionServer(admin);
                 proxy.setHostname("proxy.example.com");
                 SystemManager.activateProxy(proxy, "4.3");
                 TestUtils.saveAndFlush(proxy);
@@ -181,6 +185,7 @@ public void testProvisionSystemFromProxy() throws Exception {
                 KickstartDataTest.addCommand(admin, k,
                         "custom", "echo test-command 2");
                 k.getKickstartDefaults().getKstree().setChannel(server.getBaseChannel());
+
                 String profileName = k.getLabel();
                 RhnMockHttpServletRequest request = new RhnMockHttpServletRequest();
 
@@ -209,17 +214,18 @@ public void testProvisionSystemFromProxy() throws Exception {
 
         @Test
         public void testProvisionSystemFromProxyAutoDetected() throws Exception {
-                MinionServer server = MinionServerFactoryTest.createTestMinionServer(admin);
-                systemEntitlementManager.setBaseEntitlement(server, EntitlementManager.SALT);
+                Server server = MinionServerFactoryTest.createTestMinionServer(admin);
                 TestUtils.saveAndFlush(server);
                 server = reload(server);
 
+                Channel baseChannel = ChannelFactoryTest.createTestChannel(admin);
                 // salt-minion package has to be added to pass Kickstart validator
                 Package testPackage = PackageTest.createTestPackage(admin.getOrg(), "salt-minion");
+                baseChannel.getPackages().add(testPackage);
+                server = SystemManager.subscribeServerToChannel(admin, server, baseChannel);
                 PackageManagerTest.associateSystemToPackage(server, testPackage);
 
-                Server proxy = ServerTestUtils.createTestSystem(admin);
-                systemEntitlementManager.setBaseEntitlement(server, EntitlementManager.SALT);
+                Server proxy = MinionServerFactoryTest.createTestMinionServer(admin);
                 proxy.setHostname("proxy.example.com");
                 SystemManager.activateProxy(proxy, "4.3");
                 TestUtils.saveAndFlush(proxy);
