이메일 발송 테스트 코드

This commit is contained in:
Rinjae
2025-11-10 11:23:26 +09:00
parent 5b354cffb1
commit ccc4a80c99
3 changed files with 48 additions and 24 deletions
+9
View File
@@ -8,3 +8,12 @@ eapim-admin 에서 포함하여 테스트 이용시 느린 부팅 속도 떄문
- EAI 배치 연계
- 고객이메일발송 시스템 연계
## 테스트
### testEmailInServer
```bash
# git pull
GIT_SSH_COMMAND='ssh -i ~/.ssh/id_rsa-jenkins' git pull origin jenkins_with_weblogic
# test run
KJB_EAPIM_TEST_ENABLED=TRUE kjb-gradle.sh :eapim-admin-kjb:test --tests "com.eactive.ext.kjb.ums.test.UmsTest.testEmailInServer" -Psafedb
```
@@ -36,7 +36,6 @@ public class EmailJob {
private static final int BEFORE_SEND = 2;
private static final int SEND = 3;
private final Path tempFilePath;
private final Path eaiFilePath;
private final Path backupFilePath;
private final Path failedFilePath;
@@ -52,7 +51,6 @@ public class EmailJob {
this.prop = prop;
String filename = messageRequest.getServiceId() + "_" + DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(now);
this.tempFilePath = Paths.get(prop.getUmsEaiBatchSendDir(), filename + ".tmp");
this.eaiFilePath = Paths.get(prop.getUmsEaiBatchSendDir(), filename);
this.backupFilePath = Paths.get(prop.getUmsEaiBatchBackupDir(), filename);
this.failedFilePath = Paths.get(prop.getUmsEaiBatchBackupDir(), filename + ".failed");
@@ -192,7 +190,7 @@ public class EmailJob {
throw new IllegalStateException("Mail File exists for ID: " + messageRequest.getId());
}
File mailFile = tempFilePath.toFile();
File mailFile = eaiFilePath.toFile();
try {
boolean created = mailFile.createNewFile();
if (!created) {
@@ -218,22 +216,11 @@ public class EmailJob {
throw new RuntimeException(e);
}
try {
Files.write(tempFilePath, data);
Files.copy(tempFilePath, eaiFilePath);
Files.delete(tempFilePath);
Files.write(eaiFilePath, data);
log.debug("Wrote JSON to file: {}", eaiFilePath.toString());
} catch (IOException e) {
log.error("Cannot write JSON to file: {}", eaiFilePath.toString(), e);
throw new RuntimeException(e);
} finally {
// 임시 파일이 남아 있다면 오류 상황이므로 에러 경로로 이동
if (Files.exists(tempFilePath)) {
try {
Files.move(tempFilePath, Paths.get(prop.getUmsEaiBatchErrorDir(), tempFilePath.getFileName().toString()));
} catch (IOException e) {
log.warn("임시 파일 저장시 실패 하여 에러 경로로 옮기는 도중 에러 발생", e);
}
}
}
}
@@ -96,15 +96,43 @@ public class UmsTest {
throw new RuntimeException(e);
}
// CompletableFuture<Boolean> future = service.sendEmail(messageRequest, (result, ex) -> {
// if (ex != null) {
// log.error("failed", ex);
// } else {
// log.info("result: {}", result);
// }
// });
//
// future.join();
log.info("done");
}
@Test
public void testEmailInServer() {
Assumptions.assumeTrue(
"true".equalsIgnoreCase(System.getenv("KJB_EAPIM_TEST_ENABLED")),
"OS 환경변수 내 KJB_EAPIM_TEST_ENABLED=TRUE 설정되어 있어야 동작함");
prop.setEaiBatchUrl("http://172.31.32.111:10230/BATAppWeb/EaiBatCall");
prop.setUmsEaiBatchSendDir("/Data/eapim/portal/sendmail/snd");
prop.setUmsEaiBatchBackupDir("/Data/eapim/portal/sendmail/bak");
prop.setUmsEaiBatchErrorDir("/Data/eapim/portal/sendmail/ error");
prop.setUmsEaiBatchInterfaceId("UAGFF00001UIE");
System.getProperties().keySet().forEach(key -> {
log.info("{}: {}", key, System.getProperty((String) key));
});
KjbEmailSendModule service = KjbEmailSendModule.getInstance(prop, null);
MessageRequest messageRequest = new MessageRequest();
messageRequest.setId(UUID.randomUUID().toString());
messageRequest.setMessageCode(MessageCode.USER_VERIFICATION_EMAIL);
messageRequest.setEmail("dearmai@dearmai.net");
messageRequest.setUsername("김광은");
messageRequest.setSubject("제목 - test");
messageRequest.setMessage("{\"ATHN_NO\": \"543216\"}");
messageRequest.setServiceId("FM_APIM001");
log.info("MessageRequest - {}", messageRequest);
try {
service.sendEmail(messageRequest);
} catch (KjbEaiBatchException e) {
throw new RuntimeException(e);
}
log.info("done");
}