Skip to content

Commit

Permalink
tests fixes and workflowbusiness
Browse files Browse the repository at this point in the history
  • Loading branch information
ethaaalpha committed Dec 11, 2024
1 parent be44652 commit 3028dfa
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ public synchronized String launch(User user, List<String> groups, Map<String, St

List<Resource> 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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,30 +589,23 @@ public void testRequestNewEmail() throws BusinessException {
// Check update db
Assertions.assertNotNull(configurationBusiness.getUser(emailUser2));
Assertions.assertEquals("[email protected]", configurationBusiness.getUser(emailUser2).getNextEmail(), "Incorrect user next email");

}


@Test
public void testSendContactEmail() throws BusinessException, DAOException {
// Reset not to capture the calls to sendEmail in the Setup
Mockito.reset(emailBusiness);
Mockito.doReturn(new String[]{"[email protected]"}).when(emailBusiness).getAdministratorsEmails();

// Capture email content
ArgumentCaptor<String> emailContent = ArgumentCaptor.forClass(String.class);
// Capture email recipient
ArgumentCaptor<String[]> 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");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3028dfa

Please sign in to comment.