menu 개발 중. 언어 변경 시 반영 않됨
This commit is contained in:
@@ -4,10 +4,8 @@ using Cysharp.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UVC.Data;
|
||||
|
||||
@@ -46,22 +44,33 @@ namespace UVC.Tests.Data
|
||||
Setup();
|
||||
|
||||
Debug.Log("===== HttpPipeLine 테스트 시작 =====");
|
||||
RunTest(nameof(Add_NewInfo_AddedSuccessfully), Add_NewInfo_AddedSuccessfully);
|
||||
RunTest(nameof(Add_ExistingInfo_UpdatesExistingEntry), Add_ExistingInfo_UpdatesExistingEntry);
|
||||
await RunTestAsync(nameof(Remove_ExistingInfo_RemovedSuccessfullyAsync), Remove_ExistingInfo_RemovedSuccessfullyAsync);
|
||||
await RunTestAsync(nameof(Remove_NonExistingInfo_DoesNothing), Remove_NonExistingInfo_DoesNothing);
|
||||
RunTest(nameof(Excute_WithNonExistingKey_DoesNothing), Excute_WithNonExistingKey_DoesNothing);
|
||||
await RunTestAsync(nameof(Excute_WithJObjectResponse_ProcessesDataCorrectly), Excute_WithJObjectResponse_ProcessesDataCorrectly);
|
||||
await RunTestAsync(nameof(Excute_WithJArrayResponse_ProcessesDataCorrectly), Excute_WithJArrayResponse_ProcessesDataCorrectly);
|
||||
await RunTestAsync(nameof(Test_Excute_AgvDataParsing), Test_Excute_AgvDataParsing);
|
||||
await RunTestAsync(nameof(Test_Excute_AlarmDataParsing), Test_Excute_AlarmDataParsing);
|
||||
await RunTestAsync(nameof(Test_Excute_MultipleDataTypes), Test_Excute_MultipleDataTypes);
|
||||
await RunTestAsync(nameof(Test_Excute_CarrierDataParsing), Test_Excute_CarrierDataParsing);
|
||||
await RunTestAsync(nameof(Test_Excute_BaseInfoDataParsing), Test_Excute_BaseInfoDataParsing);
|
||||
await RunTestAsync(nameof(Test_Excute_WithRepeatExecution), Test_Excute_WithRepeatExecution);
|
||||
await RunTestAsync(nameof(Test_StopRepeat_StopsExecutionCorrectly), Test_StopRepeat_StopsExecutionCorrectly);
|
||||
await RunTestAsync(nameof(Test_MultipleRepeatingRequests_ManagedIndependently), Test_MultipleRepeatingRequests_ManagedIndependently);
|
||||
await RunTestAsync(nameof(Test_RepeatWithCount_StopsAutomatically), Test_RepeatWithCount_StopsAutomatically);
|
||||
//RunTest(nameof(Add_NewInfo_AddedSuccessfully), Add_NewInfo_AddedSuccessfully);
|
||||
//RunTest(nameof(Add_ExistingInfo_UpdatesExistingEntry), Add_ExistingInfo_UpdatesExistingEntry);
|
||||
//await RunTestAsync(nameof(Remove_ExistingInfo_RemovedSuccessfullyAsync), Remove_ExistingInfo_RemovedSuccessfullyAsync);
|
||||
//await RunTestAsync(nameof(Remove_NonExistingInfo_DoesNothing), Remove_NonExistingInfo_DoesNothing);
|
||||
//RunTest(nameof(Excute_WithNonExistingKey_DoesNothing), Excute_WithNonExistingKey_DoesNothing);
|
||||
//await RunTestAsync(nameof(Excute_WithJObjectResponse_ProcessesDataCorrectly), Excute_WithJObjectResponse_ProcessesDataCorrectly);
|
||||
//await RunTestAsync(nameof(Excute_WithJArrayResponse_ProcessesDataCorrectly), Excute_WithJArrayResponse_ProcessesDataCorrectly);
|
||||
//await RunTestAsync(nameof(Test_Excute_AgvDataParsing), Test_Excute_AgvDataParsing);
|
||||
//await RunTestAsync(nameof(Test_Excute_AlarmDataParsing), Test_Excute_AlarmDataParsing);
|
||||
//await RunTestAsync(nameof(Test_Excute_MultipleDataTypes), Test_Excute_MultipleDataTypes);
|
||||
//await RunTestAsync(nameof(Test_Excute_CarrierDataParsing), Test_Excute_CarrierDataParsing);
|
||||
//await RunTestAsync(nameof(Test_Excute_BaseInfoDataParsing), Test_Excute_BaseInfoDataParsing);
|
||||
//await RunTestAsync(nameof(Test_Excute_WithRepeatExecution), Test_Excute_WithRepeatExecution);
|
||||
//await RunTestAsync(nameof(Test_StopRepeat_StopsExecutionCorrectly), Test_StopRepeat_StopsExecutionCorrectly);
|
||||
//await RunTestAsync(nameof(Test_MultipleRepeatingRequests_ManagedIndependently), Test_MultipleRepeatingRequests_ManagedIndependently);
|
||||
//await RunTestAsync(nameof(Test_RepeatWithCount_StopsAutomatically), Test_RepeatWithCount_StopsAutomatically);
|
||||
|
||||
// HttpResponseMask 테스트 추가
|
||||
Debug.Log("===== HttpResponseMask 테스트 시작 =====");
|
||||
RunTest(nameof(HttpResponseMask_Apply_SuccessfulResponse_ReturnsSuccessWithData), HttpResponseMask_Apply_SuccessfulResponse_ReturnsSuccessWithData);
|
||||
RunTest(nameof(HttpResponseMask_Apply_FailedResponse_WrongSuccessValue_ReturnsFailWithMessage), HttpResponseMask_Apply_FailedResponse_WrongSuccessValue_ReturnsFailWithMessage);
|
||||
RunTest(nameof(HttpResponseMask_Apply_FailedResponse_MissingSuccessKey_ReturnsFailWithMessage), HttpResponseMask_Apply_FailedResponse_MissingSuccessKey_ReturnsFailWithMessage);
|
||||
RunTest(nameof(HttpResponseMask_Apply_FailedResponse_MissingDataKey_ReturnsFailWithMessage), HttpResponseMask_Apply_FailedResponse_MissingDataKey_ReturnsFailWithMessage);
|
||||
RunTest(nameof(HttpResponseMask_Apply_SuccessfulResponse_CustomKeys_ReturnsSuccessWithData), HttpResponseMask_Apply_SuccessfulResponse_CustomKeys_ReturnsSuccessWithData);
|
||||
RunTest(nameof(HttpResponseMask_Apply_InvalidJson_ThrowsException), HttpResponseMask_Apply_InvalidJson_ThrowsException);
|
||||
Debug.Log("===== HttpResponseMask 테스트 완료 =====");
|
||||
|
||||
Debug.Log("===== HttpPipeLine 테스트 완료 =====");
|
||||
}
|
||||
|
||||
@@ -234,7 +243,7 @@ namespace UVC.Tests.Data
|
||||
// HttpPipeLineInfo 설정
|
||||
var info = new HttpPipeLineInfo("http://test.com")
|
||||
.setDataMapper(dataMapper)
|
||||
.setHandler((data) =>
|
||||
.setSuccessHandler((data) =>
|
||||
{
|
||||
handlerCalled = true;
|
||||
if (data is DataObject dataObject)
|
||||
@@ -291,7 +300,7 @@ namespace UVC.Tests.Data
|
||||
// HttpPipeLineInfo 설정
|
||||
var info = new HttpPipeLineInfo("http://test.com")
|
||||
.setDataMapper(dataMapper)
|
||||
.setHandler((data) =>
|
||||
.setSuccessHandler((data) =>
|
||||
{
|
||||
handlerCalled = true;
|
||||
receivedData = data;
|
||||
@@ -337,7 +346,7 @@ namespace UVC.Tests.Data
|
||||
// Arrange - 의도적으로 아무 것도 설정하지 않음
|
||||
|
||||
// Act & Assert - 예외가 발생하지 않아야 함
|
||||
Assert.DoesNotThrow(() => pipeLine.Excute("nonExistingKey"));
|
||||
Assert.DoesNotThrow(() => pipeLine.Excute("nonExistingKey"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -368,7 +377,7 @@ namespace UVC.Tests.Data
|
||||
// HttpPipeLineInfo 설정
|
||||
var info = new HttpPipeLineInfo(agvUrl, "get")
|
||||
.setDataMapper(dataMapper)
|
||||
.setHandler((data) =>
|
||||
.setSuccessHandler((data) =>
|
||||
{
|
||||
handlerCalled = true;
|
||||
receivedData = data;
|
||||
@@ -422,7 +431,7 @@ namespace UVC.Tests.Data
|
||||
// HttpPipeLineInfo 설정
|
||||
var info = new HttpPipeLineInfo(alarmUrl, "get")
|
||||
.setDataMapper(dataMapper)
|
||||
.setHandler((data) =>
|
||||
.setSuccessHandler((data) =>
|
||||
{
|
||||
handlerCalled = true;
|
||||
receivedData = data;
|
||||
@@ -505,7 +514,7 @@ namespace UVC.Tests.Data
|
||||
string key = item.Key;
|
||||
var info = new HttpPipeLineInfo(item.Value, "get")
|
||||
.setDataMapper(new DataMapper(dataMasks[key]))
|
||||
.setHandler((data) =>
|
||||
.setSuccessHandler((data) =>
|
||||
{
|
||||
handlerCallCount++;
|
||||
results[key] = data;
|
||||
@@ -544,7 +553,7 @@ namespace UVC.Tests.Data
|
||||
|
||||
// DataMask와 DataMapper 설정
|
||||
var dataMask = new DataMask
|
||||
{
|
||||
{
|
||||
["MAIN_CARR_ID"] = "캐리어ID",
|
||||
["SUB_CARR_ID"] = "서브ID",
|
||||
["CARR_SEQ"] = "순번",
|
||||
@@ -556,7 +565,7 @@ namespace UVC.Tests.Data
|
||||
// HttpPipeLineInfo 설정
|
||||
var info = new HttpPipeLineInfo(testUrl, "get")
|
||||
.setDataMapper(dataMapper)
|
||||
.setHandler((data) =>
|
||||
.setSuccessHandler((data) =>
|
||||
{
|
||||
handlerCalled = true;
|
||||
receivedData = data;
|
||||
@@ -634,7 +643,7 @@ namespace UVC.Tests.Data
|
||||
// HttpPipeLineInfo 설정
|
||||
var info = new HttpPipeLineInfo(baseInfoUrl, "get")
|
||||
.setDataMapper(dataMapper)
|
||||
.setHandler((data) =>
|
||||
.setSuccessHandler((data) =>
|
||||
{
|
||||
handlerCalled = true;
|
||||
receivedData = data;
|
||||
@@ -720,7 +729,7 @@ namespace UVC.Tests.Data
|
||||
// 반복 실행 설정을 포함한 HttpPipeLineInfo 생성
|
||||
var info = new HttpPipeLineInfo(testUrl, "get")
|
||||
.setDataMapper(dataMapper)
|
||||
.setHandler(async (data) =>
|
||||
.setSuccessHandler(async (data) =>
|
||||
{
|
||||
handlerCallCount++;
|
||||
if (data is DataObject dataObject)
|
||||
@@ -794,7 +803,7 @@ namespace UVC.Tests.Data
|
||||
// 무한 반복 설정을 포함한 HttpPipeLineInfo 생성
|
||||
var info = new HttpPipeLineInfo(testUrl, "get")
|
||||
.setDataMapper(dataMapper)
|
||||
.setHandler((data) => { handlerCallCount++;})
|
||||
.setSuccessHandler((data) => { handlerCallCount++; })
|
||||
.setRepeat(true, 0, repeatInterval, false); // 무한 반복 (repeatCount = 0)
|
||||
|
||||
pipeLine.UseMockup = true;
|
||||
@@ -862,12 +871,12 @@ namespace UVC.Tests.Data
|
||||
// 두 개의 반복 요청 설정
|
||||
var info1 = new HttpPipeLineInfo(testUrl1, "get")
|
||||
.setDataMapper(dataMapper)
|
||||
.setHandler((data) => { handlerCallCount1++; })
|
||||
.setSuccessHandler((data) => { handlerCallCount1++; })
|
||||
.setRepeat(true, 0, repeatInterval1, false);
|
||||
|
||||
var info2 = new HttpPipeLineInfo(testUrl2, "get")
|
||||
.setDataMapper(dataMapper)
|
||||
.setHandler((data) => { handlerCallCount2++; })
|
||||
.setSuccessHandler((data) => { handlerCallCount2++; })
|
||||
.setRepeat(true, 0, repeatInterval2, false);
|
||||
|
||||
pipeLine.UseMockup = true;
|
||||
@@ -944,7 +953,7 @@ namespace UVC.Tests.Data
|
||||
// 반복 횟수가 지정된 HttpPipeLineInfo 생성
|
||||
var info = new HttpPipeLineInfo(testUrl, "get")
|
||||
.setDataMapper(dataMapper)
|
||||
.setHandler((data) =>
|
||||
.setSuccessHandler((data) =>
|
||||
{
|
||||
handlerCallCount++;
|
||||
receivedData.Add(data);
|
||||
@@ -996,5 +1005,127 @@ namespace UVC.Tests.Data
|
||||
|
||||
return (Dictionary<string, CancellationTokenSource>)fieldInfo.GetValue(pipeLine);
|
||||
}
|
||||
|
||||
#region HttpResponseMask Tests
|
||||
|
||||
/// <summary>
|
||||
/// HttpResponseMask.Apply가 성공적인 응답을 올바르게 처리하는지 테스트합니다.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void HttpResponseMask_Apply_SuccessfulResponse_ReturnsSuccessWithData()
|
||||
{
|
||||
// Arrange
|
||||
var responseMask = new HttpResponseMask(); // 기본값 사용 (successKey="message", successValue="success", dataKey="data")
|
||||
var jsonResponse = @"{""message"": ""success"", ""data"": {""key"":""value""}}";
|
||||
var expectedData = @"{""key"":""value""}";
|
||||
|
||||
// Act
|
||||
var result = responseMask.Apply(jsonResponse);
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(result.IsSuccess, "결과가 성공이어야 합니다.");
|
||||
Assert.AreEqual(expectedData, result.Data, "추출된 데이터가 예상과 다릅니다.");
|
||||
Assert.IsNull(result.Message, "성공 시 메시지는 null이어야 합니다.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// HttpResponseMask.Apply가 잘못된 성공 값으로 실패 응답을 올바르게 처리하는지 테스트합니다.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void HttpResponseMask_Apply_FailedResponse_WrongSuccessValue_ReturnsFailWithMessage()
|
||||
{
|
||||
// Arrange
|
||||
var responseMask = new HttpResponseMask();
|
||||
var jsonResponse = @"{""message"": ""failed"", ""data"": {""key"": ""value""}}"; // successValue가 "success"가 아님
|
||||
|
||||
// Act
|
||||
var result = responseMask.Apply(jsonResponse);
|
||||
|
||||
// Assert
|
||||
Assert.IsFalse(result.IsSuccess, "결과가 실패여야 합니다.");
|
||||
Assert.IsNull(result.Data, "실패 시 데이터는 null이어야 합니다.");
|
||||
Assert.AreEqual(jsonResponse, result.Message, "실패 시 메시지는 원본 응답이어야 합니다.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// HttpResponseMask.Apply가 성공 키가 없는 실패 응답을 올바르게 처리하는지 테스트합니다.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void HttpResponseMask_Apply_FailedResponse_MissingSuccessKey_ReturnsFailWithMessage()
|
||||
{
|
||||
// Arrange
|
||||
var responseMask = new HttpResponseMask();
|
||||
var jsonResponse = @"{""error"": ""some error"", ""data"": {""key"": ""value""}}"; // "message" 키가 없음
|
||||
|
||||
// Act
|
||||
var result = responseMask.Apply(jsonResponse);
|
||||
|
||||
// Assert
|
||||
Assert.IsFalse(result.IsSuccess, "결과가 실패여야 합니다.");
|
||||
Assert.IsNull(result.Data, "실패 시 데이터는 null이어야 합니다.");
|
||||
Assert.AreEqual(jsonResponse, result.Message, "실패 시 메시지는 원본 응답이어야 합니다.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// HttpResponseMask.Apply가 데이터 키가 없는 실패 응답을 올바르게 처리하는지 테스트합니다.
|
||||
/// (현재 구현상 successKey 조건만 만족하면 dataKey가 없어도 성공으로 간주하고 Data를 null로 반환할 수 있으므로, 이 테스트는 실패할 수 있습니다.
|
||||
/// 요구사항에 따라 이 부분의 동작을 명확히 하고 테스트를 조정해야 합니다.)
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void HttpResponseMask_Apply_FailedResponse_MissingDataKey_ReturnsFailWithMessage()
|
||||
{
|
||||
// Arrange
|
||||
var responseMask = new HttpResponseMask();
|
||||
// 성공 키는 있지만 데이터 키가 없는 경우
|
||||
var jsonResponse = @"{""message"": ""success"", ""payload"": {""key"": ""value""}}"; // "data" 키가 없음
|
||||
|
||||
// Act
|
||||
var result = responseMask.Apply(jsonResponse);
|
||||
|
||||
// Assert
|
||||
// 현재 Apply 메서드 구현에 따르면, successKey/successValue가 일치하고 dataKey가 없으면
|
||||
// IsSuccess = false, Data = null 로 반환됩니다.
|
||||
// 만약 dataKey가 필수라면 Apply 메서드 수정 또는 이 테스트의 기대 결과 수정이 필요합니다.
|
||||
// 여기서는 현재 구현을 기준으로 테스트합니다.
|
||||
Assert.IsFalse(result.IsSuccess, "data 키가 없으면 success 조건 만족 시 실패여야 합니다 (현재 로직 기준).");
|
||||
Assert.IsNull(result.Data, "data 키가 없는 경우 Data는 null이어야 합니다.");
|
||||
Assert.IsNotNull(result.Message, "실패 시 메시지는 null이 아니어야 합니다.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// HttpResponseMask.Apply가 사용자 정의 키를 사용하여 성공적인 응답을 올바르게 처리하는지 테스트합니다.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void HttpResponseMask_Apply_SuccessfulResponse_CustomKeys_ReturnsSuccessWithData()
|
||||
{
|
||||
// Arrange
|
||||
var responseMask = new HttpResponseMask("status", "ok", "payload");
|
||||
var jsonResponse = @"{""status"": ""ok"", ""payload"": {""info"":""custom data""}}";
|
||||
var expectedData = @"{""info"":""custom data""}";
|
||||
|
||||
// Act
|
||||
var result = responseMask.Apply(jsonResponse);
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(result.IsSuccess, "결과가 성공이어야 합니다.");
|
||||
Assert.AreEqual(expectedData, result.Data, "추출된 데이터가 예상과 다릅니다.");
|
||||
Assert.IsNull(result.Message, "성공 시 메시지는 null이어야 합니다.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// HttpResponseMask.Apply가 잘못된 JSON 형식의 응답을 처리할 때 예외를 발생하는지 테스트합니다.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void HttpResponseMask_Apply_InvalidJson_ThrowsException()
|
||||
{
|
||||
// Arrange
|
||||
var responseMask = new HttpResponseMask();
|
||||
var invalidJsonResponse = @"{""message"": ""success"", ""data"": {""key"": ""value"""; // 닫는 중괄호 누락
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<Newtonsoft.Json.JsonReaderException>(() => responseMask.Apply(invalidJsonResponse), "잘못된 JSON 형식에 대해 JsonReaderException이 발생해야 합니다.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user