Skip to content

Commit

Permalink
Fixed unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mackdk committed Oct 2, 2023
1 parent b10214d commit c50f2bf
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.quartz.JobExecutionException;

import java.io.BufferedReader;
import java.io.InputStreamReader;
Expand Down Expand Up @@ -103,8 +104,6 @@ public void setUp() throws Exception {
paygAuthDataExtractorMock = mock(PaygAuthDataExtractor.class);
contentSyncManagerMock = mock(ContentSyncManager.class);

checking(new Expectations() {{ allowing(contentSyncManagerMock).updateRepositories(null); }});

paygUpdateAuthTask = new PaygUpdateAuthTask();

paygUpdateAuthTask.setCloudPaygManager(new CloudPaygManager());
Expand Down Expand Up @@ -141,6 +140,7 @@ private void clearDb() {
public void testLocalhostPaygConnection() throws Exception {
checking(new Expectations() {
{
allowing(contentSyncManagerMock).updateRepositoriesPayg();
oneOf(paygAuthDataExtractorMock).extractAuthData(with(any(PaygSshData.class)));
will(returnValue(paygInstanceInfo));
oneOf(paygAuthDataExtractorMock).extractAuthData(with(any(PaygSshData.class)));
Expand Down Expand Up @@ -238,10 +238,13 @@ public boolean isPaygInstance() {
}
}
}

@Test
public void testRHUIConnection() throws Exception {
PaygInstanceInfo rhuiInstanceInfo = createRHUIInstanceInfo();
checking(new Expectations() {
{
allowing(contentSyncManagerMock).updateRepositoriesPayg();
oneOf(paygAuthDataExtractorMock).extractAuthData(with(any(PaygSshData.class)));
will(returnValue(rhuiInstanceInfo));
}});
Expand Down Expand Up @@ -308,6 +311,7 @@ else if (cs.getLabel().equals("repo-label-2-c" + cid)) {
public void testJschException() throws Exception {
checking(new Expectations() {
{
allowing(contentSyncManagerMock).updateRepositoriesPayg();
oneOf(paygAuthDataExtractorMock).extractAuthData(with(any(PaygSshData.class)));
will(throwException(new JSchException("My JSchException exception")));
}});
Expand All @@ -324,6 +328,7 @@ public void testJschException() throws Exception {
public void testPaygDataExtractException() throws Exception {
checking(new Expectations() {
{
allowing(contentSyncManagerMock).updateRepositoriesPayg();
oneOf(paygAuthDataExtractorMock).extractAuthData(with(any(PaygSshData.class)));
will(throwException(new PaygDataExtractException("My PaygDataExtractException")));
}});
Expand All @@ -346,6 +351,7 @@ public void testPaygDataExtractException() throws Exception {
public void testPaygDataExtractExceptionInvalidateCredentials() throws Exception {
checking(new Expectations() {
{
allowing(contentSyncManagerMock).updateRepositoriesPayg();
oneOf(paygAuthDataExtractorMock).extractAuthData(with(any(PaygSshData.class)));
will(returnValue(paygInstanceInfo));
oneOf(paygAuthDataExtractorMock).extractAuthData(with(any(PaygSshData.class)));
Expand Down Expand Up @@ -406,7 +412,7 @@ public void testPaygDataExtractExceptionInvalidateCredentials() throws Exception
public void testGenericException() throws Exception {
checking(new Expectations() {
{

allowing(contentSyncManagerMock).updateRepositoriesPayg();
oneOf(paygAuthDataExtractorMock).extractAuthData(with(any(PaygSshData.class)));
will(throwException(new Exception("My Exception")));
}});
Expand All @@ -423,6 +429,7 @@ public void testGenericException() throws Exception {
public void testSuccessClearStatus() throws Exception {
checking(new Expectations() {
{
allowing(contentSyncManagerMock).updateRepositoriesPayg();
oneOf(paygAuthDataExtractorMock).extractAuthData(with(any(PaygSshData.class)));
will(returnValue(paygInstanceInfo));
}});
Expand All @@ -433,6 +440,18 @@ public void testSuccessClearStatus() throws Exception {
assertEquals(0, UserNotificationFactory.listAllNotificationMessages().size());
}

@Test
public void doNotCallContentSyncManagerIfNoSshDataConnectionIsDefined() throws JobExecutionException {
PaygSshDataFactory.lookupPaygSshData().forEach(PaygSshDataFactory::deletePaygSshData);
commitAndCloseSession();

checking(new Expectations() {{
never(contentSyncManagerMock).updateRepositoriesPayg();
}});

paygUpdateAuthTask.execute(null);
}

private PaygSshData createPaygSshData() {
PaygSshData paygSshData = PaygSshDataFactory.createPaygSshData();
paygSshData.setDescription("My special instance");
Expand Down

0 comments on commit c50f2bf

Please sign in to comment.