.
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright 2025 Google. This software is provided as-is, without warranty or representation for any use or purpose.
|
||||
* Your use of it is subject to your agreement with Google.
|
||||
*/
|
||||
package com.example.service.integration_testing;
|
||||
|
||||
import com.example.service.base.MessageEntryFilter;
|
||||
import com.example.util.PerformanceTimer;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@SpringBootTest
|
||||
@ActiveProfiles("dev")
|
||||
@DisplayName("MessageEntryFilter Integration Tests")
|
||||
public class MessageEntryFilterIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private MessageEntryFilter messageEntryFilter;
|
||||
|
||||
private static final String NOTIFICATION_JSON_EXAMPLE =
|
||||
"[{\"texto\": \"Tu estado de cuenta de Agosto esta listo\"}," +
|
||||
"{\"texto\": \"Tu pago ha sido procesado\"}]";
|
||||
|
||||
private static final String CONVERSATION_JSON_EXAMPLE =
|
||||
"{\"sessionId\":\"ec9f3731-59ac-4bd0-849e-f45fcc18436d\"," +
|
||||
"\"userId\":\"user_by_phone_0102030405060708\"," +
|
||||
"\"telefono\":\"0102030405060708\"," +
|
||||
"\"createdAt\":\"2025-08-06T20:35:05.123699404Z\"," +
|
||||
"\"lastModified\":\"2025-08-06T20:35:05.984574281Z\"," +
|
||||
"\"entries\":[{" +
|
||||
"\"type\":\"USUARIO\"," +
|
||||
"\"timestamp\":\"2025-08-06T20:35:05.123516916Z\"," +
|
||||
"\"text\":\"Hola que tal\"" +
|
||||
"},{" +
|
||||
"\"type\":\"SISTEMA\"," +
|
||||
"\"timestamp\":\"2025-08-06T20:35:05.967828173Z\"," +
|
||||
"\"text\":\"\\Hola! Bienvenido a Banorte, te saluda Beto. \\En que te puedo ayudar? \"," +
|
||||
"\"parameters\":{" +
|
||||
"\"canal\":\"banortec\"," +
|
||||
"\"telefono\":\"0102030405060708\"," +
|
||||
"\"pantalla_contexto\":\"transferencias\"," +
|
||||
"\"usuario_id\":\"user_by_phone_0102030405060708\"," +
|
||||
"\"nickname\":\"John Doe\"" +
|
||||
"}" +
|
||||
"}]" +
|
||||
"}";
|
||||
|
||||
private static final List<String> CONVERSATION_QUERIES = Arrays.asList(
|
||||
"Hola, ¿cómo estás?",
|
||||
"Qué tal, ¿qué hay de nuevo?",
|
||||
"¿Cuál es el pronóstico del tiempo para hoy?",
|
||||
"Me gustaría saber más sobre otro servicio",
|
||||
"Tengo una pregunta general"
|
||||
);
|
||||
|
||||
private static final List<String> NOTIFICATION_QUERIES = Arrays.asList(
|
||||
"¿Dónde puedo ver mi estado de cuenta?",
|
||||
//"Quiero saber mas",
|
||||
"Muéstrame mi estado de cuenta de este mes",
|
||||
"¿Qué dice la notificación del 1 de agosto?"
|
||||
);
|
||||
|
||||
@Test
|
||||
@DisplayName("Gemini should classify various conversational queries as CONVERSATION")
|
||||
void classifyMessage_integrationTest_shouldClassifyVariousQueriesAsConversation() {
|
||||
for (int i = 0; i < CONVERSATION_QUERIES.size(); i++) {
|
||||
String query = CONVERSATION_QUERIES.get(i);
|
||||
String testName = String.format("Gemini (CONVERSATION) - Query %d", i + 1);
|
||||
|
||||
String result = PerformanceTimer.timeExecution(
|
||||
testName,
|
||||
() -> messageEntryFilter.classifyMessage(query, null,null)
|
||||
);
|
||||
|
||||
assertEquals(MessageEntryFilter.CATEGORY_CONVERSATION, result,
|
||||
String.format("Assertion failed for query: '%s'", query));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Gemini should classify various notification queries as NOTIFICATION with context")
|
||||
void classifyMessage_integrationTest_shouldClassifyVariousQueriesAsNotificationWithContext() {
|
||||
for (int i = 0; i < NOTIFICATION_QUERIES.size(); i++) {
|
||||
String query = NOTIFICATION_QUERIES.get(i);
|
||||
String testName = String.format("Gemini (NOTIFICATION with context) - Query %d", i + 1);
|
||||
|
||||
String result = PerformanceTimer.timeExecution(
|
||||
testName,
|
||||
() -> messageEntryFilter.classifyMessage(query, NOTIFICATION_JSON_EXAMPLE,CONVERSATION_JSON_EXAMPLE)
|
||||
);
|
||||
|
||||
assertEquals(MessageEntryFilter.CATEGORY_NOTIFICATION, result,
|
||||
String.format("Assertion failed for query: '%s'", query));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Gemini should classify various conversational queries as CONVERSATION even with context")
|
||||
void classifyMessage_integrationTest_shouldClassifyVariousConversationalQueriesWithContext() {
|
||||
for (int i = 0; i < CONVERSATION_QUERIES.size(); i++) {
|
||||
String query = CONVERSATION_QUERIES.get(i);
|
||||
String testName = String.format("Gemini (CONVERSATION with context) - Query %d", i + 1);
|
||||
|
||||
String result = PerformanceTimer.timeExecution(
|
||||
testName,
|
||||
() -> messageEntryFilter.classifyMessage(query, NOTIFICATION_JSON_EXAMPLE,CONVERSATION_JSON_EXAMPLE)
|
||||
);
|
||||
|
||||
assertEquals(MessageEntryFilter.CATEGORY_CONVERSATION, result,
|
||||
String.format("Assertion failed for query: '%s'", query));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.example.service.integration_testing;
|
||||
|
||||
import com.example.service.base.NotificationContextResolver;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
@SpringBootTest
|
||||
@ActiveProfiles("dev")
|
||||
@DisplayName("NotificationContextResolver Live Tests")
|
||||
public class NotificationContextResolverLiveTest {
|
||||
|
||||
private String notificationsJson;
|
||||
private String conversationJson;
|
||||
private String queryInputText;
|
||||
private String metadataJson;
|
||||
|
||||
@Autowired
|
||||
private NotificationContextResolver notificationContextResolver;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
notificationsJson = "Hola :\n" +
|
||||
"Pasó algo con la captura de tu INE y no se completó tu *solicitud de tarjeta de crédito con folio *.\n"
|
||||
+
|
||||
"¡Reinténtalo cuando quieras! Solo toma en cuenta estos consejos:\n" +
|
||||
"🪪 Presenta tu INE original (no copias ni escaneos).\n" +
|
||||
"📅Revisa que esté vigente y sin tachaduras.\n" +
|
||||
"📷 Confirma que la fotografía sea clara.\n" +
|
||||
"🏠 Asegúrate de que la dirección sea legible.\n" +
|
||||
"Estamos listos para recibirte.\n";
|
||||
|
||||
conversationJson = "System: Hola :Pasó algo con la captura de tu INE y no se completó tu *solicitud de tarjeta de crédito con folio *.¡Reinténtalo cuando quieras! Solo toma en cuenta estos consejos:🪪 Presenta tu INE original (no copias ni escaneos).📅Revisa que esté vigente y sin tachaduras.📷 Confirma que la fotografía sea clara.🏠 Asegúrate de que la dirección sea legible.Estamos listos para recibirte.notification_po_contexto=campañaprueba, notification_po_id_campaña=campaña01, notification_po_id_aplicacion=TestSigma, notification_po_id_notificacion=Prueba2";
|
||||
queryInputText = "cual es el id de la notificaion?";
|
||||
metadataJson = "{\"contexto\":\"campañaprueba\",\"id_aplicacion\":\"TestSigma\",\"id_campaña\":\"campaña01\",\"id_notificacion\":\"Prueba2\",\"vigencia\":\"30/09/2025\"}";
|
||||
//metadataJson = "{}";
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should get live response from LLM and print it")
|
||||
public void shouldGetLiveResponseFromLlmAndPrintIt() {
|
||||
String result = notificationContextResolver.resolveContext(queryInputText, notificationsJson, conversationJson,
|
||||
metadataJson, "test_user", "test_session", "1234567890");
|
||||
System.out.println("Live LLM Response: " + result);
|
||||
assertNotNull(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user