From ca4e798f1a3e29e6918e695b91bc8376a2bf67ed Mon Sep 17 00:00:00 2001
From: Michael Calmer <michael.calmer@suse.com>
Date: Thu, 12 Dec 2024 16:36:37 +0100
Subject: [PATCH 2/2] adapt unit tests

---
 code/src/com/redhat/rhn/taskomatic/task/payg/test/PaygUpdateAuthTaskTest.java |   30 +++++++---
 1 file changed, 21 insertions(+), 9 deletions(-)

--- a/code/src/com/redhat/rhn/taskomatic/task/payg/test/PaygUpdateAuthTaskTest.java
+++ b/code/src/com/redhat/rhn/taskomatic/task/payg/test/PaygUpdateAuthTaskTest.java
@@ -327,19 +327,33 @@ public class PaygUpdateAuthTaskTest exte
         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");
@@ -385,9 +399,7 @@ public class PaygUpdateAuthTaskTest exte
 
         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());
@@ -400,6 +412,9 @@ public class PaygUpdateAuthTaskTest exte
 
         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());
@@ -428,9 +443,6 @@ public class PaygUpdateAuthTaskTest exte
         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
