From 2d488dfd16cc19cf04278e8fa612e8101f236f3d Mon Sep 17 00:00:00 2001 From: Thomas Florio Date: Tue, 17 Oct 2023 16:23:21 +0200 Subject: [PATCH] Add test to ensure updateRepositoriesPayg() does not call SCC --- .../manager/content/ContentSyncManager.java | 2 +- .../content/test/ContentSyncManagerTest.java | 31 +++++++++++++++++-- .../rhn/testing/MockObjectTestCase.java | 14 +++++---- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/java/code/src/com/redhat/rhn/manager/content/ContentSyncManager.java b/java/code/src/com/redhat/rhn/manager/content/ContentSyncManager.java index 718ccfec6e53..463cdb11c6c3 100644 --- a/java/code/src/com/redhat/rhn/manager/content/ContentSyncManager.java +++ b/java/code/src/com/redhat/rhn/manager/content/ContentSyncManager.java @@ -2488,7 +2488,7 @@ protected boolean accessibleUrl(String url, String user, String password) { * @throws SCCClientException when access is not possible * @return {@link SCCWebClient} */ - private SCCClient getSCCClient(Credentials credentials) + protected SCCClient getSCCClient(Credentials credentials) throws URISyntaxException, SCCClientException { // check that URL is valid URI url = new URI(Config.get().getString(ConfigDefaults.SCC_URL)); diff --git a/java/code/src/com/redhat/rhn/manager/content/test/ContentSyncManagerTest.java b/java/code/src/com/redhat/rhn/manager/content/test/ContentSyncManagerTest.java index 7621f2f47ed4..93fd702912dd 100644 --- a/java/code/src/com/redhat/rhn/manager/content/test/ContentSyncManagerTest.java +++ b/java/code/src/com/redhat/rhn/manager/content/test/ContentSyncManagerTest.java @@ -16,6 +16,8 @@ import static com.redhat.rhn.domain.channel.test.ChannelFactoryTest.createTestClonedChannel; +import static com.redhat.rhn.testing.RhnBaseTestCase.assertContains; +import static com.redhat.rhn.testing.RhnBaseTestCase.assertNotEmpty; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -67,7 +69,7 @@ import com.redhat.rhn.manager.content.ProductTreeEntry; import com.redhat.rhn.manager.setup.MirrorCredentialsManager; import com.redhat.rhn.manager.system.SystemManager; -import com.redhat.rhn.testing.BaseTestCaseWithUser; +import com.redhat.rhn.testing.JMockBaseTestCaseWithUser; import com.redhat.rhn.testing.TestUtils; import com.suse.cloud.CloudPaygManager; @@ -75,6 +77,7 @@ import com.suse.manager.webui.services.pillar.MinionPillarManager; import com.suse.mgrsync.MgrSyncStatus; import com.suse.salt.netapi.parser.JsonParser; +import com.suse.scc.client.SCCClient; import com.suse.scc.model.ChannelFamilyJson; import com.suse.scc.model.SCCProductJson; import com.suse.scc.model.SCCRepositoryJson; @@ -111,7 +114,7 @@ /** * Tests for {@link ContentSyncManager}. */ -public class ContentSyncManagerTest extends BaseTestCaseWithUser { +public class ContentSyncManagerTest extends JMockBaseTestCaseWithUser { // Files we read private static final String JARPATH = "/com/redhat/rhn/manager/content/test/"; @@ -2380,6 +2383,30 @@ public void testBuildRepoFileUrl() throws Exception { assertEquals(2, csm.buildRepoFileUrl(repourl, rpmrepo).size()); } + @Test + public void updateRepositoriesForPaygDoNotCallSCC() { + Credentials credentials = CredentialsFactory.createSCCCredentials(); + credentials.setPassword("dummy"); + credentials.setUrl("dummy"); + credentials.setUsername("dummy"); + credentials.setUser(user); + CredentialsFactory.storeCredentials(credentials); + + SCCClient sccClient = mock(SCCClient.class); + + checking(expectations -> { + expectations.never(sccClient).listRepositories(); + }); + + ContentSyncManager csm = new ContentSyncManager() { + @Override + protected SCCClient getSCCClient(Credentials credentials) { + return sccClient; + } + }; + + csm.updateRepositoriesPayg(); + } /** * {@inheritDoc} diff --git a/java/code/src/com/redhat/rhn/testing/MockObjectTestCase.java b/java/code/src/com/redhat/rhn/testing/MockObjectTestCase.java index 18220333c48e..c8e0ad50550a 100644 --- a/java/code/src/com/redhat/rhn/testing/MockObjectTestCase.java +++ b/java/code/src/com/redhat/rhn/testing/MockObjectTestCase.java @@ -15,6 +15,8 @@ package com.redhat.rhn.testing; +import com.suse.utils.Exceptions; + import org.jmock.Expectations; import org.jmock.Mockery; import org.jmock.States; @@ -24,8 +26,6 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; -import java.util.function.Consumer; - /** * jMock boilerplate. */ @@ -59,10 +59,12 @@ public void checking(ExpectationBuilder expectations) { /** * @param expectationsConsumer consumer to build the expectations */ - public void checking(Consumer expectationsConsumer) { - Expectations expectations = new Expectations(); - expectationsConsumer.accept(expectations); - context.checking(expectations); + public void checking(Exceptions.ThrowingConsumer expectationsConsumer) { + Exceptions.handleByWrapping(() -> { + Expectations expectations = new Expectations(); + expectationsConsumer.accept(expectations); + context.checking(expectations); + }); } /**