feat: 모든 변수 표현식에 :기본값 문법 추가
- ${callprop.KEY:default} - 직접 참조 기본값
- ${callprop[MSG.path]:default} - 간접 참조 기본값
- ${MSG.path:default} - 표준전문 경로 기본값
키/경로 미존재 또는 callProp null 시 기본값 반환, 기본값 미지정 시 빈 문자열.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+139
@@ -160,6 +160,30 @@ class TemplateAdapterErrorMsgHandlerTest {
|
||||
|
||||
assertEquals("상세설명입니다", handler.render("${MSG.MAIN_MSG.outp_msg_desc}", msg, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("경로:기본값 – 경로 존재 시 값 반환")
|
||||
void 표준전문_기본값_경로존재() {
|
||||
StandardMessage msg = buildMsg("E001", "오류", "", null);
|
||||
|
||||
assertEquals("E001", handler.render("${MSG.MAIN_MSG.outp_msg_cd:DEFAULT}", msg, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("경로:기본값 – 경로 없으면 기본값 반환")
|
||||
void 표준전문_기본값_경로없음() {
|
||||
StandardMessage msg = buildMsg("E001", "오류", "", null);
|
||||
|
||||
assertEquals("UNKNOWN", handler.render("${NONE.PATH:UNKNOWN}", msg, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("경로:기본값 – 기본값이 빈 문자열")
|
||||
void 표준전문_기본값_빈문자열() {
|
||||
StandardMessage msg = buildMsg("E001", "오류", "", null);
|
||||
|
||||
assertEquals("", handler.render("${NONE.PATH:}", msg, null));
|
||||
}
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
@@ -273,6 +297,121 @@ class TemplateAdapterErrorMsgHandlerTest {
|
||||
|
||||
assertEquals("", handler.render("${callprop.SUB.NONE_KEY}", msg, callProp));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("callprop.키:기본값 – 키 존재 시 값 반환")
|
||||
void callProp_직접_기본값_키존재() {
|
||||
StandardMessage msg = buildMsg("E001", "오류", "", null);
|
||||
Properties callProp = props("ADAPTER_NAME", "MY_ADAPTER");
|
||||
|
||||
assertEquals("MY_ADAPTER", handler.render("${callprop.ADAPTER_NAME:DEFAULT}", msg, callProp));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("callprop.키:기본값 – 키 없으면 기본값 반환")
|
||||
void callProp_직접_기본값_키없음() {
|
||||
StandardMessage msg = buildMsg("E001", "오류", "", null);
|
||||
Properties callProp = new Properties();
|
||||
|
||||
assertEquals("DEFAULT_VAL", handler.render("${callprop.NONE_KEY:DEFAULT_VAL}", msg, callProp));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("callprop.키:기본값 – callProp null 이면 기본값 반환")
|
||||
void callProp_직접_기본값_null() {
|
||||
StandardMessage msg = buildMsg("E001", "오류", "", null);
|
||||
|
||||
assertEquals("FALLBACK", handler.render("${callprop.ADAPTER_NAME:FALLBACK}", msg, null));
|
||||
}
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// callProp 간접 참조 ${callprop[표준전문경로]} / ${callprop[경로]:기본값}
|
||||
// ================================================================
|
||||
|
||||
@Nested
|
||||
@DisplayName("callProp 간접 참조 ${callprop[경로]}")
|
||||
class IndirectCallPropSubstitution {
|
||||
|
||||
/** 표준전문에 cp_key 필드가 있는 메시지 */
|
||||
private StandardMessage buildMsgWithKey(String cpKey, String errCode) {
|
||||
StandardMessage msg = buildMsg(errCode, "오류", "", null);
|
||||
// MSG 그룹 아래 cp_key 필드 추가
|
||||
StandardItem msgGroup = msg.findItem("MSG");
|
||||
if (msgGroup != null) {
|
||||
msgGroup.addItem(field("cp_key", cpKey));
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("표준전문 경로 값으로 callProp 키를 결정해 값 조회")
|
||||
void 간접_참조_정상() {
|
||||
StandardMessage msg = buildMsgWithKey("ADAPTER_NAME", "E001");
|
||||
Properties callProp = props("ADAPTER_NAME", "MY_ADAPTER");
|
||||
String template = "${callprop[MSG.cp_key]}";
|
||||
|
||||
assertEquals("MY_ADAPTER", handler.render(template, msg, callProp));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("표준전문 경로 값이 없으면 기본값 반환")
|
||||
void 표준전문_경로_없으면_기본값() {
|
||||
StandardMessage msg = buildMsg("E001", "오류", "", null);
|
||||
Properties callProp = props("ADAPTER_NAME", "MY_ADAPTER");
|
||||
String template = "${callprop[MSG.NONE_KEY]:DEFAULT_ADAPTER}";
|
||||
|
||||
assertEquals("DEFAULT_ADAPTER", handler.render(template, msg, callProp));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("callProp 에 해당 키 없으면 기본값 반환")
|
||||
void callProp_키_없으면_기본값() {
|
||||
StandardMessage msg = buildMsgWithKey("MISSING_KEY", "E001");
|
||||
Properties callProp = props("OTHER_KEY", "OTHER_VALUE");
|
||||
String template = "${callprop[MSG.cp_key]:FALLBACK}";
|
||||
|
||||
assertEquals("FALLBACK", handler.render(template, msg, callProp));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("기본값 미지정 시 빈 문자열")
|
||||
void 기본값_없으면_빈문자열() {
|
||||
StandardMessage msg = buildMsg("E001", "오류", "", null);
|
||||
Properties callProp = props("ADAPTER_NAME", "MY_ADAPTER");
|
||||
String template = "${callprop[MSG.NONE_KEY]}";
|
||||
|
||||
assertEquals("", handler.render(template, msg, callProp));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("callProp 이 null 이면 기본값 반환")
|
||||
void callProp_null_기본값() {
|
||||
StandardMessage msg = buildMsgWithKey("ADAPTER_NAME", "E001");
|
||||
String template = "${callprop[MSG.cp_key]:NO_PROP}";
|
||||
|
||||
assertEquals("NO_PROP", handler.render(template, msg, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("기본값이 빈 문자열인 경우")
|
||||
void 기본값이_빈문자열() {
|
||||
StandardMessage msg = buildMsg("E001", "오류", "", null);
|
||||
Properties callProp = new Properties();
|
||||
String template = "${callprop[MSG.NONE_KEY]:}";
|
||||
|
||||
assertEquals("", handler.render(template, msg, callProp));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("간접 참조와 직접 참조 혼합")
|
||||
void 간접_직접_혼합() {
|
||||
StandardMessage msg = buildMsgWithKey("IF_ID_KEY", "E001");
|
||||
Properties callProp = props("IF_ID_KEY", "SVC_001", "ADAPTER_NAME", "MY_ADAPTER");
|
||||
String template = "{\"adapter\":\"${callprop.ADAPTER_NAME}\",\"ifId\":\"${callprop[MSG.cp_key]}\"}";
|
||||
|
||||
assertEquals("{\"adapter\":\"MY_ADAPTER\",\"ifId\":\"SVC_001\"}", handler.render(template, msg, callProp));
|
||||
}
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
|
||||
Reference in New Issue
Block a user