이메일 발송 테스트 코드
This commit is contained in:
@@ -8,3 +8,12 @@ eapim-admin 에서 포함하여 테스트 이용시 느린 부팅 속도 떄문
|
|||||||
- EAI 배치 연계
|
- 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 BEFORE_SEND = 2;
|
||||||
private static final int SEND = 3;
|
private static final int SEND = 3;
|
||||||
|
|
||||||
private final Path tempFilePath;
|
|
||||||
private final Path eaiFilePath;
|
private final Path eaiFilePath;
|
||||||
private final Path backupFilePath;
|
private final Path backupFilePath;
|
||||||
private final Path failedFilePath;
|
private final Path failedFilePath;
|
||||||
@@ -52,7 +51,6 @@ public class EmailJob {
|
|||||||
this.prop = prop;
|
this.prop = prop;
|
||||||
|
|
||||||
String filename = messageRequest.getServiceId() + "_" + DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(now);
|
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.eaiFilePath = Paths.get(prop.getUmsEaiBatchSendDir(), filename);
|
||||||
this.backupFilePath = Paths.get(prop.getUmsEaiBatchBackupDir(), filename);
|
this.backupFilePath = Paths.get(prop.getUmsEaiBatchBackupDir(), filename);
|
||||||
this.failedFilePath = Paths.get(prop.getUmsEaiBatchBackupDir(), filename + ".failed");
|
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());
|
throw new IllegalStateException("Mail File exists for ID: " + messageRequest.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
File mailFile = tempFilePath.toFile();
|
File mailFile = eaiFilePath.toFile();
|
||||||
try {
|
try {
|
||||||
boolean created = mailFile.createNewFile();
|
boolean created = mailFile.createNewFile();
|
||||||
if (!created) {
|
if (!created) {
|
||||||
@@ -218,22 +216,11 @@ public class EmailJob {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Files.write(tempFilePath, data);
|
Files.write(eaiFilePath, data);
|
||||||
Files.copy(tempFilePath, eaiFilePath);
|
|
||||||
Files.delete(tempFilePath);
|
|
||||||
log.debug("Wrote JSON to file: {}", eaiFilePath.toString());
|
log.debug("Wrote JSON to file: {}", eaiFilePath.toString());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Cannot write JSON to file: {}", eaiFilePath.toString(), e);
|
log.error("Cannot write JSON to file: {}", eaiFilePath.toString(), e);
|
||||||
throw new RuntimeException(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);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CompletableFuture<Boolean> future = service.sendEmail(messageRequest, (result, ex) -> {
|
log.info("done");
|
||||||
// if (ex != null) {
|
}
|
||||||
// log.error("failed", ex);
|
|
||||||
// } else {
|
@Test
|
||||||
// log.info("result: {}", result);
|
public void testEmailInServer() {
|
||||||
// }
|
Assumptions.assumeTrue(
|
||||||
// });
|
"true".equalsIgnoreCase(System.getenv("KJB_EAPIM_TEST_ENABLED")),
|
||||||
//
|
"OS 환경변수 내 KJB_EAPIM_TEST_ENABLED=TRUE 설정되어 있어야 동작함");
|
||||||
// future.join();
|
|
||||||
|
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");
|
log.info("done");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user