Skip to content

Commit

Permalink
adapt unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcalmer committed Dec 19, 2024
1 parent 13171f6 commit a2e30a8
Showing 1 changed file with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,19 +314,33 @@ public void testJschException() throws Exception {
paygData = HibernateFactory.reload(paygData);
assertContains(paygData.getErrorMessage(), "My JSchException exception");
assertEquals(paygData.getStatus(), PaygSshData.Status.E);
assertEquals(1, UserNotificationFactory.listAllNotificationMessages().size());
assertEquals(NotificationType.PaygAuthenticationUpdateFailed,
UserNotificationFactory.listAllNotificationMessages().get(0).getType());
}

@Test
public void testPaygDataExtractException() throws Exception {
CloudRMTCredentials cloudCreds =
CredentialsFactory.createCloudRmtCredentials("user", "pass", "http://cloud.org");
cloudCreds.setPaygSshData(paygData);
CredentialsFactory.storeCredentials(cloudCreds);
HibernateFactory.commitTransaction();

checking(new Expectations() {
{
allowing(contentSyncManagerMock).updateRepositoriesPayg();
oneOf(paygAuthDataExtractorMock).extractAuthData(with(any(PaygSshData.class)));
will(throwException(new PaygDataExtractException("My PaygDataExtractException")));
allowing(contentSyncManagerMock).updateRepositoriesPayg();
oneOf(paygAuthDataExtractorMock).extractAuthData(with(any(PaygSshData.class)));
will(throwException(new PaygDataExtractException("My PaygDataExtractException")));
}});
// First Call with error
paygUpdateAuthTask.execute(null);
paygData = HibernateFactory.reload(paygData);
assertContains(paygData.getErrorMessage(), "My PaygDataExtractException");
assertEquals(paygData.getStatus(), PaygSshData.Status.E);
assertEquals(0, UserNotificationFactory.listAllNotificationMessages().size());

// Second Call with error
paygUpdateAuthTask.execute(null);
paygData = HibernateFactory.reload(paygData);
assertContains(paygData.getErrorMessage(), "My PaygDataExtractException");
Expand Down Expand Up @@ -372,9 +386,7 @@ public void testPaygDataExtractExceptionInvalidateCredentials() throws Exception

assertContains(paygData.getErrorMessage(), "My PaygDataExtractException");
assertEquals(paygData.getStatus(), PaygSshData.Status.E);
assertEquals(1, UserNotificationFactory.listAllNotificationMessages().size());
assertEquals(NotificationType.PaygAuthenticationUpdateFailed,
UserNotificationFactory.listAllNotificationMessages().get(0).getType());
assertEquals(0, UserNotificationFactory.listAllNotificationMessages().size());
creds = paygData.getCredentials().castAs(CloudRMTCredentials.class);
assertTrue(creds.isPresent());
assertEquals("0e248802", creds.get().getPassword());
Expand All @@ -387,6 +399,9 @@ public void testPaygDataExtractExceptionInvalidateCredentials() throws Exception

assertContains(paygData.getErrorMessage(), "My PaygDataExtractException");
assertEquals(paygData.getStatus(), PaygSshData.Status.E);
assertEquals(1, UserNotificationFactory.listAllNotificationMessages().size());
assertEquals(NotificationType.PaygAuthenticationUpdateFailed,
UserNotificationFactory.listAllNotificationMessages().get(0).getType());
creds = paygData.getCredentials().castAs(CloudRMTCredentials.class);
assertTrue(creds.isPresent());
assertEquals("invalidated", creds.get().getPassword());
Expand Down Expand Up @@ -415,9 +430,6 @@ public void testGenericException() throws Exception {
paygData = HibernateFactory.reload(paygData);
assertNull(paygData.getErrorMessage());
assertEquals(paygData.getStatus(), PaygSshData.Status.E);
assertEquals(1, UserNotificationFactory.listAllNotificationMessages().size());
assertEquals(NotificationType.PaygAuthenticationUpdateFailed,
UserNotificationFactory.listAllNotificationMessages().get(0).getType());
}

@Test
Expand Down

0 comments on commit a2e30a8

Please sign in to comment.