오류 응답 템플릿에서 요청 전문 JSON 참조 지원
- resolveCallProp JSON 드릴다운 폴백, render 단위 파싱 캐시 추가 - sys 오류 경로에서 callProp 이 null 로 전달되던 문제 수정 - 단위테스트 12건 추가
This commit is contained in:
@@ -3,8 +3,10 @@ package com.eactive.eai.adapter.handler;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -23,10 +25,10 @@ import com.eactive.eai.common.message.EAIMessage;
|
||||
import com.eactive.eai.common.property.PropManager;
|
||||
import com.eactive.eai.common.util.Logger;
|
||||
import com.eactive.eai.common.util.MessageUtil;
|
||||
import com.eactive.eai.common.util.MessageUtil;
|
||||
import com.eactive.eai.message.StandardItem;
|
||||
import com.eactive.eai.message.StandardMessage;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
/**
|
||||
@@ -86,6 +88,14 @@ import com.google.gson.JsonParser;
|
||||
* callProp.put("OUTBOUND", subProps) // subProps.setProperty("IF_ID", "SVC001")
|
||||
* → 템플릿에서 ${callprop.OUTBOUND.IF_ID} 로 참조
|
||||
* 중간 값이 Properties 가 아닌 경우 전체 keyPath 를 키로 폴백 조회한다.
|
||||
*
|
||||
* [callProp JSON 문자열 참조]
|
||||
* callProp 의 값이 JSON 문자열이면 나머지 경로로 필드를 추출한다.
|
||||
* (전체 keyPath 폴백 조회가 실패한 경우에만 동작하므로 기존 설정에는 영향이 없다)
|
||||
* callProp.put("INBOUND_REQUEST_MESSAGE", "{\"BANK_HEADER\":{\"TrSeqNo\":\"000000000001\"}}")
|
||||
* → 템플릿에서 ${callprop.INBOUND_REQUEST_MESSAGE.BANK_HEADER.TrSeqNo} 로 참조
|
||||
* 최종 노드가 오브젝트/배열이면 JSON 문자열을 그대로 반환한다.
|
||||
* 같은 JSON 문자열은 render 1회 범위에서 한 번만 파싱한다.
|
||||
*/
|
||||
public class TemplateAdapterErrorMsgHandler implements AdapterErrorMessageHandler {
|
||||
|
||||
@@ -160,6 +170,11 @@ public class TemplateAdapterErrorMsgHandler implements AdapterErrorMessageHandle
|
||||
.replace("<", "<")
|
||||
.replace(">", ">")
|
||||
.replace(""", "\"");
|
||||
// 같은 JSON 문자열(요청 전문 등)을 여러 변수에서 참조해도 파싱은 1회만 하도록
|
||||
// render 1회 범위의 파싱 캐시를 만들어 넘긴다.
|
||||
// 핸들러는 AdapterErrorMessageHandlerFactory 에서 싱글톤으로 공유되므로
|
||||
// 인스턴스 필드가 아닌 지역 변수로 두어야 스레드 안전하다.
|
||||
Map<String, JsonElement> jsonCache = new HashMap<>();
|
||||
StringBuffer result = new StringBuffer();
|
||||
Matcher matcher = COMBINED_PATTERN.matcher(template);
|
||||
while (matcher.find()) {
|
||||
@@ -175,7 +190,7 @@ public class TemplateAdapterErrorMsgHandler implements AdapterErrorMessageHandle
|
||||
// 치환값에 제어문자가 섞이면 렌더 결과가 깨진 JSON/XML 이 된다.
|
||||
// (개행이 든 값 → {"outpMsgDesc":"오류상세<개행>..."} → 수신측 파싱 실패)
|
||||
// 템플릿 포맷을 알 수 없으므로 이스케이프 대신 제어문자를 걸러낸다.
|
||||
replacement = MessageUtil.stripControlChars(resolveScalar(expr, msg, callProp, exception));
|
||||
replacement = MessageUtil.stripControlChars(resolveScalar(expr, msg, callProp, exception, jsonCache));
|
||||
}
|
||||
matcher.appendReplacement(result, Matcher.quoteReplacement(replacement));
|
||||
}
|
||||
@@ -191,9 +206,10 @@ public class TemplateAdapterErrorMsgHandler implements AdapterErrorMessageHandle
|
||||
* - "exception.필드[:기본값]" → 리플렉션으로 예외 객체 getter/필드 조회
|
||||
* - "경로[:기본값]" → StandardMessage.findItemValue(경로)
|
||||
*/
|
||||
private String resolveScalar(String expr, StandardMessage msg, Properties callProp, Throwable exception) {
|
||||
private String resolveScalar(String expr, StandardMessage msg, Properties callProp, Throwable exception,
|
||||
Map<String, JsonElement> jsonCache) {
|
||||
if (expr.startsWith(CALLPROP_INDIRECT_PREFIX)) {
|
||||
return resolveIndirectCallProp(expr, msg, callProp);
|
||||
return resolveIndirectCallProp(expr, msg, callProp, jsonCache);
|
||||
}
|
||||
if (expr.startsWith(CALLPROP_PREFIX)) {
|
||||
String rest = expr.substring(CALLPROP_PREFIX.length());
|
||||
@@ -201,7 +217,7 @@ public class TemplateAdapterErrorMsgHandler implements AdapterErrorMessageHandle
|
||||
String keyPath = colonIdx >= 0 ? rest.substring(0, colonIdx) : rest;
|
||||
String defaultVal = colonIdx >= 0 ? rest.substring(colonIdx + 1) : "";
|
||||
if (callProp == null) return defaultVal;
|
||||
String value = resolveCallProp(callProp, keyPath);
|
||||
String value = resolveCallProp(callProp, keyPath, jsonCache);
|
||||
return value != null ? value : defaultVal;
|
||||
}
|
||||
if (expr.startsWith(EXCEPTION_PREFIX)) {
|
||||
@@ -216,7 +232,7 @@ public class TemplateAdapterErrorMsgHandler implements AdapterErrorMessageHandle
|
||||
int colonIdx = expr.indexOf(':');
|
||||
String path = colonIdx >= 0 ? expr.substring(0, colonIdx) : expr;
|
||||
String defaultVal = colonIdx >= 0 ? expr.substring(colonIdx + 1) : "";
|
||||
String value = resolveMessagePath(msg, path);
|
||||
String value = resolveMessagePath(msg, path, jsonCache);
|
||||
return StringUtils.isNotEmpty(value) ? value : defaultVal;
|
||||
}
|
||||
|
||||
@@ -230,7 +246,7 @@ public class TemplateAdapterErrorMsgHandler implements AdapterErrorMessageHandle
|
||||
* 예) DATA.BIZDATA.acctNo → findItemValue("DATA.BIZDATA") → JSON 파싱 → acctNo
|
||||
* DATA.BIZDATA.addr.city → findItemValue("DATA.BIZDATA") → JSON 파싱 → addr.city
|
||||
*/
|
||||
private String resolveMessagePath(StandardMessage msg, String path) {
|
||||
private String resolveMessagePath(StandardMessage msg, String path, Map<String, JsonElement> jsonCache) {
|
||||
if (msg == null) return null;
|
||||
|
||||
int bracketStart = path.indexOf('[');
|
||||
@@ -247,7 +263,7 @@ public class TemplateAdapterErrorMsgHandler implements AdapterErrorMessageHandle
|
||||
String subPath = path.substring(dotIdx + 1);
|
||||
String parentVal = msg.findItemValue(parentPath);
|
||||
if (StringUtils.isNotBlank(parentVal)) {
|
||||
String extracted = extractFromJson(parentVal, subPath);
|
||||
String extracted = extractFromJson(parentVal, subPath, jsonCache);
|
||||
if (extracted != null) return extracted;
|
||||
}
|
||||
dotIdx = parentPath.lastIndexOf('.');
|
||||
@@ -298,9 +314,9 @@ public class TemplateAdapterErrorMsgHandler implements AdapterErrorMessageHandle
|
||||
* 중간 경로가 JSON 오브젝트면 계속 탐색하고, 최종 값이 primitive 면 문자열로,
|
||||
* 오브젝트/배열이면 JSON 문자열 그대로 반환한다. 파싱 실패 시 null 반환.
|
||||
*/
|
||||
private String extractFromJson(String json, String fieldPath) {
|
||||
private String extractFromJson(String json, String fieldPath, Map<String, JsonElement> jsonCache) {
|
||||
try {
|
||||
JsonElement el = new JsonParser().parse(json);
|
||||
JsonElement el = parseJsonCached(json, jsonCache);
|
||||
for (String part : fieldPath.split("\\.", -1)) {
|
||||
if (!el.isJsonObject()) return null;
|
||||
el = el.getAsJsonObject().get(part);
|
||||
@@ -312,13 +328,42 @@ public class TemplateAdapterErrorMsgHandler implements AdapterErrorMessageHandle
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON 문자열을 파싱한다. render 1회 범위의 캐시가 있으면 재사용한다.
|
||||
* 같은 요청 전문에서 여러 필드를 뽑을 때(BANK_HEADER 13개 항목 등) 파싱이 1회로 줄어든다.
|
||||
* 파싱 실패도 JsonNull 로 캐시해 같은 문자열을 반복 파싱하지 않는다
|
||||
* (JsonNull 은 isJsonObject() 가 false 라 호출부에서 자연히 null 이 된다).
|
||||
*/
|
||||
JsonElement parseJsonCached(String json, Map<String, JsonElement> jsonCache) {
|
||||
if (jsonCache != null) {
|
||||
JsonElement cached = jsonCache.get(json);
|
||||
if (cached != null) return cached;
|
||||
}
|
||||
|
||||
JsonElement parsed;
|
||||
try {
|
||||
parsed = new JsonParser().parse(json);
|
||||
} catch (Exception e) {
|
||||
parsed = JsonNull.INSTANCE;
|
||||
}
|
||||
if (parsed == null) {
|
||||
parsed = JsonNull.INSTANCE;
|
||||
}
|
||||
|
||||
if (jsonCache != null) {
|
||||
jsonCache.put(json, parsed);
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* ${callprop[경로]} 또는 ${callprop[경로]:기본값} 처리.
|
||||
* 1. 표준전문 경로로 callProp 키를 동적으로 결정한다.
|
||||
* 2. 결정된 키로 callProp 에서 값을 조회한다.
|
||||
* 3. 키 또는 값을 찾지 못하면 기본값(없으면 빈 문자열)을 반환한다.
|
||||
*/
|
||||
private String resolveIndirectCallProp(String expr, StandardMessage msg, Properties callProp) {
|
||||
private String resolveIndirectCallProp(String expr, StandardMessage msg, Properties callProp,
|
||||
Map<String, JsonElement> jsonCache) {
|
||||
int closeIdx = expr.indexOf(']');
|
||||
if (closeIdx < 0) return "";
|
||||
|
||||
@@ -333,7 +378,7 @@ public class TemplateAdapterErrorMsgHandler implements AdapterErrorMessageHandle
|
||||
if (StringUtils.isBlank(key)) return defaultVal;
|
||||
if (callProp == null) return defaultVal;
|
||||
|
||||
String value = resolveCallProp(callProp, key);
|
||||
String value = resolveCallProp(callProp, key, jsonCache);
|
||||
return value != null ? value : defaultVal;
|
||||
}
|
||||
|
||||
@@ -341,9 +386,13 @@ public class TemplateAdapterErrorMsgHandler implements AdapterErrorMessageHandle
|
||||
* Properties 체인을 점(.) 구분자로 재귀 탐색한다.
|
||||
* - 첫 세그먼트의 값이 Properties 이면 나머지 경로로 재귀
|
||||
* - String 이면 반환, 그 외 Object 이면 toString() 반환
|
||||
* - 첫 세그먼트 값이 Properties 가 아닌 경우 전체 keyPath 로 폴백 조회
|
||||
* - 첫 세그먼트 값이 Properties 가 아닌 경우 전체 keyPath 를 키로 폴백 조회
|
||||
* - 폴백까지 실패하면 첫 세그먼트 값을 JSON 으로 보고 나머지 경로로 필드를 추출한다.
|
||||
* callProp 에 JSON 문자열로 실려오는 값(요청 전문 INBOUND_REQUEST_MESSAGE 등)을
|
||||
* 표준전문 경로(resolveMessagePath)와 같은 규칙으로 참조하기 위한 처리.
|
||||
* 예) ${callprop.INBOUND_REQUEST_MESSAGE.BANK_HEADER.TrSeqNo}
|
||||
*/
|
||||
private String resolveCallProp(Properties props, String keyPath) {
|
||||
private String resolveCallProp(Properties props, String keyPath, Map<String, JsonElement> jsonCache) {
|
||||
int dotIdx = keyPath.indexOf('.');
|
||||
if (dotIdx < 0) {
|
||||
Object val = props.get(keyPath);
|
||||
@@ -356,14 +405,22 @@ public class TemplateAdapterErrorMsgHandler implements AdapterErrorMessageHandle
|
||||
String rest = keyPath.substring(dotIdx + 1);
|
||||
Object val = props.get(first);
|
||||
if (val instanceof Properties) {
|
||||
return resolveCallProp((Properties) val, rest);
|
||||
return resolveCallProp((Properties) val, rest, jsonCache);
|
||||
}
|
||||
|
||||
// 중간 값이 Properties 가 아닌 경우: 전체 keyPath 를 키로 폴백
|
||||
// 중간 값이 Properties 가 아닌 경우: 전체 keyPath 를 키로 폴백 (기존 동작 유지)
|
||||
Object direct = props.get(keyPath);
|
||||
if (direct == null) return null;
|
||||
if (direct instanceof String) return (String) direct;
|
||||
return direct.toString();
|
||||
if (direct != null) {
|
||||
if (direct instanceof String) return (String) direct;
|
||||
return direct.toString();
|
||||
}
|
||||
|
||||
// 폴백도 실패: 첫 세그먼트 값이 JSON 문자열이면 나머지 경로로 필드 추출
|
||||
if (val != null) {
|
||||
String json = (val instanceof String) ? (String) val : val.toString();
|
||||
return extractFromJson(json, rest, jsonCache);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -780,8 +780,11 @@ public class ExceptionHandler {
|
||||
logger.warn("ExceptionHandler] errorSyncSend coordinateSetStandardMessageError 처리 실패: " + e.getMessage());
|
||||
}
|
||||
|
||||
// callProp 은 RequestProcessor 에서 EAIMessage 에 실어둔 거래 Properties 다.
|
||||
// (요청 전문 INBOUND_REQUEST_MESSAGE 등 참조 → 템플릿의 ${callprop.*} 치환에 필요)
|
||||
Object responseObj = handler.generateNonStandardInternalErrorResponseMessage(
|
||||
sngSysItfTp, inboundAdapterVO.getName(), null, tmpMsg, eaiMessage);
|
||||
sngSysItfTp, inboundAdapterVO.getName(), eaiMessage.getCallProp(), tmpMsg,
|
||||
eaiMessage);
|
||||
if (responseObj != null) {
|
||||
resultEAIMessage = eaiMessage;
|
||||
try {
|
||||
|
||||
+201
@@ -3,11 +3,14 @@ package com.eactive.eai.adapter.handler;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -30,6 +33,8 @@ import com.eactive.eai.common.util.ApplicationContextProvider;
|
||||
import com.eactive.eai.message.StandardItem;
|
||||
import com.eactive.eai.message.StandardMessage;
|
||||
import com.eactive.eai.message.StandardType;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
|
||||
/**
|
||||
* TemplateAdapterErrorMsgHandler 단위테스트
|
||||
@@ -350,6 +355,202 @@ class TemplateAdapterErrorMsgHandlerTest {
|
||||
}
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// callProp JSON 문자열 참조 ${callprop.키.JSON경로}
|
||||
// ================================================================
|
||||
|
||||
@Nested
|
||||
@DisplayName("callProp JSON 문자열 참조 ${callprop.키.JSON경로}")
|
||||
class CallPropJsonSubstitution {
|
||||
|
||||
/** 쿠콘 공통부(BANK_HEADER)를 포함한 요청 전문 */
|
||||
private static final String REQ_MESSAGE =
|
||||
"{\"BANK_HEADER\":{"
|
||||
+ "\"MsgLen\":\"000094\","
|
||||
+ "\"BsDsCd\":\"API\","
|
||||
+ "\"PatIsCd\":\"034\","
|
||||
+ "\"FinIsCd\":\"0000000001\","
|
||||
+ "\"TxCd\":\"0400\","
|
||||
+ "\"TrCd\":\"500\","
|
||||
+ "\"TrSeqNo\":\"000000000001\","
|
||||
+ "\"SndRcvFlg\":\"B\","
|
||||
+ "\"TrDt\":\"20260923102030\","
|
||||
+ "\"RepCd\":\"\","
|
||||
+ "\"EchAr\":\"ECHO0001\","
|
||||
+ "\"FintechMarkChnlCd\":\"001\","
|
||||
+ "\"FillerC\":\"\"},"
|
||||
+ "\"MSG\":{\"acctNo\":\"1234567890\"}}";
|
||||
|
||||
private Properties callPropWithRequest() {
|
||||
Properties callProp = new Properties();
|
||||
callProp.setProperty("INBOUND_REQUEST_MESSAGE", REQ_MESSAGE);
|
||||
return callProp;
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("JSON 문자열 값을 점(.) 경로로 드릴다운")
|
||||
void callProp_JSON_드릴다운() {
|
||||
StandardMessage msg = buildMsg("E001", "오류", "", null);
|
||||
|
||||
assertEquals("000000000001", handler.render(
|
||||
"${callprop.INBOUND_REQUEST_MESSAGE.BANK_HEADER.TrSeqNo}", msg, callPropWithRequest()));
|
||||
assertEquals("034", handler.render(
|
||||
"${callprop.INBOUND_REQUEST_MESSAGE.BANK_HEADER.PatIsCd}", msg, callPropWithRequest()));
|
||||
assertEquals("ECHO0001", handler.render(
|
||||
"${callprop.INBOUND_REQUEST_MESSAGE.BANK_HEADER.EchAr}", msg, callPropWithRequest()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("오류응답 템플릿 – BANK_HEADER 요청값 에코 + RepCd 는 표준전문 값")
|
||||
void callProp_JSON_BANK_HEADER_에코() {
|
||||
StandardMessage msg = buildMsg("4000", "처리오류", "", null);
|
||||
String template = "{\"BANK_HEADER\":{"
|
||||
+ "\"MsgLen\":\"\","
|
||||
+ "\"BsDsCd\":\"${callprop.INBOUND_REQUEST_MESSAGE.BANK_HEADER.BsDsCd:API}\","
|
||||
+ "\"PatIsCd\":\"${callprop.INBOUND_REQUEST_MESSAGE.BANK_HEADER.PatIsCd}\","
|
||||
+ "\"FinIsCd\":\"${callprop.INBOUND_REQUEST_MESSAGE.BANK_HEADER.FinIsCd}\","
|
||||
+ "\"TxCd\":\"0410\","
|
||||
+ "\"TrCd\":\"${callprop.INBOUND_REQUEST_MESSAGE.BANK_HEADER.TrCd}\","
|
||||
+ "\"TrSeqNo\":\"${callprop.INBOUND_REQUEST_MESSAGE.BANK_HEADER.TrSeqNo}\","
|
||||
+ "\"SndRcvFlg\":\"${callprop.INBOUND_REQUEST_MESSAGE.BANK_HEADER.SndRcvFlg}\","
|
||||
+ "\"TrDt\":\"${callprop.INBOUND_REQUEST_MESSAGE.BANK_HEADER.TrDt}\","
|
||||
+ "\"RepCd\":\"${MSG.MAIN_MSG.outp_msg_cd}\","
|
||||
+ "\"EchAr\":\"${callprop.INBOUND_REQUEST_MESSAGE.BANK_HEADER.EchAr}\","
|
||||
+ "\"FintechMarkChnlCd\":\"${callprop.INBOUND_REQUEST_MESSAGE.BANK_HEADER.FintechMarkChnlCd}\","
|
||||
+ "\"FillerC\":\"${callprop.INBOUND_REQUEST_MESSAGE.BANK_HEADER.FillerC}\"}}";
|
||||
|
||||
String expected = "{\"BANK_HEADER\":{"
|
||||
+ "\"MsgLen\":\"\","
|
||||
+ "\"BsDsCd\":\"API\","
|
||||
+ "\"PatIsCd\":\"034\","
|
||||
+ "\"FinIsCd\":\"0000000001\","
|
||||
+ "\"TxCd\":\"0410\","
|
||||
+ "\"TrCd\":\"500\","
|
||||
+ "\"TrSeqNo\":\"000000000001\","
|
||||
+ "\"SndRcvFlg\":\"B\","
|
||||
+ "\"TrDt\":\"20260923102030\","
|
||||
+ "\"RepCd\":\"4000\","
|
||||
+ "\"EchAr\":\"ECHO0001\","
|
||||
+ "\"FintechMarkChnlCd\":\"001\","
|
||||
+ "\"FillerC\":\"\"}}";
|
||||
|
||||
assertEquals(expected, handler.render(template, msg, callPropWithRequest()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("선행 0 이 있는 값은 문자열 그대로 유지")
|
||||
void callProp_JSON_선행0_유지() {
|
||||
StandardMessage msg = buildMsg("E001", "오류", "", null);
|
||||
|
||||
assertEquals("000094", handler.render(
|
||||
"${callprop.INBOUND_REQUEST_MESSAGE.BANK_HEADER.MsgLen}", msg, callPropWithRequest()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("최종 노드가 오브젝트면 JSON 문자열 그대로 반환")
|
||||
void callProp_JSON_오브젝트_반환() {
|
||||
StandardMessage msg = buildMsg("E001", "오류", "", null);
|
||||
|
||||
assertEquals("{\"acctNo\":\"1234567890\"}", handler.render(
|
||||
"${callprop.INBOUND_REQUEST_MESSAGE.MSG}", msg, callPropWithRequest()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("JSON 에 없는 경로는 빈 문자열 / 기본값")
|
||||
void callProp_JSON_없는경로() {
|
||||
StandardMessage msg = buildMsg("E001", "오류", "", null);
|
||||
|
||||
assertEquals("", handler.render(
|
||||
"${callprop.INBOUND_REQUEST_MESSAGE.BANK_HEADER.NONE_FIELD}", msg, callPropWithRequest()));
|
||||
assertEquals("DEF", handler.render(
|
||||
"${callprop.INBOUND_REQUEST_MESSAGE.BANK_HEADER.NONE_FIELD:DEF}", msg, callPropWithRequest()));
|
||||
assertEquals("DEF", handler.render(
|
||||
"${callprop.INBOUND_REQUEST_MESSAGE.NONE_GROUP.TrSeqNo:DEF}", msg, callPropWithRequest()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("값이 JSON 이 아니면 빈 문자열 / 기본값 (예외 없음)")
|
||||
void callProp_JSON_아닌값() {
|
||||
StandardMessage msg = buildMsg("E001", "오류", "", null);
|
||||
Properties callProp = new Properties();
|
||||
callProp.setProperty("INBOUND_REQUEST_MESSAGE", "key1=value1&key2=value2");
|
||||
|
||||
assertEquals("", handler.render(
|
||||
"${callprop.INBOUND_REQUEST_MESSAGE.BANK_HEADER.TrSeqNo}", msg, callProp));
|
||||
assertEquals("DEF", handler.render(
|
||||
"${callprop.INBOUND_REQUEST_MESSAGE.BANK_HEADER.TrSeqNo:DEF}", msg, callProp));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("깨진 JSON 이어도 예외 없이 기본값 반환")
|
||||
void callProp_JSON_파싱실패() {
|
||||
StandardMessage msg = buildMsg("E001", "오류", "", null);
|
||||
Properties callProp = new Properties();
|
||||
callProp.setProperty("INBOUND_REQUEST_MESSAGE", "{\"BANK_HEADER\":{\"TrSeqNo\":");
|
||||
|
||||
assertEquals("DEF", handler.render(
|
||||
"${callprop.INBOUND_REQUEST_MESSAGE.BANK_HEADER.TrSeqNo:DEF}", msg, callProp));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("전체 keyPath 로 등록된 값이 JSON 드릴다운보다 우선 (기존 동작 유지)")
|
||||
void callProp_전체keyPath_우선() {
|
||||
StandardMessage msg = buildMsg("E001", "오류", "", null);
|
||||
Properties callProp = callPropWithRequest();
|
||||
callProp.setProperty("INBOUND_REQUEST_MESSAGE.BANK_HEADER.TrSeqNo", "DIRECT_KEY_VALUE");
|
||||
|
||||
assertEquals("DIRECT_KEY_VALUE", handler.render(
|
||||
"${callprop.INBOUND_REQUEST_MESSAGE.BANK_HEADER.TrSeqNo}", msg, callProp));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("중첩 Properties 안의 JSON 문자열도 드릴다운")
|
||||
void callProp_중첩Properties_안의_JSON() {
|
||||
Properties sub = new Properties();
|
||||
sub.setProperty("BODY", REQ_MESSAGE);
|
||||
|
||||
Properties callProp = new Properties();
|
||||
callProp.put("INBOUND", sub);
|
||||
|
||||
StandardMessage msg = buildMsg("E001", "오류", "", null);
|
||||
|
||||
assertEquals("000000000001", handler.render(
|
||||
"${callprop.INBOUND.BODY.BANK_HEADER.TrSeqNo}", msg, callProp));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("같은 JSON 문자열은 render 1회 범위에서 한 번만 파싱한다")
|
||||
void callProp_JSON_파싱캐시() {
|
||||
Map<String, JsonElement> cache = new HashMap<>();
|
||||
|
||||
JsonElement first = handler.parseJsonCached(REQ_MESSAGE, cache);
|
||||
JsonElement second = handler.parseJsonCached(REQ_MESSAGE, cache);
|
||||
|
||||
assertEquals(1, cache.size());
|
||||
assertSame(first, second);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("파싱 캐시가 없어도(null) 동작한다")
|
||||
void callProp_JSON_캐시없음() {
|
||||
assertNotNull(handler.parseJsonCached(REQ_MESSAGE, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("파싱 실패도 캐시해 재파싱하지 않는다")
|
||||
void callProp_JSON_파싱실패_캐시() {
|
||||
Map<String, JsonElement> cache = new HashMap<>();
|
||||
String broken = "{\"BANK_HEADER\":{\"TrSeqNo\":";
|
||||
|
||||
JsonElement first = handler.parseJsonCached(broken, cache);
|
||||
JsonElement second = handler.parseJsonCached(broken, cache);
|
||||
|
||||
assertEquals(1, cache.size());
|
||||
assertSame(first, second);
|
||||
assertSame(JsonNull.INSTANCE, first);
|
||||
}
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// callProp 간접 참조 ${callprop[표준전문경로]} / ${callprop[경로]:기본값}
|
||||
// ================================================================
|
||||
|
||||
Reference in New Issue
Block a user