From 3028dfa469db478dc63c006ff367a577820fd628 Mon Sep 17 00:00:00 2001 From: Ethaniel Billon Date: Wed, 11 Dec 2024 13:13:28 +0100 Subject: [PATCH] tests fixes and workflowbusiness --- .../vip/application/server/business/EngineBusiness.java | 3 ++- .../application/server/business/WorkflowBusiness.java | 6 +++--- .../creatis/vip/core/server/business/EmailBusiness.java | 4 +--- .../vip/core/integrationtest/UsersAndGroupsIT.java | 9 +-------- .../core/integrationtest/database/SpringDatabaseIT.java | 2 +- .../vip/core/integrationtest/database/SpringJndiIT.java | 2 +- 6 files changed, 9 insertions(+), 17 deletions(-) diff --git a/vip-application/src/main/java/fr/insalyon/creatis/vip/application/server/business/EngineBusiness.java b/vip-application/src/main/java/fr/insalyon/creatis/vip/application/server/business/EngineBusiness.java index bd7aeaa0c..48261a97d 100644 --- a/vip-application/src/main/java/fr/insalyon/creatis/vip/application/server/business/EngineBusiness.java +++ b/vip-application/src/main/java/fr/insalyon/creatis/vip/application/server/business/EngineBusiness.java @@ -60,8 +60,9 @@ public class EngineBusiness { private EngineDAO engineDAO; private WorkflowDAO workflowDAO; - public EngineBusiness(EngineDAO engineDAO) { + public EngineBusiness(EngineDAO engineDAO, WorkflowDAO workflowDAO) { this.engineDAO = engineDAO; + this.workflowDAO = workflowDAO; } public void add(Engine engine) throws BusinessException { diff --git a/vip-application/src/main/java/fr/insalyon/creatis/vip/application/server/business/WorkflowBusiness.java b/vip-application/src/main/java/fr/insalyon/creatis/vip/application/server/business/WorkflowBusiness.java index 704608dfe..b5d816385 100644 --- a/vip-application/src/main/java/fr/insalyon/creatis/vip/application/server/business/WorkflowBusiness.java +++ b/vip-application/src/main/java/fr/insalyon/creatis/vip/application/server/business/WorkflowBusiness.java @@ -168,12 +168,12 @@ public synchronized String launch(User user, List groups, Map resource = resourceBusiness.getUsableResources(user, appVersion); if (resource.isEmpty()) { - throw new BusinessException("There is no ressource available for the moment !"); + throw new BusinessException("There are no ressources available for the moment !"); } - Engine engine = engineBusiness.selectEngine(engineBusiness.getByResource(resource.get(0))); + Engine engine = engineBusiness.selectEngine(engineBusiness.getUsableEngines(resource.get(0))); if (engine == null) { - throw new BusinessException("There is no engine available for the moment !"); + throw new BusinessException("There are no engines available for the moment !"); } WorkflowExecutionBusiness executionBusiness = getWorkflowExecutionBusiness(engine.getEndpoint()); diff --git a/vip-core/src/main/java/fr/insalyon/creatis/vip/core/server/business/EmailBusiness.java b/vip-core/src/main/java/fr/insalyon/creatis/vip/core/server/business/EmailBusiness.java index e74d28871..b237d4218 100644 --- a/vip-core/src/main/java/fr/insalyon/creatis/vip/core/server/business/EmailBusiness.java +++ b/vip-core/src/main/java/fr/insalyon/creatis/vip/core/server/business/EmailBusiness.java @@ -28,9 +28,7 @@ public EmailBusiness(SMAClient smaClient, UserDAO userDAO) { this.userDAO = userDAO; } - public void sendEmail(String subject, String content, String[] recipients, - boolean direct, String username) throws BusinessException { - + public void sendEmail(String subject, String content, String[] recipients, boolean direct, String username) throws BusinessException { try { smaClient.sendEmail(subject, content, recipients, direct, username); } catch (SMAClientException ex) { diff --git a/vip-core/src/test/java/fr/insalyon/creatis/vip/core/integrationtest/UsersAndGroupsIT.java b/vip-core/src/test/java/fr/insalyon/creatis/vip/core/integrationtest/UsersAndGroupsIT.java index b155475e2..cffb7f99d 100644 --- a/vip-core/src/test/java/fr/insalyon/creatis/vip/core/integrationtest/UsersAndGroupsIT.java +++ b/vip-core/src/test/java/fr/insalyon/creatis/vip/core/integrationtest/UsersAndGroupsIT.java @@ -589,7 +589,6 @@ public void testRequestNewEmail() throws BusinessException { // Check update db Assertions.assertNotNull(configurationBusiness.getUser(emailUser2)); Assertions.assertEquals("newEmail@test.fr", configurationBusiness.getUser(emailUser2).getNextEmail(), "Incorrect user next email"); - } @@ -597,22 +596,16 @@ public void testRequestNewEmail() throws BusinessException { public void testSendContactEmail() throws BusinessException, DAOException { // Reset not to capture the calls to sendEmail in the Setup Mockito.reset(emailBusiness); - Mockito.doReturn(new String[]{"test-admin@test.com"}).when(emailBusiness).getAdministratorsEmails(); // Capture email content ArgumentCaptor emailContent = ArgumentCaptor.forClass(String.class); - // Capture email recipient - ArgumentCaptor emailRecipients = ArgumentCaptor.forClass(String[].class); configurationBusiness.sendContactMail(user1, "category", "subject", "comment"); - Mockito.verify(emailBusiness).sendEmail(Mockito.anyString(), emailContent.capture(), emailRecipients.capture(), Mockito.eq(true), Mockito.anyString()); + Mockito.verify(emailBusiness).sendEmailToAdmins(Mockito.anyString(), emailContent.capture(), Mockito.eq(true), Mockito.anyString()); // Check email content Assertions.assertTrue(emailContent.getValue().contains(user1.getFirstName()), "Incorrect user firstname"); Assertions.assertTrue(emailContent.getValue().contains(user1.getLastName()), "Incorrect user lastname"); - // Check recipient - Assertions.assertEquals(1, emailRecipients.getValue().length, "Incorrect length of recipients"); - Assertions.assertEquals(adminEmail, emailRecipients.getValue()[0], "Incorrect user recipient"); } diff --git a/vip-core/src/test/java/fr/insalyon/creatis/vip/core/integrationtest/database/SpringDatabaseIT.java b/vip-core/src/test/java/fr/insalyon/creatis/vip/core/integrationtest/database/SpringDatabaseIT.java index 108d1a036..9d4f649aa 100644 --- a/vip-core/src/test/java/fr/insalyon/creatis/vip/core/integrationtest/database/SpringDatabaseIT.java +++ b/vip-core/src/test/java/fr/insalyon/creatis/vip/core/integrationtest/database/SpringDatabaseIT.java @@ -115,7 +115,7 @@ private void testRollbackInTransaction( // but before, verify the user has well been deleted assertEquals(1, countUser.get()); throw exception; - }).when(emailBusiness).sendEmail(any(), any(), any(), anyBoolean(), any()); + }).when(emailBusiness).sendEmailToAdmins(any(), any(), anyBoolean(), any()); Exception exceptionCatched = null; try { diff --git a/vip-core/src/test/java/fr/insalyon/creatis/vip/core/integrationtest/database/SpringJndiIT.java b/vip-core/src/test/java/fr/insalyon/creatis/vip/core/integrationtest/database/SpringJndiIT.java index 2b09528b7..890fca494 100644 --- a/vip-core/src/test/java/fr/insalyon/creatis/vip/core/integrationtest/database/SpringJndiIT.java +++ b/vip-core/src/test/java/fr/insalyon/creatis/vip/core/integrationtest/database/SpringJndiIT.java @@ -169,7 +169,7 @@ private void testRollbackInTransaction( // but before, verify the user has well been deleted assertEquals(1, countUser.get()); throw exception; - }).when(emailBusiness).sendEmail(any(), any(), any(), anyBoolean(), any()); + }).when(emailBusiness).sendEmailToAdmins(any(), any(), anyBoolean(), any()); Exception exceptionCatched = null; try {