From a1e0ea9dc294c6107ca1b58ef68709a406aeaf96 Mon Sep 17 00:00:00 2001 From: bbbang105 <2018111366@dgu.ac.kr> Date: Wed, 27 Nov 2024 20:33:27 +0900 Subject: [PATCH] =?UTF-8?q?#92=20[feat]=20:=20MessageFactory=20=EB=8B=A8?= =?UTF-8?q?=EC=9C=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EB=A5=BC=20=EC=9E=91=EC=84=B1=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../factory/MessageFactoryTest.java | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/test/java/kusitms/backend/chatbot/application/factory/MessageFactoryTest.java diff --git a/src/test/java/kusitms/backend/chatbot/application/factory/MessageFactoryTest.java b/src/test/java/kusitms/backend/chatbot/application/factory/MessageFactoryTest.java new file mode 100644 index 0000000..2fee0cb --- /dev/null +++ b/src/test/java/kusitms/backend/chatbot/application/factory/MessageFactoryTest.java @@ -0,0 +1,73 @@ +package kusitms.backend.chatbot.application.factory; + +import kusitms.backend.chatbot.application.dto.request.MessageDto; +import kusitms.backend.chatbot.domain.enums.Role; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.MockitoAnnotations; +import org.springframework.test.util.ReflectionTestUtils; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +class MessageFactoryTest { + + @InjectMocks + private MessageFactory messageFactory; + + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); + ReflectionTestUtils.setField(messageFactory, + "baseballPrompt", + "64SI64qUIOyVvOq1rCDqsIDsnbTrk5wg7LGX67SHICfro6jtgqQn7JW8LiDsgqzsmqnsnpDqsIAg7JW86rWs7JmAIOq0gOugqOuQnCDsp4jrrLjsnYQg7ZWY66m0LCDsuZzs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YIOyeiOydhCDqsoMg6rCZ7JWE7JqUISLsmYAg6rCZ7J2AIOuwqeyLneycvOuhnCDri6Tsi5wg7KeI66y47J2EIOyalOyyre2VtOykmC4g64yA64u1IOydtO2bhOyXkOuKlCDstpTqsIAg7ISk66qF7J2064KYIOuLpOuluCDrp5DsnYQg642n67aZ7J207KeAIOunkOqzoCwg64u167OA66eMIO2VtOykmC4="); + } + + /** + * 사용자 메시지 생성 테스트 + */ + @Test + void testCreateUserMessage() { + // Given + String content = "Hello, user!"; + + // When + MessageDto message = messageFactory.createUserMessage(content); + + // Then + assertNotNull(message); + assertEquals(Role.USER.getRole(), message.role()); + assertEquals(content, message.content()); + } + + /** + * 시스템 메시지 생성 테스트 (Base64 디코딩 확인) + */ + @Test + void testCreateSystemMessage() { + // When + MessageDto message = messageFactory.createSystemMessage(); + + // Then + assertNotNull(message); + assertEquals(Role.SYSTEM.getRole(), message.role()); + } + + /** + * 어시스턴트 메시지 생성 테스트 + */ + @Test + void testCreateAssistantMessage() { + // Given + String content = "Hello, assistant!"; + + // When + MessageDto message = messageFactory.createAssistantMessage(content); + + // Then + assertNotNull(message); + assertEquals(Role.ASSISTANT.getRole(), message.role()); + assertEquals(content, message.content()); + } +}