fix: GenerateMethod 테스트에서 AdapterPropManager → PropManager 목 객체로 변경
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+73
-10
@@ -15,7 +15,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import com.eactive.eai.adapter.AdapterPropManager;
|
||||
import com.eactive.eai.common.property.PropManager;
|
||||
import com.eactive.eai.common.util.ApplicationContextProvider;
|
||||
import com.eactive.eai.message.StandardItem;
|
||||
import com.eactive.eai.message.StandardMessage;
|
||||
@@ -26,7 +26,7 @@ import com.eactive.eai.message.StandardType;
|
||||
*
|
||||
* - render() : package-private 이므로 같은 패키지에서 직접 호출
|
||||
* - generateNonStandardErrorResponseMessage() : ApplicationContextProvider 에
|
||||
* mock ApplicationContext 를 리플렉션으로 주입하여 AdapterPropManager 격리
|
||||
* mock ApplicationContext 를 리플렉션으로 주입하여 PropManager 격리
|
||||
*/
|
||||
class TemplateAdapterErrorMsgHandlerTest {
|
||||
|
||||
@@ -210,6 +210,69 @@ class TemplateAdapterErrorMsgHandlerTest {
|
||||
|
||||
assertEquals("", handler.render("${callprop.ADAPTER_NAME}", msg, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("callProp 값이 Properties 인 경우 중첩 탐색")
|
||||
void callProp_중첩_Properties() {
|
||||
Properties sub = new Properties();
|
||||
sub.setProperty("IF_ID", "SVC001");
|
||||
sub.setProperty("SVC_NM", "조회서비스");
|
||||
|
||||
Properties callProp = new Properties();
|
||||
callProp.put("OUTBOUND", sub);
|
||||
callProp.setProperty("ADAPTER_NAME", "MY_ADAPTER");
|
||||
|
||||
StandardMessage msg = buildMsg("E001", "오류", "", null);
|
||||
String template = "{\"adapter\":\"${callprop.ADAPTER_NAME}\",\"ifId\":\"${callprop.OUTBOUND.IF_ID}\",\"svcNm\":\"${callprop.OUTBOUND.SVC_NM}\"}";
|
||||
|
||||
String result = handler.render(template, msg, callProp);
|
||||
|
||||
assertEquals("{\"adapter\":\"MY_ADAPTER\",\"ifId\":\"SVC001\",\"svcNm\":\"조회서비스\"}", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("중첩 Properties 3단계 탐색")
|
||||
void callProp_3단계_중첩() {
|
||||
Properties level2 = new Properties();
|
||||
level2.setProperty("CODE", "L2CODE");
|
||||
|
||||
Properties level1 = new Properties();
|
||||
level1.put("LEVEL2", level2);
|
||||
|
||||
Properties callProp = new Properties();
|
||||
callProp.put("LEVEL1", level1);
|
||||
|
||||
StandardMessage msg = buildMsg("E001", "오류", "", null);
|
||||
|
||||
assertEquals("L2CODE", handler.render("${callprop.LEVEL1.LEVEL2.CODE}", msg, callProp));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("중간 값이 Properties 가 아니면 전체 keyPath 로 폴백 조회")
|
||||
void callProp_중간값_비Properties_폴백() {
|
||||
Properties callProp = new Properties();
|
||||
callProp.setProperty("A.B", "FALLBACK_VALUE"); // 점 포함 키
|
||||
callProp.setProperty("A", "NOT_PROPS"); // String 값
|
||||
|
||||
StandardMessage msg = buildMsg("E001", "오류", "", null);
|
||||
|
||||
// A 는 String 이므로 Properties 가 아님 → "A.B" 전체 키로 폴백
|
||||
assertEquals("FALLBACK_VALUE", handler.render("${callprop.A.B}", msg, callProp));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("중첩 Properties 에서 없는 키는 빈 문자열")
|
||||
void callProp_중첩_없는키() {
|
||||
Properties sub = new Properties();
|
||||
sub.setProperty("EXIST", "VALUE");
|
||||
|
||||
Properties callProp = new Properties();
|
||||
callProp.put("SUB", sub);
|
||||
|
||||
StandardMessage msg = buildMsg("E001", "오류", "", null);
|
||||
|
||||
assertEquals("", handler.render("${callprop.SUB.NONE_KEY}", msg, callProp));
|
||||
}
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
@@ -341,16 +404,16 @@ class TemplateAdapterErrorMsgHandlerTest {
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// generateNonStandardErrorResponseMessage – AdapterPropManager mock
|
||||
// generateNonStandardErrorResponseMessage – PropManager mock
|
||||
// ================================================================
|
||||
|
||||
@Nested
|
||||
@DisplayName("generateNonStandardErrorResponseMessage")
|
||||
class GenerateMethod {
|
||||
|
||||
private void injectMockPropManager(AdapterPropManager mockPropManager) throws Exception {
|
||||
private void injectMockPropManager(PropManager mockPropManager) throws Exception {
|
||||
ApplicationContext mockCtx = Mockito.mock(ApplicationContext.class);
|
||||
Mockito.when(mockCtx.getBean(AdapterPropManager.class)).thenReturn(mockPropManager);
|
||||
Mockito.when(mockCtx.getBean(PropManager.class)).thenReturn(mockPropManager);
|
||||
Field ctxField = ApplicationContextProvider.class.getDeclaredField("context");
|
||||
ctxField.setAccessible(true);
|
||||
ctxField.set(null, mockCtx);
|
||||
@@ -359,7 +422,7 @@ class TemplateAdapterErrorMsgHandlerTest {
|
||||
@Test
|
||||
@DisplayName("템플릿 미설정 시 null 반환")
|
||||
void 템플릿_없으면_null() throws Exception {
|
||||
AdapterPropManager mockProp = Mockito.mock(AdapterPropManager.class);
|
||||
PropManager mockProp = Mockito.mock(PropManager.class);
|
||||
Mockito.when(mockProp.getProperty(anyString(), anyString())).thenReturn(null);
|
||||
injectMockPropManager(mockProp);
|
||||
|
||||
@@ -373,7 +436,7 @@ class TemplateAdapterErrorMsgHandlerTest {
|
||||
@Test
|
||||
@DisplayName("빈 템플릿 시 null 반환")
|
||||
void 빈_템플릿_null() throws Exception {
|
||||
AdapterPropManager mockProp = Mockito.mock(AdapterPropManager.class);
|
||||
PropManager mockProp = Mockito.mock(PropManager.class);
|
||||
Mockito.when(mockProp.getProperty(anyString(), anyString())).thenReturn(" ");
|
||||
injectMockPropManager(mockProp);
|
||||
|
||||
@@ -388,7 +451,7 @@ class TemplateAdapterErrorMsgHandlerTest {
|
||||
@DisplayName("템플릿 설정 시 StandardMessage 치환 결과 반환")
|
||||
void 템플릿_stdmsg_치환() throws Exception {
|
||||
String template = "{\"code\":\"${MSG.MAIN_MSG.outp_msg_cd}\"}";
|
||||
AdapterPropManager mockProp = Mockito.mock(AdapterPropManager.class);
|
||||
PropManager mockProp = Mockito.mock(PropManager.class);
|
||||
Mockito.when(mockProp.getProperty(
|
||||
eq(TemplateAdapterErrorMsgHandler.PROP_GROUP),
|
||||
eq("MY_GROUP.template"))).thenReturn(template);
|
||||
@@ -405,7 +468,7 @@ class TemplateAdapterErrorMsgHandlerTest {
|
||||
@DisplayName("callProp 값이 템플릿에 치환되어 반환")
|
||||
void 템플릿_callProp_치환() throws Exception {
|
||||
String template = "{\"adapter\":\"${callprop.ADAPTER_NAME}\",\"code\":\"${MSG.MAIN_MSG.outp_msg_cd}\"}";
|
||||
AdapterPropManager mockProp = Mockito.mock(AdapterPropManager.class);
|
||||
PropManager mockProp = Mockito.mock(PropManager.class);
|
||||
Mockito.when(mockProp.getProperty(
|
||||
eq(TemplateAdapterErrorMsgHandler.PROP_GROUP),
|
||||
eq("MY_GROUP.template"))).thenReturn(template);
|
||||
@@ -423,7 +486,7 @@ class TemplateAdapterErrorMsgHandlerTest {
|
||||
@Test
|
||||
@DisplayName("템플릿 키는 {adapterGroupId}.template 형식으로 조회")
|
||||
void 템플릿_키_형식_검증() throws Exception {
|
||||
AdapterPropManager mockProp = Mockito.mock(AdapterPropManager.class);
|
||||
PropManager mockProp = Mockito.mock(PropManager.class);
|
||||
Mockito.when(mockProp.getProperty(anyString(), anyString())).thenReturn(null);
|
||||
injectMockPropManager(mockProp);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user