Skip to content

Commit

Permalink
Merge pull request #24 from transcom/B-20564-Email-For-Malfomred-TAC-…
Browse files Browse the repository at this point in the history
…LOA-Data

Using spring constructor injection for EmailService
  • Loading branch information
TevinAdams authored Aug 12, 2024
2 parents 81dd466 + 7aeef1e commit 522b882
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>com.milmove.trdmlambda</groupId>
<artifactId>trdm-lambda</artifactId>
<version>1.0.3.14</version>
<version>1.0.3.15</version>
<name>trdm java spring interface</name>
<description>Project for deploying a Java TRDM interfacer for TGET data.</description>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ public class EmailService {
private String subject;
private String bodyHTML;

public EmailService() throws URISyntaxException {
public EmailService(SecretFetcher secretFetcher) throws URISyntaxException {
logger.info("starting initialization of Email Service");
this.sender = secretFetcher.getSecret("ses_sender_email");
this.recipient = secretFetcher.getSecret("ses_recipient");
this.sesClient = SesClient.builder()
.region(Region.of("us-gov-west-1"))
.build();
Expand Down Expand Up @@ -94,9 +96,6 @@ public void sendMalformedLOADataEmail(ArrayList<String> loaSysIds) {
}

public void send(SesClient client) throws MessagingException {
SecretFetcher secretFetcher = new SecretFetcher();
this.sender = secretFetcher.getSecret("ses_sender_email");
this.recipient = secretFetcher.getSecret("ses_recipient");

logger.info("start of EmailService.send()");
Destination destination = Destination.builder()
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/milmove/trdmlambda/milmove/util/Trdm.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class Trdm {
private final DatabaseService databaseService;
private final TransportationAccountingCodeParser tacParser;
private final LineOfAccountingParser loaParser;
private final EmailService emailService;

private final Connection rdsConnection;
private static final Set<String> allowedTableNames = Set.of("transportation_accounting_codes",
Expand All @@ -62,12 +63,14 @@ public class Trdm {
public Trdm(LastTableUpdateService lastTableUpdateService,
GetTableService getTableService,
DatabaseService databaseService,
EmailService emailService,
TransportationAccountingCodeParser tacParser,
LineOfAccountingParser loaParser) throws SQLException {

this.lastTableUpdateService = lastTableUpdateService;
this.getTableService = getTableService;
this.databaseService = databaseService;
this.emailService = emailService;
this.tacParser = tacParser;
this.loaParser = loaParser;

Expand Down Expand Up @@ -182,9 +185,8 @@ public void UpdateTGETData(XMLGregorianCalendar ourLastUpdate, String trdmTable,
case "transportation_accounting_codes":
// Parse the response attachment to get the codes
logger.info("parsing response back from TRDM getTable");
EmailService malformedTACDataEmailService = new EmailService();
List<TransportationAccountingCode> codes = tacParser.parse(getTableResponse.getAttachment(),
oneWeekLater, malformedTACDataEmailService);
oneWeekLater, emailService);

// Generate list of TACs that needs to be updated. If TAC is in currentTacs then the
// TAC will be in updateTacs list because the TAC already exist
Expand All @@ -205,9 +207,8 @@ public void UpdateTGETData(XMLGregorianCalendar ourLastUpdate, String trdmTable,
case "lines_of_accounting":
// Parse the response attachment to get the loas
logger.info("parsing response back from TRDM getTable");
EmailService malformedLOADataEmailService = new EmailService();
List<LineOfAccounting> loas = loaParser.parse(getTableResponse.getAttachment(),
oneWeekLater, malformedLOADataEmailService);
oneWeekLater, emailService);

// Generate list of loas that needs to be updated. If loas are in curentLoas
// then the loa will be in updateLoas list because the loa already exist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,33 @@

import jakarta.mail.MessagingException;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyList;

import org.apache.cxf.common.i18n.Exception;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

import com.milmove.trdmlambda.milmove.model.TransportationAccountingCode;

import java.net.URISyntaxException;
import java.util.ArrayList;

@ExtendWith(MockitoExtension.class)
public class EmailServiceTest {

@Mock
private SecretFetcher secretFetcher;

@InjectMocks
private EmailService emailService;

@Test // Test sendMalformedTACDataEmailTest()
void sendMalformedTACDataEmailTest() throws MessagingException, URISyntaxException {

EmailService emailService = new EmailService();
EmailService spyEmailService = spy(emailService);
ArrayList<String> codes = new ArrayList<String>();

Expand All @@ -45,7 +46,6 @@ void sendMalformedTACDataEmailTest() throws MessagingException, URISyntaxExcepti
@Test // Test sendMalformedLOADataEmailTest()
void sendMalformedLOADataEmailTest() throws MessagingException, URISyntaxException {

EmailService emailService = new EmailService();
EmailService spyEmailService = spy(emailService);
ArrayList<String> codes = new ArrayList<String>();
codes.add("TEST");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.milmove.trdmlambda.milmove.model.gettable.GetTableRequest;
import com.milmove.trdmlambda.milmove.model.gettable.GetTableResponse;
import com.milmove.trdmlambda.milmove.service.DatabaseService;
import com.milmove.trdmlambda.milmove.service.EmailService;
import com.milmove.trdmlambda.milmove.service.GetTableService;
import com.milmove.trdmlambda.milmove.service.LastTableUpdateService;
import com.milmove.trdmlambda.milmove.model.LineOfAccounting;
Expand All @@ -43,6 +44,8 @@
@ExtendWith(MockitoExtension.class)
class TrdmTest {

@Mock
private EmailService emailService;
@Mock
private LastTableUpdateService lastTableUpdateService;
@Mock
Expand Down

0 comments on commit 522b882

Please sign in to comment.