Skip to content

Commit

Permalink
Add test to ensure updateRepositoriesPayg() does not call SCC
Browse files Browse the repository at this point in the history
  • Loading branch information
mackdk committed Oct 17, 2023
1 parent bdaedb2 commit 2d488df
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,14 +69,15 @@
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;
import com.suse.manager.webui.services.pillar.MinionGeneralPillarGenerator;
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;
Expand Down Expand Up @@ -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/";
Expand Down Expand Up @@ -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}
Expand Down
14 changes: 8 additions & 6 deletions java/code/src/com/redhat/rhn/testing/MockObjectTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*/
Expand Down Expand Up @@ -59,10 +59,12 @@ public void checking(ExpectationBuilder expectations) {
/**
* @param expectationsConsumer consumer to build the expectations
*/
public void checking(Consumer<Expectations> expectationsConsumer) {
Expectations expectations = new Expectations();
expectationsConsumer.accept(expectations);
context.checking(expectations);
public void checking(Exceptions.ThrowingConsumer<Expectations, Exception> expectationsConsumer) {
Exceptions.handleByWrapping(() -> {
Expectations expectations = new Expectations();
expectationsConsumer.accept(expectations);
context.checking(expectations);
});
}

/**
Expand Down

0 comments on commit 2d488df

Please sign in to comment.