Compare commits
7 Commits
2153ed51a8
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 46aaaf1059 | |||
| 6bbddb4794 | |||
| b414561b47 | |||
| b6c64983ee | |||
| 831dc9fc48 | |||
| ad7ff7276f | |||
| ec6b51f2a8 |
+27
-1
@@ -110,7 +110,11 @@ dependencies {
|
||||
|
||||
|
||||
implementation "org.springframework:spring-webmvc:${springVersion}"
|
||||
implementation "org.springframework.security:spring-security-jwt:1.1.1.RELEASE"
|
||||
// bcpkix/bcprov-jdk15on:1.64 전이 차단 — BouncyCastle 은 elink-online-common 이
|
||||
// 제공하는 jdk18on 라인만 사용한다(구버전 클래스 중복 방지).
|
||||
implementation ("org.springframework.security:spring-security-jwt:1.1.1.RELEASE") {
|
||||
exclude group: 'org.bouncycastle'
|
||||
}
|
||||
|
||||
//implementation "com.eactive:ojdbc8:1.0"
|
||||
//implementation "org.postgresql:postgresql:42.2.23"
|
||||
@@ -157,6 +161,28 @@ test {
|
||||
configurations.all {
|
||||
exclude group: 'log4j', module: 'log4j'
|
||||
exclude group: 'org.codehaus.jackson'
|
||||
|
||||
// commons-fileupload: elink-online-common 이 api 로 선언(build.gradle:85)하지만,
|
||||
// 사용처는 HttpAdapterServiceRest / HttpAdapterServiceVirtualAccount 두 클래스뿐이다.
|
||||
// 두 클래스는 정적 참조가 없고 HttpAdapterServiceFactory 의
|
||||
// Class.forName(DB 설정 클래스명) 으로만 로드되는데, DJB 는 자체 DJBApiAdapterService 를
|
||||
// 사용하므로 이 어댑터 서비스가 기동되지 않는다(= 런타임 미사용).
|
||||
// 공유 모듈인 elink-online-common 에서 의존성을 지우면 타 사이트가 깨지므로,
|
||||
// 루트에서만 배제해 배포 WAR(WEB-INF/lib)에서 제외한다.
|
||||
// ※ 운영 DB 어댑터 설정에 위 두 클래스가 등록되면 NoClassDefFoundError 가 발생하므로,
|
||||
// 해당 어댑터를 사용하게 되는 시점에 이 exclude 를 반드시 제거할 것.
|
||||
exclude group: 'commons-fileupload'
|
||||
|
||||
// BouncyCastle jdk15on 라인 최종 차단.
|
||||
// jdk15on 과 jdk18on 은 artifactId 가 달라 Gradle 이 같은 라이브러리로 보지 않는다.
|
||||
// 어느 경로로든 유입되면 org.bouncycastle.* 가 WEB-INF/lib 에 중복 적재되므로
|
||||
// 배포 WAR 기준으로 한 번 더 배제한다(사용 버전: bcprov/bcpkix-jdk18on 1.78.1).
|
||||
exclude group: 'org.bouncycastle', module: 'bcprov-jdk15on'
|
||||
exclude group: 'org.bouncycastle', module: 'bcpkix-jdk15on'
|
||||
|
||||
// 구 groupId 의 dom4j(=1.6.1) 최종 차단. org.dom4j:dom4j:2.1.3 만 사용한다.
|
||||
// (groupId 가 달라 Gradle 이 버전 충돌로 인식하지 못하므로 명시적으로 배제)
|
||||
exclude group: 'dom4j', module: 'dom4j'
|
||||
}
|
||||
|
||||
task settingEclipseEncoding {
|
||||
|
||||
+1
-1
Submodule elink-online-common updated: e9fbffa87e...1c48dd834a
+1
-1
Submodule elink-online-core-jpa updated: 62291c9e57...6651e0e809
+1
-1
Submodule elink-online-transformer updated: 09ac7f4ca5...8701f5d459
@@ -78,6 +78,14 @@ public class StandardMessageCoordinatorDJB extends DefaultStandardMessageCoordin
|
||||
// DATA 영역 경로
|
||||
public static final String DATA_SCOP_LEN = "DATA.data_scop_len";
|
||||
|
||||
// 정상 응답 메시지.
|
||||
// 예전에는 표준전문 레이아웃의 기본값으로 붙였으나, 그렇게 두면 "아무도 채우지 않은 상태" 와
|
||||
// "정상이라고 판정한 상태" 가 구분되지 않는다. 실제로 2026-09 사고에서 MSG 부 파싱이 통째로
|
||||
// 스킵됐는데도 오류가 "정상처리되었습니다." 로 보고됐다.
|
||||
// 이제 레이아웃 기본값을 없애고, 정상이라고 판정한 지점에서만 명시적으로 설정한다.
|
||||
public static final String NORMAL_OUTP_MSG_CD = "NCMM00001";
|
||||
public static final String NORMAL_OUTP_MSG_CTNT = "정상처리되었습니다.";
|
||||
|
||||
private String[] netInfo;
|
||||
|
||||
@Override
|
||||
@@ -156,6 +164,20 @@ public class StandardMessageCoordinatorDJB extends DefaultStandardMessageCoordin
|
||||
standardMessage.setData(HEAD_MESG_RSPN_DT, now.format(FMT_DATE));
|
||||
standardMessage.setData(HEAD_MESG_RSPN_TIME, now.format(FMT_TIME_MILLIS));
|
||||
|
||||
// 정상 응답의 MSG 코드/메시지를 여기서 채운다. 레이아웃 기본값을 없앴으므로
|
||||
// 이 지점이 정상 응답 메시지의 유일한 출처다.
|
||||
// coordinateBeforeResponse 는 모든 동기 응답이 거치는 마지막 관문이라
|
||||
// (RequestProcessor 에서 호출) 경로를 빠짐없이 덮는다.
|
||||
//
|
||||
// 반드시 두 조건을 함께 본다.
|
||||
// 1) 정상 응답일 때만. 오류 응답에 "정상처리되었습니다." 를 채우면 2026-09 사고
|
||||
// (MSG 부가 버려졌는데 오류가 정상으로 보고됨)를 코드로 재현하는 셈이다.
|
||||
// 2) 값이 비어 있을 때만. 대외계가 표준응답으로 MSG 를 채워 보낸 경우 그 값이
|
||||
// 우선이며 덮어쓰면 안 된다.
|
||||
if (STDMessageKeys.RESPONSE_TYPE_CODE_N.equals(mapper.getResponseType(standardMessage))) {
|
||||
setIfBlank(standardMessage, MSG_OUTP_MSG_CD, NORMAL_OUTP_MSG_CD);
|
||||
setIfBlank(standardMessage, MSG_OUTP_MSG_CTNT, NORMAL_OUTP_MSG_CTNT);
|
||||
}
|
||||
|
||||
StandardItem msgListRowCnt = standardMessage.findItem(StandardMessageCoordinatorDJB.MSG_LIST_ROWCNT);
|
||||
if (msgListRowCnt == null || "0".equals(msgListRowCnt.getValue()) || "".equals(msgListRowCnt.getValue())) {
|
||||
@@ -249,8 +271,9 @@ public class StandardMessageCoordinatorDJB extends DefaultStandardMessageCoordin
|
||||
mainMsgItem.setSize(1);
|
||||
}
|
||||
|
||||
// msg_dvcd=NM, outp_atrb_cd=0, outp_msg_cd, outp_msg_ctnt, msg_list_rowcnt=0
|
||||
// → 모두 CSV 기본값 사용
|
||||
// msg_dvcd=NM, outp_atrb_cd=0, msg_list_rowcnt=0 → 레이아웃 기본값 사용
|
||||
// outp_msg_cd, outp_msg_ctnt → 레이아웃 기본값을 없앴으므로 여기서는 비워 두고,
|
||||
// 모든 동기 응답이 거치는 coordinateBeforeResponse 에서 정상 응답일 때만 채운다.
|
||||
|
||||
makeMsgScopLen(responseMessage);
|
||||
}
|
||||
@@ -270,6 +293,17 @@ public class StandardMessageCoordinatorDJB extends DefaultStandardMessageCoordin
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 항목이 존재하고 값이 비어 있을 때만 설정한다.
|
||||
* 이미 채워진 값(대외계가 보낸 MSG, 오류 경로가 설정한 값 등)은 그대로 보존한다.
|
||||
*/
|
||||
private void setIfBlank(StandardMessage standardMessage, String path, String value) {
|
||||
StandardItem item = standardMessage.findItem(path);
|
||||
if (item != null && StringUtils.isBlank(item.getValue())) {
|
||||
item.setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
private void resolveCallPropRefValues(StandardMessage standardMessage, Properties prop) {
|
||||
if (prop == null) return;
|
||||
resolveCallPropInChilds(standardMessage.getChilds(), prop);
|
||||
@@ -397,18 +431,10 @@ public class StandardMessageCoordinatorDJB extends DefaultStandardMessageCoordin
|
||||
if (StringUtils.isBlank(refPath) || StringUtils.isBlank(refValue)) {
|
||||
return true;
|
||||
}
|
||||
String actualValue = StringUtils.trimToEmpty(standardMessage.findItemValue(refPath));
|
||||
boolean negate = refValue.startsWith("!");
|
||||
String compareValue = negate ? refValue.substring(1) : refValue;
|
||||
boolean matched = matchesAny(compareValue, actualValue);
|
||||
return negate ? !matched : matched;
|
||||
}
|
||||
|
||||
private boolean matchesAny(String refValue, String actualValue) {
|
||||
for (String v : refValue.split("\\|")) {
|
||||
if (v.equals(actualValue)) return true;
|
||||
}
|
||||
return false;
|
||||
// 판정 기준은 StandardItem.matchRefCondition 하나로 통일한다.
|
||||
// (FlatReader 파싱 / FLAT 직렬화와 같은 기준이어야 블록 유무 판단이 어긋나지 않음)
|
||||
return StandardItem.matchRefCondition(refValue,
|
||||
StringUtils.trimToEmpty(standardMessage.findItemValue(refPath)));
|
||||
}
|
||||
|
||||
private void makeupDataScopLen(StandardMessage standardMessage, String charset) {
|
||||
|
||||
@@ -151,8 +151,8 @@ msg_dvcd,2,2,0,1,2,1,,,NM
|
||||
msg_scop_len,2,2,0,1,8,2,,,
|
||||
MAIN_MSG,2,3,0,1,0,1,,,
|
||||
outp_atrb_cd,3,2,1,1,1,1,,,0
|
||||
outp_msg_cd,3,2,1,1,12,1,,,NCMM00001
|
||||
outp_msg_ctnt,3,2,1,1,200,1,,,정상처리되었습니다.
|
||||
outp_msg_cd,3,2,1,1,12,1,,,
|
||||
outp_msg_ctnt,3,2,1,1,200,1,,,
|
||||
outp_msg_desc,3,2,1,1,300,1,,,
|
||||
mngm_msg_cd,3,2,1,1,12,1,,,
|
||||
msg_list_rowcnt,3,2,0,1,5,2,,,0
|
||||
|
||||
|
+49
-6
@@ -324,20 +324,59 @@ class StandardMessageCoordinatorDJBTest {
|
||||
"정상 수신 시 msg_dvcd는 NM이어야 함");
|
||||
}
|
||||
|
||||
// outp_msg_cd / outp_msg_ctnt 는 레이아웃 기본값을 없앴으므로 이 시점에는 비어 있고,
|
||||
// 실제 흐름대로 coordinateBeforeResponse 까지 거쳐야 채워진다.
|
||||
@Test
|
||||
void 정상수신시_outp_msg_cd_설정됨() {
|
||||
void 정상수신시_outp_msg_cd_는_응답조정후_설정됨() {
|
||||
coordinator.coordinateAfterRecvNonStdSyncResponse(message);
|
||||
assertTrue(isBlankValue(message.findItemValue("MSG.MAIN_MSG.outp_msg_cd")),
|
||||
"수신 조정 단계에서는 아직 비어 있어야 함 (레이아웃 기본값이 없어야 한다)");
|
||||
|
||||
String msgCd = message.findItemValue("MSG.MAIN_MSG.outp_msg_cd");
|
||||
assertFalse(msgCd == null || msgCd.trim().isEmpty(), "outp_msg_cd가 설정되어야 함");
|
||||
coordinator.coordinateBeforeResponse(message, null, null, "utf-8");
|
||||
|
||||
assertEquals(StandardMessageCoordinatorDJB.NORMAL_OUTP_MSG_CD,
|
||||
message.findItemValue("MSG.MAIN_MSG.outp_msg_cd"),
|
||||
"정상 응답의 outp_msg_cd 가 설정되어야 함");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 정상수신시_outp_msg_ctnt_설정됨() {
|
||||
void 정상수신시_outp_msg_ctnt_는_응답조정후_설정됨() {
|
||||
coordinator.coordinateAfterRecvNonStdSyncResponse(message);
|
||||
assertTrue(isBlankValue(message.findItemValue("MSG.MAIN_MSG.outp_msg_ctnt")),
|
||||
"수신 조정 단계에서는 아직 비어 있어야 함 (레이아웃 기본값이 없어야 한다)");
|
||||
|
||||
String ctnt = message.findItemValue("MSG.MAIN_MSG.outp_msg_ctnt");
|
||||
assertFalse(ctnt == null || ctnt.trim().isEmpty(), "outp_msg_ctnt가 설정되어야 함");
|
||||
coordinator.coordinateBeforeResponse(message, null, null, "utf-8");
|
||||
|
||||
assertEquals(StandardMessageCoordinatorDJB.NORMAL_OUTP_MSG_CTNT,
|
||||
message.findItemValue("MSG.MAIN_MSG.outp_msg_ctnt"),
|
||||
"정상 응답의 outp_msg_ctnt 가 설정되어야 함");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 오류응답에는_정상메시지가_채워지지_않는다() {
|
||||
coordinator.coordinateSetStandardMessageError(message, mapper, "RECEAIINA001", "테스트오류");
|
||||
coordinator.coordinateBeforeResponse(message, null, null, "utf-8");
|
||||
|
||||
assertNotEquals(StandardMessageCoordinatorDJB.NORMAL_OUTP_MSG_CD,
|
||||
message.findItemValue("MSG.MAIN_MSG.outp_msg_cd"),
|
||||
"오류 응답에 정상코드가 채워지면 안 됨");
|
||||
assertNotEquals(StandardMessageCoordinatorDJB.NORMAL_OUTP_MSG_CTNT,
|
||||
message.findItemValue("MSG.MAIN_MSG.outp_msg_ctnt"),
|
||||
"오류 응답에 '정상처리되었습니다.' 가 채워지면 안 됨 — 2026-09 사고의 재현");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 대외계가_보낸_MSG_값은_덮어쓰지_않는다() {
|
||||
coordinator.coordinateAfterRecvNonStdSyncResponse(message);
|
||||
message.setData("MSG.MAIN_MSG.outp_msg_cd", "ABC00001");
|
||||
message.setData("MSG.MAIN_MSG.outp_msg_ctnt", "상대가 보낸 메시지");
|
||||
|
||||
coordinator.coordinateBeforeResponse(message, null, null, "utf-8");
|
||||
|
||||
assertEquals("ABC00001", message.findItemValue("MSG.MAIN_MSG.outp_msg_cd"),
|
||||
"이미 채워진 outp_msg_cd 를 덮어쓰면 안 됨");
|
||||
assertEquals("상대가 보낸 메시지", message.findItemValue("MSG.MAIN_MSG.outp_msg_ctnt"),
|
||||
"이미 채워진 outp_msg_ctnt 를 덮어쓰면 안 됨");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -496,4 +535,8 @@ class StandardMessageCoordinatorDJBTest {
|
||||
f.setAccessible(true);
|
||||
f.set(item, refValue);
|
||||
}
|
||||
|
||||
private static boolean isBlankValue(String value) {
|
||||
return value == null || value.trim().isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,19 +32,20 @@ import static org.mockito.ArgumentMatchers.anyString;
|
||||
* 검증 시나리오:
|
||||
* 1. FlatReader 등록 확인
|
||||
* 2. 비ERP 요청 FLAT 왕복 — HEAD 보존, EZDATA/MSG 바이트 미포함
|
||||
* 2-1. ERP 요청인데 JSON 에 EZDATA 가 없는 경우 — EZDATA 바이트 포함
|
||||
* 3. ERP 요청 FLAT 왕복 — EZDATA 포함 보존
|
||||
* 4. 오류 응답 FLAT 왕복 — MSG EM 포함 보존
|
||||
* 5. 정상 응답 FLAT 왕복 — MSG NM 포함 보존
|
||||
* 6. 거래로그 시나리오 — FLAT 바이트 길이 검증 (조건부 블록 포함 여부)
|
||||
*
|
||||
* 핵심 버그 (EZDATA FLAT 오류):
|
||||
* JSON 파싱 시 JSON에 없는 조건부 블록(EZDATA, MSG)은 isHidden=false 로 남는다.
|
||||
* toByteArray() GROUP 케이스에서 size=0 이면서 refPath/refValue 가 있는 경우
|
||||
* isHidden 체크만으로는 불충분 → FLAT에 비활성 블록 바이트가 잘못 포함된다.
|
||||
* 핵심: FLAT 은 위치 기반이라 블록의 존재 여부를 전문에서 알 수 없고 ref 조건으로만 판단한다.
|
||||
* 따라서 직렬화와 파싱이 같은 기준을 써야 한다.
|
||||
*
|
||||
* 수정: toByteArray() / getBytesDataLength() GROUP 케이스를
|
||||
* toJson() 과 동일하게 size==0 이면 무조건 skip 으로 변경
|
||||
* (StandardItem.java 두 곳)
|
||||
* 기준: 조건부 블록(refPath/refValue)은 ref 조건 성립 여부로 FLAT 포함 여부를 정한다.
|
||||
* - 조건 불성립 → JSON 에 블록이 있어도 FLAT 미포함
|
||||
* - 조건 성립 → JSON 에 블록이 없어도(size=0) 레이아웃 기본값으로 FLAT 포함
|
||||
* (StandardItem.isFlatGroupActive / FlatReader.traverse 가 공유하는
|
||||
* StandardItem.matchRefCondition 로 판정)
|
||||
*/
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class StandardMessageFlatFlowTest {
|
||||
@@ -127,6 +128,42 @@ class StandardMessageFlatFlowTest {
|
||||
+ "}"
|
||||
+ "}";
|
||||
|
||||
/**
|
||||
* ERP 요청인데 EZDATA 블록을 보내지 않은 JSON.
|
||||
* corp_tlwn_virt_brcd=ERP 이므로 레이아웃상 EZDATA 는 "있어야 하는" 블록이지만
|
||||
* 수신 JSON 에 없어 size=0 으로 남는다. 실제 거래로그에서 확인된 케이스다.
|
||||
*/
|
||||
private static final String ERP_REQ_NO_EZDATA_JSON =
|
||||
"{"
|
||||
+ "\"HEAD\":{"
|
||||
+ "\"nxgn_stnd_idfr\":\"JERA\","
|
||||
+ "\"guid\":\"" + TEST_GUID + "\","
|
||||
+ "\"guid_prgs_no\":\"1\","
|
||||
+ "\"stnd_mesg_ver\":\"R10\","
|
||||
+ "\"ortr_guid\":\"" + TEST_GUID + "\","
|
||||
+ "\"dman_rspn_dvcd\":\"S\","
|
||||
+ "\"if_id\":\"" + TEST_IF_ID + "\","
|
||||
+ "\"procs_rslt_dvcd\":\"S\","
|
||||
+ "\"tx_id\":\"" + TEST_TX_ID + "\","
|
||||
+ "\"chnl_tycd\":\"EAI\","
|
||||
+ "\"hmab_dvcd\":\"1\","
|
||||
+ "\"corp_tlwn_virt_brcd\":\"ERP\","
|
||||
+ "\"trnm_sys_dvcd\":\"OPA\","
|
||||
+ "\"frst_trnm_sys_dvcd\":\"OPA\","
|
||||
+ "\"sys_env_dvcd\":\"D\","
|
||||
+ "\"frst_mesg_dman_dt\":\"20260420\","
|
||||
+ "\"frst_mesg_dman_time\":\"120000000\""
|
||||
+ "},"
|
||||
+ "\"DATA\":{"
|
||||
+ "\"data_dvcd\":\"IO\","
|
||||
+ "\"data_scop_len\":\"00000037\","
|
||||
+ "\"BIZ_DATA\":{\"acct_no\":\"987654321\",\"amt\":\"500000\"}"
|
||||
+ "}"
|
||||
+ "}";
|
||||
|
||||
/** EZDATA 블록 선언 길이 (standard-layout-djb.csv 기준) */
|
||||
private static final int EZDATA_BLOCK_SIZE = 1500;
|
||||
|
||||
private StandardMessageManager manager;
|
||||
private InterfaceMapper mapper;
|
||||
private StandardReader flatReader;
|
||||
@@ -253,6 +290,78 @@ class StandardMessageFlatFlowTest {
|
||||
"비ERP FLAT 왕복 후 EZDATA 블록이 활성 상태이면 안 됨");
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// 2-1. ERP 요청인데 JSON 에 EZDATA 가 없는 경우
|
||||
//
|
||||
// [버그] corp_tlwn_virt_brcd=ERP 라 FlatReader 는 EZDATA(1500B)가 있다고 보고 읽는데,
|
||||
// 직렬화는 size==0 이라 건너뛰어 헤더가 678B 로 기록된다.
|
||||
// → cut() underflow → 거래로그 화면에서 헤더 파싱 실패(원문 노출)
|
||||
// [수정] ref 조건이 성립하면 size==0 이어도 레이아웃 기본값으로 FLAT 출력
|
||||
// (StandardItem.isFlatGroupActive)
|
||||
// ================================================================
|
||||
|
||||
@Test
|
||||
void ERP요청_EZDATA미포함_FLAT_파싱_예외없음() throws Exception {
|
||||
StandardMessage src = parseJson(ERP_REQ_NO_EZDATA_JSON);
|
||||
String flatStr = src.toFixedString(false, FLAT_CHARSET);
|
||||
|
||||
StandardMessage dst = manager.getStandardMessage();
|
||||
assertDoesNotThrow(() -> flatReader.parse(dst, flatStr),
|
||||
"ERP 요청(EZDATA 미포함) FLAT 파싱 중 예외 발생 — "
|
||||
+ "corp_tlwn_virt_brcd=ERP 이면 EZDATA 바이트가 FLAT 에 포함되어야 함");
|
||||
}
|
||||
|
||||
@Test
|
||||
void ERP요청_EZDATA미포함_FLAT에_EZDATA_바이트_포함() throws Exception {
|
||||
byte[] nonErpBytes = parseJson(NON_ERP_REQ_JSON)
|
||||
.toFixedString(false, FLAT_CHARSET).getBytes(FLAT_CHARSET);
|
||||
byte[] erpNoEzBytes = parseJson(ERP_REQ_NO_EZDATA_JSON)
|
||||
.toFixedString(false, FLAT_CHARSET).getBytes(FLAT_CHARSET);
|
||||
|
||||
assertEquals(nonErpBytes.length + EZDATA_BLOCK_SIZE, erpNoEzBytes.length,
|
||||
String.format("ERP 요청(EZDATA 미포함) FLAT 길이(%d)는 "
|
||||
+ "비ERP FLAT 길이(%d) + EZDATA(%d) 여야 함",
|
||||
erpNoEzBytes.length, nonErpBytes.length, EZDATA_BLOCK_SIZE));
|
||||
}
|
||||
|
||||
@Test
|
||||
void ERP요청_EZDATA_포함여부와_무관하게_FLAT_길이_동일() throws Exception {
|
||||
byte[] withEzBytes = parseJson(ERP_REQ_JSON)
|
||||
.toFixedString(false, FLAT_CHARSET).getBytes(FLAT_CHARSET);
|
||||
byte[] noEzBytes = parseJson(ERP_REQ_NO_EZDATA_JSON)
|
||||
.toFixedString(false, FLAT_CHARSET).getBytes(FLAT_CHARSET);
|
||||
|
||||
// 블록 유무는 JSON 수신 여부가 아니라 ref 조건(corp_tlwn_virt_brcd=ERP)이 정한다
|
||||
assertEquals(withEzBytes.length, noEzBytes.length,
|
||||
String.format("EZDATA 포함 JSON(%d)과 미포함 JSON(%d)의 FLAT 길이가 달라짐",
|
||||
withEzBytes.length, noEzBytes.length));
|
||||
}
|
||||
|
||||
@Test
|
||||
void ERP요청_EZDATA미포함_FLAT_왕복_HEAD_corp_tlwn_virt_brcd_ERP() throws Exception {
|
||||
StandardMessage dst = flatRoundTrip(parseJson(ERP_REQ_NO_EZDATA_JSON));
|
||||
|
||||
assertEquals("ERP", dst.findItemValue("HEAD.corp_tlwn_virt_brcd").trim(),
|
||||
"ERP 요청(EZDATA 미포함) FLAT 왕복 후 HEAD.corp_tlwn_virt_brcd 불일치");
|
||||
}
|
||||
|
||||
@Test
|
||||
void ERP요청_EZDATA미포함_FLAT_왕복_HEAD_if_id_보존() throws Exception {
|
||||
StandardMessage dst = flatRoundTrip(parseJson(ERP_REQ_NO_EZDATA_JSON));
|
||||
|
||||
assertEquals(TEST_IF_ID, dst.findItemValue("HEAD.if_id").trim(),
|
||||
"ERP 요청(EZDATA 미포함) FLAT 왕복 후 HEAD.if_id 불일치");
|
||||
}
|
||||
|
||||
@Test
|
||||
void ERP요청_EZDATA미포함_FLAT_왕복_DATA_data_dvcd_IO() throws Exception {
|
||||
// 거래로그 화면에서 깨졌던 지점: EZDATA 를 건너뛰면 DATA 부 오프셋이 어긋난다
|
||||
StandardMessage dst = flatRoundTrip(parseJson(ERP_REQ_NO_EZDATA_JSON));
|
||||
|
||||
assertEquals("IO", dst.findItemValue("DATA.data_dvcd").trim(),
|
||||
"ERP 요청(EZDATA 미포함) FLAT 왕복 후 DATA.data_dvcd 불일치 — EZDATA 오프셋 어긋남");
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// 3. ERP 요청 FLAT 왕복 — EZDATA 포함
|
||||
// ================================================================
|
||||
|
||||
@@ -443,11 +443,15 @@ class StandardMessageJsonFlowTest {
|
||||
void 비표준수신_정상응답_JSON_직렬화_outp_msg_ctnt_설정됨() throws Exception {
|
||||
StandardMessage msg = manager.getStandardMessage();
|
||||
coordinator.coordinateAfterRecvNonStdSyncResponse(msg);
|
||||
// outp_msg_cd/ctnt 는 레이아웃 기본값이 없으므로, 실제 흐름대로 응답 직전 조정까지
|
||||
// 거쳐야 채워진다 (StandardMessageCoordinatorDJB.coordinateBeforeResponse)
|
||||
coordinator.coordinateBeforeResponse(msg, null, null, "utf-8");
|
||||
|
||||
String json = msg.getDataString(MessageType.JSON, "utf-8");
|
||||
JsonNode root = jacksonMapper.readTree(json);
|
||||
String ctnt = root.path("MSG").path("MAIN_MSG").path("outp_msg_ctnt").asText();
|
||||
assertFalse(ctnt.isEmpty(), "정상응답 JSON의 outp_msg_ctnt가 설정되어야 함");
|
||||
assertEquals(StandardMessageCoordinatorDJB.NORMAL_OUTP_MSG_CTNT, ctnt,
|
||||
"정상응답 JSON의 outp_msg_ctnt가 설정되어야 함");
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
|
||||
@@ -0,0 +1,262 @@
|
||||
package com.eactive.eai.message;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.eactive.eai.message.parser.FlatReader;
|
||||
|
||||
/**
|
||||
* 조건부 GROUP 블록의 FLAT 직렬화 판정 단위 테스트
|
||||
*
|
||||
* 검증 대상:
|
||||
* - {@link StandardItem#matchRefCondition(String, String)} : ref 조건 판정 규칙
|
||||
* - {@link StandardItem#isFlatGroupActive(StandardMessage, boolean)} : GROUP 의 FLAT 출력 여부
|
||||
* (관측 가능한 계약인 toByteArray() / getBytesDataLength() 결과로 검증)
|
||||
*
|
||||
* 핵심 계약:
|
||||
* FLAT 은 위치 기반이라 전문만 보고 블록 존재 여부를 알 수 없고 ref 조건으로만 판단한다.
|
||||
* 따라서 직렬화(StandardItem)와 파싱(FlatReader)이 반드시 같은 기준을 써야 하며,
|
||||
* 조건이 성립하면 수신 전문에 블록이 없어(size=0) 도 레이아웃 기본값으로 출력해야 한다.
|
||||
* 출력하지 않으면 파서는 블록이 있다고 보고 읽어 오프셋이 어긋난다.
|
||||
*/
|
||||
class StandardItemFlatGroupTest {
|
||||
|
||||
private static final String CHARSET = "euc-kr";
|
||||
|
||||
// 테스트 레이아웃 블록별 선언 길이
|
||||
private static final int HEAD_LEN = 3; // mode(3)
|
||||
private static final int COND_SUB_LEN = 4; // SUB.s1(4)
|
||||
private static final int COND_LEN = 5 + COND_SUB_LEN; // c1(5) + SUB
|
||||
private static final int TAIL_LEN = 2; // t1(2)
|
||||
|
||||
private static final int LEN_WITH_COND = HEAD_LEN + COND_LEN + TAIL_LEN; // 14
|
||||
private static final int LEN_WITHOUT_COND = HEAD_LEN + TAIL_LEN; // 5
|
||||
|
||||
// ================================================================
|
||||
// 1. matchRefCondition — ref 조건 판정 규칙
|
||||
// ================================================================
|
||||
|
||||
@Test
|
||||
void matchRefCondition_단일값_일치() {
|
||||
assertTrue(StandardItem.matchRefCondition("ERP", "ERP"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void matchRefCondition_단일값_불일치() {
|
||||
assertFalse(StandardItem.matchRefCondition("ERP", "XXX"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void matchRefCondition_실제값_공백패딩_무시() {
|
||||
// FLAT 필드는 스페이스로 우측 패딩되므로 trim 후 비교해야 한다
|
||||
assertTrue(StandardItem.matchRefCondition("ERP", "ERP "));
|
||||
assertTrue(StandardItem.matchRefCondition("ERP", " ERP "));
|
||||
}
|
||||
|
||||
@Test
|
||||
void matchRefCondition_실제값_null이면_불일치() {
|
||||
assertFalse(StandardItem.matchRefCondition("ERP", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void matchRefCondition_refValue_null이면_불일치() {
|
||||
assertFalse(StandardItem.matchRefCondition(null, "ERP"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void matchRefCondition_OR조건() {
|
||||
assertTrue(StandardItem.matchRefCondition("NM|EM", "NM"));
|
||||
assertTrue(StandardItem.matchRefCondition("NM|EM", "EM"));
|
||||
assertFalse(StandardItem.matchRefCondition("NM|EM", "XX"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void matchRefCondition_NOT조건() {
|
||||
assertFalse(StandardItem.matchRefCondition("!S", "S"));
|
||||
assertTrue(StandardItem.matchRefCondition("!S", "R"));
|
||||
// 응답구분이 비어 있으면 S 가 아니므로 조건 성립
|
||||
assertTrue(StandardItem.matchRefCondition("!S", " "));
|
||||
}
|
||||
|
||||
@Test
|
||||
void matchRefCondition_NOT와_OR_조합() {
|
||||
assertFalse(StandardItem.matchRefCondition("!NM|EM", "NM"));
|
||||
assertFalse(StandardItem.matchRefCondition("!NM|EM", "EM"));
|
||||
assertTrue(StandardItem.matchRefCondition("!NM|EM", "XX"));
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// 2. 조건부 GROUP 의 FLAT 출력 여부
|
||||
// ================================================================
|
||||
|
||||
@Test
|
||||
void 조건성립이면_size0이어도_FLAT에_포함() throws Exception {
|
||||
// 수신 전문에 COND 블록이 없어 size=0 이지만 조건(mode=ERP)이 성립하는 상황
|
||||
StandardMessage msg = newMessage("ERP");
|
||||
assertEquals(0, msg.findItem("COND").getSize(), "전제조건: COND 는 미활성(size=0) 이어야 함");
|
||||
|
||||
assertEquals(LEN_WITH_COND, msg.toByteArray(false, CHARSET).length,
|
||||
"조건 성립 시 COND 블록이 레이아웃 기본값으로 FLAT 에 포함되어야 함");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 조건불성립이면_FLAT에_미포함() throws Exception {
|
||||
StandardMessage msg = newMessage("XXX");
|
||||
|
||||
assertEquals(LEN_WITHOUT_COND, msg.toByteArray(false, CHARSET).length,
|
||||
"조건 불성립 시 COND 블록은 FLAT 에서 제외되어야 함");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 조건성립으로_활성화된_블록의_하위_무조건GROUP도_포함() throws Exception {
|
||||
StandardMessage msg = newMessage("ERP");
|
||||
assertEquals(0, msg.findItem("COND.SUB").getSize(), "전제조건: SUB 도 미활성(size=0) 이어야 함");
|
||||
|
||||
// SUB(4바이트)가 빠지면 FlatReader 가 SUB 를 읽을 때 오프셋이 어긋난다
|
||||
int len = msg.toByteArray(false, CHARSET).length;
|
||||
assertEquals(LEN_WITH_COND, len,
|
||||
String.format("활성화된 COND 하위의 무조건 GROUP(SUB %d바이트)도 함께 출력되어야 함. 실제=%d",
|
||||
COND_SUB_LEN, len));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hidden블록은_조건성립이어도_미포함() throws Exception {
|
||||
StandardMessage msg = newMessage("ERP");
|
||||
msg.findItem("COND").setHidden(true);
|
||||
|
||||
assertEquals(LEN_WITHOUT_COND, msg.toByteArray(false, CHARSET).length,
|
||||
"isHidden=true 인 블록은 조건이 성립해도 출력하지 않아야 함");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 명시적으로_활성화된_블록은_조건불성립이어도_포함() throws Exception {
|
||||
// 코디네이터가 setSize(1) 로 직접 활성화한 블록(오류응답 MSG 등)의 기존 동작 보존
|
||||
StandardMessage msg = newMessage("XXX");
|
||||
msg.findItem("COND").setSize(1);
|
||||
|
||||
assertEquals(LEN_WITH_COND, msg.toByteArray(false, CHARSET).length,
|
||||
"size>0 으로 명시 활성화된 블록은 조건과 무관하게 출력되어야 함");
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// 3. 길이 계산(getBytesDataLength)과 직렬화(toByteArray)의 일관성
|
||||
// FlatMessageFilter 가 전문길이 필드를 이 값으로 채우므로 어긋나면 안 된다
|
||||
// ================================================================
|
||||
|
||||
@Test
|
||||
void 조건성립_길이계산과_직렬화결과_일치() throws Exception {
|
||||
StandardMessage msg = newMessage("ERP");
|
||||
|
||||
assertEquals(msg.toByteArray(false, CHARSET).length, msg.getBytesDataLength(CHARSET),
|
||||
"조건 성립 시 getBytesDataLength 와 toByteArray 길이가 달라짐");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 조건불성립_길이계산과_직렬화결과_일치() throws Exception {
|
||||
StandardMessage msg = newMessage("XXX");
|
||||
|
||||
assertEquals(msg.toByteArray(false, CHARSET).length, msg.getBytesDataLength(CHARSET),
|
||||
"조건 불성립 시 getBytesDataLength 와 toByteArray 길이가 달라짐");
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// 4. 기존 시그니처 호환 — root 없이 호출하면 종전 규칙(size==0 skip) 유지
|
||||
// ================================================================
|
||||
|
||||
@Test
|
||||
void root없이_호출하면_조건평가없이_size규칙_적용() throws Exception {
|
||||
StandardMessage msg = newMessage("ERP");
|
||||
StandardItem cond = msg.findItem("COND");
|
||||
|
||||
// 조건을 평가할 root 가 없으므로 size==0 인 블록은 출력하지 않는다
|
||||
assertEquals(0, cond.toByteArray(false, CHARSET).length,
|
||||
"root 미전달 시에는 기존 규칙(size==0 → skip)이 유지되어야 함");
|
||||
assertEquals(0, cond.getBytesDataLength(CHARSET),
|
||||
"root 미전달 시에는 기존 규칙(size==0 → skip)이 유지되어야 함");
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// 5. 직렬화 ↔ 파싱 대칭성 (FlatReader 와 같은 기준인지)
|
||||
// ================================================================
|
||||
|
||||
@Test
|
||||
void 조건성립_FLAT_왕복_남는바이트없이_파싱() throws Exception {
|
||||
String flat = newMessage("ERP").toFixedString(false, CHARSET);
|
||||
StandardMessage dst = newMessage("");
|
||||
|
||||
// FlatReader 는 다 읽고 남은 바이트가 있으면 예외를 던진다(overflow),
|
||||
// 블록이 모자라면 cut() 에서 underflow 예외를 던진다
|
||||
assertDoesNotThrow(() -> new FlatReader().parse(dst, flat),
|
||||
"조건 성립 FLAT 파싱 중 예외 발생 — 직렬화와 파싱 기준 불일치");
|
||||
assertEquals("ERP", dst.findItemValue("HEAD.mode").trim(), "왕복 후 HEAD.mode 불일치");
|
||||
assertEquals("IO", dst.findItemValue("TAIL.t1").trim(),
|
||||
"왕복 후 TAIL.t1 불일치 — COND 블록 오프셋이 어긋남");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 조건불성립_FLAT_왕복_남는바이트없이_파싱() throws Exception {
|
||||
String flat = newMessage("XXX").toFixedString(false, CHARSET);
|
||||
StandardMessage dst = newMessage("");
|
||||
|
||||
assertDoesNotThrow(() -> new FlatReader().parse(dst, flat),
|
||||
"조건 불성립 FLAT 파싱 중 예외 발생 — 직렬화와 파싱 기준 불일치");
|
||||
assertEquals("XXX", dst.findItemValue("HEAD.mode").trim(), "왕복 후 HEAD.mode 불일치");
|
||||
assertEquals("IO", dst.findItemValue("TAIL.t1").trim(), "왕복 후 TAIL.t1 불일치");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 조건성립_FLAT_왕복후_COND블록_기본값_보존() throws Exception {
|
||||
StandardMessage src = newMessage("ERP");
|
||||
String flat = src.toFixedString(false, CHARSET);
|
||||
|
||||
StandardMessage dst = newMessage("");
|
||||
new FlatReader().parse(dst, flat);
|
||||
|
||||
assertEquals("C1", dst.findItemValue("COND.c1").trim(),
|
||||
"왕복 후 COND.c1 레이아웃 기본값 불일치");
|
||||
assertEquals("S1", dst.findItemValue("COND.SUB.s1").trim(),
|
||||
"왕복 후 COND.SUB.s1 레이아웃 기본값 불일치");
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// helpers
|
||||
// ================================================================
|
||||
|
||||
/**
|
||||
* 테스트용 최소 레이아웃 (DJBank 표준전문의 HEAD / EZDATA / DATA 구조를 축약)
|
||||
*
|
||||
* <pre>
|
||||
* HEAD GROUP size=1
|
||||
* mode (3) 조건 판정 필드
|
||||
* COND GROUP size=0, 조건 HEAD.mode=ERP
|
||||
* c1 (5)
|
||||
* SUB GROUP size=0, 조건 없음 (상위 활성화 전파 검증용)
|
||||
* s1 (4)
|
||||
* TAIL GROUP size=1
|
||||
* t1 (2)
|
||||
* </pre>
|
||||
*/
|
||||
private StandardMessage newMessage(String modeValue) throws Exception {
|
||||
return StandardMessageUtil.generate(layout(
|
||||
"HEAD,1,3,1,1,0,1,,,",
|
||||
"mode,2,2,1,1,3,1,,," + modeValue,
|
||||
"COND,1,3,0,1,0,1,HEAD.mode,ERP,",
|
||||
"c1,2,2,1,1,5,1,,,C1",
|
||||
"SUB,2,3,0,1,0,1,,,",
|
||||
"s1,3,2,1,1,4,1,,,S1",
|
||||
"TAIL,1,3,1,1,0,1,,,",
|
||||
"t1,2,2,1,1,2,1,,,IO"));
|
||||
}
|
||||
|
||||
/** CsvFileReader 와 동일한 방식으로 레이아웃 행을 StandardItem 으로 만든다 */
|
||||
private ArrayList<StandardItem> layout(String... rows) throws Exception {
|
||||
ArrayList<StandardItem> list = new ArrayList<StandardItem>();
|
||||
for (String row : rows) {
|
||||
list.add(new StandardItem(row.split(",", StandardItem.ITEM_COUNT)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user