From 883e4ce67a4b16abc6cf1d800bdd11843253ff01 Mon Sep 17 00:00:00 2001 From: Yves Peter Date: Thu, 14 Dec 2023 19:17:44 +0100 Subject: [PATCH] fix error when sending mail for archived deployment, fix sending mail on predeploy failure --- .../deploy/boundary/DeploymentBoundary.java | 15 +-- .../DeploymentNotificationService.java | 106 +++++++----------- .../deploy/entity/DeploymentEntity.java | 8 +- ...orDomainServiceWithAppServerRelations.java | 24 ++-- .../control/extracted/GenerationModus.java | 4 +- .../utils/notification/MailService.java | 19 ++-- .../notification/NotificationService.java | 18 +-- .../DeploymentNotificationServiceTest.java | 17 +-- .../notification/mail/MailServiceTest.java | 14 +-- .../mail/NotificationServiceTest.java | 6 +- 10 files changed, 103 insertions(+), 128 deletions(-) diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/boundary/DeploymentBoundary.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/boundary/DeploymentBoundary.java index 58df88d4c..bbeba9914 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/boundary/DeploymentBoundary.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/boundary/DeploymentBoundary.java @@ -1024,17 +1024,17 @@ private void updateDeploymentStatusMessage(final List deployme * @param resourceId - the ApplicationServe used for deployment * @param generationResult * @param reason - the DeploymentFailureReason (if any) + * @return - the updated deployment */ @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public DeploymentEntity updateDeploymentInfo(GenerationModus generationModus, final Integer deploymentId, final String errorMessage, final Integer resourceId, final GenerationResult generationResult, DeploymentFailureReason reason) { // don't lock a deployment for predeployment as there is no need to update the deployment. - if (GenerationModus.PREDEPLOY.equals(generationModus) && errorMessage == null) { + if (GenerationModus.PREDEPLOY == generationModus && errorMessage == null) { log.fine("Predeploy script finished at " + new Date()); return em.find(DeploymentEntity.class, deploymentId); } - DeploymentEntity deployment = em.find(DeploymentEntity.class, deploymentId, - LockModeType.PESSIMISTIC_FORCE_INCREMENT); + DeploymentEntity deployment = em.find(DeploymentEntity.class, deploymentId, LockModeType.PESSIMISTIC_FORCE_INCREMENT); // set as used for deployment if (resourceId != null) { @@ -1042,7 +1042,7 @@ public DeploymentEntity updateDeploymentInfo(GenerationModus generationModus, fi deployment.setResource(as); } - if (GenerationModus.DEPLOY.equals(generationModus)) { + if (GenerationModus.DEPLOY == generationModus) { if (errorMessage == null) { String nodeInfo = getNodeInfoForDeployment(generationResult); deployment.appendStateMessage("Successfully deployed at " + new Date() + "\n" + nodeInfo); @@ -1055,7 +1055,7 @@ public DeploymentEntity updateDeploymentInfo(GenerationModus generationModus, fi } deployment.setReason(reason); } - } else if (GenerationModus.PREDEPLOY.equals(generationModus)) { + } else if (GenerationModus.PREDEPLOY == generationModus) { deployment.appendStateMessage(errorMessage); deployment.setDeploymentState(DeploymentState.failed); if (reason == null) { @@ -1126,7 +1126,6 @@ public void createShakedownTestForTrackinIdOfDeployment(Integer trackingId) { * single email notification if all of them are executed (independent of their success state). */ public void sendOneNotificationForTrackingIdOfDeployment(Integer trackingId) { - // hole alle deployments mit derselben trackingId List deploymentsWithSameTrackingId = getDeplyomentsWithSameTrackingId(trackingId); if (isAllDeploymentsWithSameTrackingIdExecuted(deploymentsWithSameTrackingId)) { @@ -1136,8 +1135,7 @@ public void sendOneNotificationForTrackingIdOfDeployment(Integer trackingId) { private boolean isAllDeploymentsWithSameTrackingIdExecuted(List deploymentsWithSameTrackingId) { for (final DeploymentEntity deploymentEntity : deploymentsWithSameTrackingId) { - // not executed and not failed, failed and executed Deployments are complete - if (!deploymentEntity.isExecuted() && !DeploymentState.failed.equals(deploymentEntity.getDeploymentState())) { + if (!deploymentEntity.isExecuted()) { return false; } } @@ -1160,7 +1158,6 @@ private List getDeplyomentsWithSameTrackingId(Integer tracking * @param deployments */ private void sendsNotificationAndUpdatedStatusOfDeployments(final List deployments) { - if (deployments != null && !deployments.isEmpty()) { String message = deploymentNotificationService.createAndSendMailForDeplyoments(deployments); updateDeploymentStatusMessage(deployments, message); diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/control/DeploymentNotificationService.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/control/DeploymentNotificationService.java index 1069a4ab9..331898a82 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/control/DeploymentNotificationService.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/control/DeploymentNotificationService.java @@ -21,12 +21,9 @@ package ch.puzzle.itc.mobiliar.business.deploy.control; import ch.puzzle.itc.mobiliar.business.generator.control.extracted.ResourceDependencyResolverService; -import ch.puzzle.itc.mobiliar.business.releasing.control.ReleaseMgmtService; import ch.puzzle.itc.mobiliar.business.usersettings.control.UserSettingsService; import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.ConsumedResourceRelationEntity; import ch.puzzle.itc.mobiliar.business.deploy.entity.DeploymentEntity; -import ch.puzzle.itc.mobiliar.business.releasing.entity.ReleaseEntity; -import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; import ch.puzzle.itc.mobiliar.business.utils.notification.NotificationService; import ch.puzzle.itc.mobiliar.common.util.ConfigurationService; import ch.puzzle.itc.mobiliar.common.util.ConfigKey; @@ -55,15 +52,12 @@ public class DeploymentNotificationService { @Inject private ResourceDependencyResolverService resourceDependencyResolverService; - @Inject - private ReleaseMgmtService releaseMgmtService; - @Inject private Logger log; /** * Creates a notification email for deployment executions and sends them to - * the given receipients + * the given recipients * * @param deployments * - the executed deployments @@ -71,28 +65,22 @@ public class DeploymentNotificationService { * @throws AddressException * @throws MessagingException */ - public String createAndSendMailForDeplyoments( - final List deployments) { + public String createAndSendMailForDeplyoments(final List deployments) { String message = null; - // do nothing if no deployment is available - if (deployments != null && !deployments.isEmpty()) { - String subjectMessage = "AMW-Deploy for tracking id: " - + deployments.get(0).getTrackingId(); - - try { - Address[] emailReceipients = getAllReceipients(deployments); - - if (notificationService.createAndSendMail(subjectMessage, - getMessageContentForDeployments(deployments), - emailReceipients)) { - message = getSuccessfulSendMailToReceipientMessage(emailReceipients); - } - } catch (MessagingException e) { - message = getFailureSendMailMessage(e.getMessage()); - log.log(Level.WARNING, "Deployment notification (" - + subjectMessage + ") could not be sent", e); + if (deployments == null || deployments.isEmpty()) { + return message; + } + String subjectMessage = "Liima-Deploy for tracking id: " + deployments.get(0).getTrackingId(); + + try { + Address[] emailRecipients = getAllRecipients(deployments); + if (notificationService.createAndSendMail(subjectMessage, getMessageContentForDeployments(deployments), emailRecipients)) { + message = getSuccessfulSendMailToRecipientMessage(emailRecipients); } + } catch (MessagingException e) { + message = getFailureSendMailMessage(e.getMessage()); + log.log(Level.WARNING, "Deployment notification (" + subjectMessage + ") could not be sent", e); } return message; @@ -105,8 +93,7 @@ public String createAndSendMailForDeplyoments( * - the deployments for which the email shall be generated. * @return the e-mail content to be sent */ - private String getMessageContentForDeployments( - final List deployments) { + private String getMessageContentForDeployments(final List deployments) { final StringBuffer message = new StringBuffer(); for (final DeploymentEntity deployment : deployments) { message.append("Application server: ").append(deployment.getResourceGroup().getName()); @@ -140,60 +127,47 @@ private String getApplicationWithVersionsString(DeploymentEntity deploymentEntit } /** - * Extracts the receipients interested in getting notifications about the + * Extracts the recipients interested in getting notifications about the * deployment execution. * * @param deployments * @return - an array of e-mail addresses * @throws AddressException */ - private Address[] getAllReceipients(final List deployments) + private Address[] getAllRecipients(final List deployments) throws AddressException { - final Set emailReceipients = new HashSet(); + final Set emailRecipients = new HashSet(); final Set groupIds = new HashSet(); for (final DeploymentEntity deployment : deployments) { if (deployment.isSendEmail()) { - emailReceipients.add(deployment.getDeploymentRequestUser()); + emailRecipients.add(deployment.getDeploymentRequestUser()); } if (deployment.isSendEmailConfirmation()) { - emailReceipients - .add(deployment.getDeploymentConfirmationUser()); + emailRecipients.add(deployment.getDeploymentConfirmationUser()); } - ReleaseEntity release = deployment.getRelease(); - if(release == null){ - // get Past Release - release = releaseMgmtService.getDefaultRelease(); - + // skip notification of favorites if deployment is preserved + if (deployment.isPreserved()) { + continue; + } + groupIds.add(deployment.getResourceGroup().getId()); + if (deployment.getResource().getConsumedMasterRelations() == null) { + continue; } - // Find the resourceGroup ids for the deployment - final ResourceEntity resource = resourceDependencyResolverService.getResourceEntityForRelease(deployment.getResourceGroup(), - release); - if (resource != null) { - groupIds.add(resource.getResourceGroup().getId()); - if (resource.getConsumedMasterRelations() != null) { - for (final ConsumedResourceRelationEntity rel : resourceDependencyResolverService - .getConsumedMasterRelationsForRelease(resource, - deployment.getRelease())) { - groupIds.add(rel.getSlaveResource().getResourceGroup().getId()); - } - } + for (final ConsumedResourceRelationEntity rel : resourceDependencyResolverService.getConsumedMasterRelationsForRelease(deployment.getResource(), deployment.getRelease())) { + groupIds.add(rel.getSlaveResource().getResourceGroup().getId()); } } - List userNames = userSettingsService - .getRegisteredUsernamesForResourcesIds(groupIds); - emailReceipients.addAll(userNames); + emailRecipients.addAll(userSettingsService.getRegisteredUsernamesForResourcesIds(groupIds)); - final Address[] to = new InternetAddress[emailReceipients.size()]; + + final Address[] to = new InternetAddress[emailRecipients.size()]; int i = 0; - for (final String user : emailReceipients) { - // TODO make configurable - to[i++] = new InternetAddress(user + "@" - + ConfigurationService.getProperty(ConfigKey.MAIL_DOMAIN)); + for (final String user : emailRecipients) { + to[i++] = new InternetAddress(user + "@" + ConfigurationService.getProperty(ConfigKey.MAIL_DOMAIN)); } - return to; } @@ -211,15 +185,15 @@ private String getFailureSendMailMessage(final String e) { /** * Generates a success message for email sending process. * - * @param emailReceipients - * - the receipients to which the email was successfully sent + * @param emailRecipients + * - the recipients to which the email was successfully sent * @return */ - private String getSuccessfulSendMailToReceipientMessage( - final Address[] emailReceipients) { + private String getSuccessfulSendMailToRecipientMessage( + final Address[] emailRecipients) { final StringBuffer result = new StringBuffer( - "Notification email sent to following receipients: \n"); - for (final Address address : emailReceipients) { + "Notification email sent to following recipients: \n"); + for (final Address address : emailRecipients) { result.append(address.toString()); result.append("\n"); } diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/entity/DeploymentEntity.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/entity/DeploymentEntity.java index 5cecd5371..4afadb443 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/entity/DeploymentEntity.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/entity/DeploymentEntity.java @@ -28,25 +28,31 @@ import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceGroupEntity; import ch.puzzle.itc.mobiliar.business.shakedown.entity.ShakedownTestEntity; import ch.puzzle.itc.mobiliar.common.exception.DeploymentStateException; + import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; + import lombok.Getter; import lombok.Setter; - +import lombok.ToString; import lombok.SneakyThrows; + import org.hibernate.annotations.BatchSize; import javax.persistence.*; + import java.io.Serializable; import java.io.StringReader; import java.util.*; + /** * Entity implementation class for Entity: Deployment */ @Entity +@ToString @Table(name = "TAMW_deployment") @NamedQuery(name = DeploymentEntity.LAST_SUCCESSFUL_DEPLOYMENT, query = "select d from DeploymentEntity d where d.deploymentDate=(select max(t.deploymentDate) from DeploymentEntity t where t.context=:context and t.resourceGroup=:resourceGroup and t.release=:release and t.deploymentState=:deploymentState)") public class DeploymentEntity implements Serializable { diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/GeneratorDomainServiceWithAppServerRelations.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/GeneratorDomainServiceWithAppServerRelations.java index db42fd40c..704ba79fe 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/GeneratorDomainServiceWithAppServerRelations.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/GeneratorDomainServiceWithAppServerRelations.java @@ -46,6 +46,7 @@ import ch.puzzle.itc.mobiliar.common.exception.GeneratorException.MISSING; import ch.puzzle.itc.mobiliar.common.exception.ResourceNotFoundException; import ch.puzzle.itc.mobiliar.common.util.DefaultResourceTypeDefinition; + import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; @@ -425,24 +426,18 @@ public EnvironmentGenerationResult generateApplicationServerConfigurationForEnvi */ private void handleException(GenerationModus generationModus, final Exception e, final DeploymentEntity deployment) { - log.log(Level.WARNING, "Deployment fehlgeschlagen", e); - String message = generationModus.getAction() + " failure at " + new Date() + ". Reason: " + e - .getMessage() + "\n"; + log.log(Level.WARNING, String.format("Deployment %d failed ",deployment.getId()), e); + String message = generationModus.getAction() + " failure at " + new Date() + ". Reason: " + e.getMessage() + "\n"; DeploymentFailureReason reason = (e instanceof GeneratorException && ((GeneratorException) e).getMissingObject().equals(MISSING.NODE)) ? DeploymentFailureReason.NODE_MISSING : null; - deploymentBoundary.updateDeploymentInfo(generationModus, deployment.getId(), message, - deployment.getResource() != null ? deployment.getResource() - .getId() : null, null, reason); - if (generationModus.isSendNotificationOnErrorGenerationModus()) { - deploymentBoundary.sendOneNotificationForTrackingIdOfDeployment(deployment.getTrackingId()); - } + deploymentBoundary.updateDeploymentInfoAndSendNotification(generationModus, deployment.getId(), message, + deployment.getResource() != null ? deployment.getResource().getId() : null, null, reason); } /** * Handle exceptions in the preparation of the deployment. */ - private void handleExceptions(GenerationModus generationModus, GenerationResult generationResult, - final DeploymentEntity deployment) { + private void handleExceptions(GenerationModus generationModus, GenerationResult generationResult, DeploymentEntity deployment) { StringBuilder message = new StringBuilder(generationModus.getAction() + " failure at " + new Date() + ". Reasons: "); if (generationResult.hasErrors()) { @@ -457,12 +452,9 @@ private void handleExceptions(GenerationModus generationModus, GenerationResult } } - log.log(Level.WARNING, "Deployment fehlgeschlagen \n" + message.toString()); - deploymentBoundary.updateDeploymentInfo(generationModus, deployment.getId(), message.toString(), + log.log(Level.WARNING, String.format("Deployment %d failed: %s", deployment.getId(), message)); + deploymentBoundary.updateDeploymentInfoAndSendNotification(generationModus, deployment.getId(), message.toString(), deployment.getResource() != null ? deployment.getResource().getId() : null, generationResult, reason); - if (generationModus.isSendNotificationOnErrorGenerationModus()) { - deploymentBoundary.sendOneNotificationForTrackingIdOfDeployment(deployment.getTrackingId()); - } } /** diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/GenerationModus.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/GenerationModus.java index b379877ef..6d56d0f22 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/GenerationModus.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/GenerationModus.java @@ -71,7 +71,7 @@ public void setAction(String action) { * @return */ public boolean isSendNotificationOnErrorGenerationModus(){ - return (DEPLOY.equals(this) || PREDEPLOY.equals(this)); + return DEPLOY == this || PREDEPLOY == this; } /** @@ -79,7 +79,7 @@ public boolean isSendNotificationOnErrorGenerationModus(){ * @return */ public boolean isSendNotificationOnSuccessGenerationModus(){ - return (DEPLOY.equals(this)); + return DEPLOY == this; } } diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/utils/notification/MailService.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/utils/notification/MailService.java index 360f8434c..a90d514b1 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/utils/notification/MailService.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/utils/notification/MailService.java @@ -20,11 +20,16 @@ package ch.puzzle.itc.mobiliar.business.utils.notification; +import java.util.logging.Logger; + import javax.annotation.Resource; import javax.inject.Inject; -import javax.mail.*; +import javax.mail.Address; +import javax.mail.Message; +import javax.mail.MessagingException; +import javax.mail.Session; +import javax.mail.Transport; import javax.mail.internet.MimeMessage; -import java.util.logging.Logger; public class MailService { @@ -36,20 +41,20 @@ public class MailService { @Inject private Logger log; - public boolean createMessageAndSend(String subject, String content, Address[] emailReceipients) throws MessagingException{ + public boolean createMessageAndSend(String subject, String content, Address[] emailRecipients) throws MessagingException{ if (mailSession == null) { String addresses = ""; - if(emailReceipients != null) { - for (Address address : emailReceipients) { + if(emailRecipients != null) { + for (Address address : emailRecipients) { addresses += address.toString() + ", "; } } - log.warning("Mail session not available, unable to send Mail(subject: " +subject+", content: "+content+" ) to Receipients: " + addresses); + log.warning("Mail session not available, unable to send Mail(subject: " +subject+", content: "+content+" ) to Recipients: " + addresses); return false; } final MimeMessage mail = new MimeMessage(mailSession); - mail.setRecipients(Message.RecipientType.TO, emailReceipients); + mail.setRecipients(Message.RecipientType.TO, emailRecipients); mail.setSubject(subject); mail.setContent(content, CONTENT_TYPE); mail.setSentDate(new java.util.Date()); diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/utils/notification/NotificationService.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/utils/notification/NotificationService.java index 67eee0ecf..d773938e9 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/utils/notification/NotificationService.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/utils/notification/NotificationService.java @@ -20,14 +20,14 @@ package ch.puzzle.itc.mobiliar.business.utils.notification; -import ch.puzzle.itc.mobiliar.common.util.ConfigurationService; -import ch.puzzle.itc.mobiliar.common.util.ConfigKey; - import javax.ejb.Stateless; import javax.inject.Inject; import javax.mail.Address; import javax.mail.MessagingException; +import ch.puzzle.itc.mobiliar.common.util.ConfigKey; +import ch.puzzle.itc.mobiliar.common.util.ConfigurationService; + @Stateless public class NotificationService { @@ -35,19 +35,19 @@ public class NotificationService { private MailService mailService; /** - * creates and sends an Email to the given emailReceipients + * creates and sends an Email to the given emailRecipients * * @param subject * @param content - * @param emailReceipients + * @param emailRecipients * @return * @throws MessagingException */ - public boolean createAndSendMail(String subject, String content, Address[] emailReceipients) throws MessagingException{ + public boolean createAndSendMail(String subject, String content, Address[] emailRecipients) throws MessagingException{ boolean deliverEmails = ConfigurationService.getPropertyAsBoolean(ConfigKey.DELIVER_MAIL, true); - // deliverEmails is active and emailReceipients are available - if (deliverEmails && emailReceipients != null && emailReceipients.length > 0) { - return mailService.createMessageAndSend(subject, content, emailReceipients); + // deliverEmails is active and emailRecipients are available + if (deliverEmails && emailRecipients != null && emailRecipients.length > 0) { + return mailService.createMessageAndSend(subject, content, emailRecipients); } return false; } diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/deploy/control/DeploymentNotificationServiceTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/deploy/control/DeploymentNotificationServiceTest.java index 794f472a4..60b34fddf 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/deploy/control/DeploymentNotificationServiceTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/deploy/control/DeploymentNotificationServiceTest.java @@ -80,9 +80,6 @@ public void setUp(){ MockitoAnnotations.openMocks(this); applicationServer = ResourceFactory.createNewResource("appServer"); - when(dependencyResolverService.getResourceEntityForRelease((ResourceGroupEntity) any(), (ReleaseEntity) any())).thenReturn( - applicationServer); - context = new ContextEntity(); context.setName("dev"); @@ -119,6 +116,7 @@ public void createAndSendMailForDeplyoments_oneDeployment_noAddress_sending_ok() DeploymentEntity deployment = new DeploymentEntity(); deployment.setTrackingId(Integer.valueOf(12)); deployment.setDeploymentState(DeploymentState.success); + deployment.setResource(applicationServer); deployment.setResourceGroup(applicationServer.getResourceGroup()); deployment.setContext(context); deployments.add(deployment); @@ -130,7 +128,7 @@ public void createAndSendMailForDeplyoments_oneDeployment_noAddress_sending_ok() // then assertNotNull(result); - assertEquals("Notification email sent to following receipients: \n", result); + assertEquals("Notification email sent to following recipients: \n", result); } @Test @@ -141,6 +139,7 @@ public void createAndSendMailForDeplyoments_oneDeployment_noAddress_sending_nok( DeploymentEntity deployment = new DeploymentEntity(); deployment.setTrackingId(Integer.valueOf(12)); deployment.setDeploymentState(DeploymentState.success); + deployment.setResource(applicationServer); deployment.setResourceGroup(applicationServer.getResourceGroup()); deployment.setContext(context); deployments.add(deployment); @@ -165,6 +164,7 @@ public void createAndSendMailForDeplyoments_oneDeployment_noAddress_sending_nok_ DeploymentEntity deployment = new DeploymentEntity(); deployment.setTrackingId(Integer.valueOf(12)); deployment.setDeploymentState(DeploymentState.success); + deployment.setResource(applicationServer); deployment.setResourceGroup(applicationServer.getResourceGroup()); deployment.setContext(context); deployment.setRelease(defaultRelease); @@ -173,7 +173,6 @@ public void createAndSendMailForDeplyoments_oneDeployment_noAddress_sending_nok_ when(notificationService.createAndSendMail(anyString(), anyString(), any(Address[].class))).thenReturn(false); - // when String result = deploymentNotificationService.createAndSendMailForDeplyoments(deployments); @@ -191,6 +190,7 @@ public void createAndSendMailForDeplyoments_oneDeployment_noAddress_sending_Exce DeploymentEntity deployment = new DeploymentEntity(); deployment.setTrackingId(Integer.valueOf(12)); deployment.setDeploymentState(DeploymentState.success); + deployment.setResource(applicationServer); deployment.setResourceGroup(applicationServer.getResourceGroup()); deployment.setContext(context); deployments.add(deployment); @@ -208,13 +208,14 @@ public void createAndSendMailForDeplyoments_oneDeployment_noAddress_sending_Exce @Test - public void createAndSendMailForDeplyoments_oneDeployment_noAddress_sending_Receipients() throws MessagingException { + public void createAndSendMailForDeplyoments_oneDeployment_noAddress_sending_Recipients() throws MessagingException { // given ArrayList deployments = new ArrayList(); DeploymentEntity deployment = new DeploymentEntity(); deployment.setTrackingId(Integer.valueOf(12)); deployment.setDeploymentState(DeploymentState.success); + deployment.setResource(applicationServer); deployment.setResourceGroup(applicationServer.getResourceGroup()); deployment.setApplicationsWithVersion(new ArrayList()); deployment.setContext(context); @@ -222,7 +223,7 @@ public void createAndSendMailForDeplyoments_oneDeployment_noAddress_sending_Rece when(notificationService.createAndSendMail(anyString(), anyString(), any(Address[].class))).thenReturn(true); when(releaseMgmtService.getDefaultRelease()).thenReturn(defaultRelease); - List value = new ArrayList(); + List value = new ArrayList<>(); value.add("testuser1"); when(userSettingsService.getRegisteredUsernamesForResourcesIds(any(Set.class))).thenReturn(value ); @@ -231,7 +232,7 @@ public void createAndSendMailForDeplyoments_oneDeployment_noAddress_sending_Rece // then assertNotNull(result); - assertEquals("Notification email sent to following receipients: \ntestuser1@null\n", result); + assertEquals("Notification email sent to following recipients: \ntestuser1@null\n", result); } } diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/notification/mail/MailServiceTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/notification/mail/MailServiceTest.java index cc010b395..ba8aa0ca0 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/notification/mail/MailServiceTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/notification/mail/MailServiceTest.java @@ -20,22 +20,22 @@ package ch.puzzle.itc.mobiliar.business.utils.notification.mail; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - import java.util.logging.Logger; import javax.mail.Address; import javax.mail.MessagingException; import javax.mail.internet.InternetAddress; -import ch.puzzle.itc.mobiliar.business.utils.notification.MailService; import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import org.mockito.MockitoAnnotations; +import ch.puzzle.itc.mobiliar.business.utils.notification.MailService; + public class MailServiceTest { @InjectMocks @@ -59,7 +59,7 @@ public void test_createMessageAndSend_logging_null() throws MessagingException { mailService.createMessageAndSend("subject", "content", null); // then - verify(log, times(1)).warning("Mail session not available, unable to send Mail(subject: subject, content: content ) to Receipients: "); + verify(log, times(1)).warning("Mail session not available, unable to send Mail(subject: subject, content: content ) to Recipients: "); } @Test @@ -72,7 +72,7 @@ public void test_createMessageAndSend_logging_Empty() throws MessagingException mailService.createMessageAndSend("subject", "content", to); // then - verify(log, times(1)).warning("Mail session not available, unable to send Mail(subject: subject, content: content ) to Receipients: "); + verify(log, times(1)).warning("Mail session not available, unable to send Mail(subject: subject, content: content ) to Recipients: "); } @Test @@ -86,7 +86,7 @@ public void test_createMessageAndSend_logging() throws MessagingException { mailService.createMessageAndSend("subject", "content", to); // then - verify(log, times(1)).warning("Mail session not available, unable to send Mail(subject: subject, content: content ) to Receipients: test@test.ch, "); + verify(log, times(1)).warning("Mail session not available, unable to send Mail(subject: subject, content: content ) to Recipients: test@test.ch, "); } } diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/notification/mail/NotificationServiceTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/notification/mail/NotificationServiceTest.java index 349497e1b..1405f3fb5 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/notification/mail/NotificationServiceTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/notification/mail/NotificationServiceTest.java @@ -59,7 +59,7 @@ public void setUp(){ @Test - public void test_createAndSendMail_noEmailReceipients() throws MessagingException { + public void test_createAndSendMail_noEmailRecipients() throws MessagingException { // given // when @@ -70,7 +70,7 @@ public void test_createAndSendMail_noEmailReceipients() throws MessagingExceptio } @Test - public void test_createAndSendMail_noEmailReceipients_emptyList() throws MessagingException { + public void test_createAndSendMail_noEmailRecipients_emptyList() throws MessagingException { // given Address[] to = new InternetAddress[0]; // when @@ -81,7 +81,7 @@ public void test_createAndSendMail_noEmailReceipients_emptyList() throws Messagi } @Test - public void test_createAndSendMail_noEmailReceipients_DeliverEmailsFalse() throws MessagingException { + public void test_createAndSendMail_noEmailRecipients_DeliverEmailsFalse() throws MessagingException { // given Properties props = System.getProperties(); props.setProperty(ConfigKey.DELIVER_MAIL.getValue(), "false");