|
| 1 | +package io.sentrius.sentrius.analysis.model; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertNull; |
| 6 | + |
| 7 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 8 | +import io.sentrius.agent.analysis.model.LLMResponse; |
| 9 | +import io.sentrius.sso.core.utils.JsonUtil; |
| 10 | +import java.util.HashMap; |
| 11 | +import java.util.Map; |
| 12 | +import org.junit.jupiter.api.Test; |
| 13 | + |
| 14 | +class LLMResponseTest { |
| 15 | + |
| 16 | + @Test |
| 17 | + void testLLMResponseWithMemoryLookup() { |
| 18 | + // Given |
| 19 | + Map<String, Object> args = new HashMap<>(); |
| 20 | + args.put("arg1", "value1"); |
| 21 | + |
| 22 | + // When |
| 23 | + LLMResponse response = LLMResponse.builder() |
| 24 | + .previousOperation("getPlan") |
| 25 | + .nextOperation("executeOperation") |
| 26 | + .memoryLookup("search for user preferences") |
| 27 | + .summaryForLLM("Summary of operations") |
| 28 | + .responseForUser("Task completed successfully") |
| 29 | + .arguments(args) |
| 30 | + .build(); |
| 31 | + |
| 32 | + // Then |
| 33 | + assertEquals("getPlan", response.getPreviousOperation()); |
| 34 | + assertEquals("executeOperation", response.getNextOperation()); |
| 35 | + assertEquals("search for user preferences", response.getMemoryLookup()); |
| 36 | + assertEquals("Summary of operations", response.getSummaryForLLM()); |
| 37 | + assertEquals("Task completed successfully", response.getResponseForUser()); |
| 38 | + assertNotNull(response.getArguments()); |
| 39 | + assertEquals("value1", response.getArguments().get("arg1")); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + void testLLMResponseWithoutMemoryLookup() { |
| 44 | + // Given & When |
| 45 | + LLMResponse response = LLMResponse.builder() |
| 46 | + .previousOperation("getPlan") |
| 47 | + .nextOperation("executeOperation") |
| 48 | + .summaryForLLM("Summary of operations") |
| 49 | + .responseForUser("Task completed successfully") |
| 50 | + .build(); |
| 51 | + |
| 52 | + // Then |
| 53 | + assertEquals("getPlan", response.getPreviousOperation()); |
| 54 | + assertEquals("executeOperation", response.getNextOperation()); |
| 55 | + assertNull(response.getMemoryLookup()); |
| 56 | + assertEquals("Summary of operations", response.getSummaryForLLM()); |
| 57 | + assertEquals("Task completed successfully", response.getResponseForUser()); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + void testLLMResponseJsonSerialization() throws JsonProcessingException { |
| 62 | + // Given |
| 63 | + Map<String, Object> args = new HashMap<>(); |
| 64 | + args.put("query", "test query"); |
| 65 | + |
| 66 | + LLMResponse response = LLMResponse.builder() |
| 67 | + .previousOperation("lookupData") |
| 68 | + .nextOperation("processData") |
| 69 | + .memoryLookup("find previous user interactions") |
| 70 | + .summaryForLLM("Looking up and processing data") |
| 71 | + .responseForUser("Processing your request") |
| 72 | + .arguments(args) |
| 73 | + .build(); |
| 74 | + |
| 75 | + // When |
| 76 | + String json = JsonUtil.MAPPER.writeValueAsString(response); |
| 77 | + LLMResponse deserialized = JsonUtil.MAPPER.readValue(json, LLMResponse.class); |
| 78 | + |
| 79 | + // Then |
| 80 | + assertNotNull(deserialized); |
| 81 | + assertEquals(response.getPreviousOperation(), deserialized.getPreviousOperation()); |
| 82 | + assertEquals(response.getNextOperation(), deserialized.getNextOperation()); |
| 83 | + assertEquals(response.getMemoryLookup(), deserialized.getMemoryLookup()); |
| 84 | + assertEquals(response.getSummaryForLLM(), deserialized.getSummaryForLLM()); |
| 85 | + assertEquals(response.getResponseForUser(), deserialized.getResponseForUser()); |
| 86 | + } |
| 87 | + |
| 88 | + @Test |
| 89 | + void testLLMResponseJsonDeserializationWithMemoryLookup() throws JsonProcessingException { |
| 90 | + // Given |
| 91 | + String json = "{" |
| 92 | + + "\"previousOperation\":\"getStatus\"," |
| 93 | + + "\"nextOperation\":\"updateStatus\"," |
| 94 | + + "\"memoryLookup\":\"search for system configuration\"," |
| 95 | + + "\"summaryForLLM\":\"Status check and update\"," |
| 96 | + + "\"responseForUser\":\"Status updated\"," |
| 97 | + + "\"arguments\":{\"status\":\"active\"}" |
| 98 | + + "}"; |
| 99 | + |
| 100 | + // When |
| 101 | + LLMResponse response = JsonUtil.MAPPER.readValue(json, LLMResponse.class); |
| 102 | + |
| 103 | + // Then |
| 104 | + assertNotNull(response); |
| 105 | + assertEquals("getStatus", response.getPreviousOperation()); |
| 106 | + assertEquals("updateStatus", response.getNextOperation()); |
| 107 | + assertEquals("search for system configuration", response.getMemoryLookup()); |
| 108 | + assertEquals("Status check and update", response.getSummaryForLLM()); |
| 109 | + assertEquals("Status updated", response.getResponseForUser()); |
| 110 | + assertNotNull(response.getArguments()); |
| 111 | + } |
| 112 | + |
| 113 | + @Test |
| 114 | + void testLLMResponseJsonDeserializationWithoutMemoryLookup() throws JsonProcessingException { |
| 115 | + // Given |
| 116 | + String json = "{" |
| 117 | + + "\"previousOperation\":\"getStatus\"," |
| 118 | + + "\"nextOperation\":\"updateStatus\"," |
| 119 | + + "\"summaryForLLM\":\"Status check and update\"," |
| 120 | + + "\"responseForUser\":\"Status updated\"" |
| 121 | + + "}"; |
| 122 | + |
| 123 | + // When |
| 124 | + LLMResponse response = JsonUtil.MAPPER.readValue(json, LLMResponse.class); |
| 125 | + |
| 126 | + // Then |
| 127 | + assertNotNull(response); |
| 128 | + assertEquals("getStatus", response.getPreviousOperation()); |
| 129 | + assertEquals("updateStatus", response.getNextOperation()); |
| 130 | + assertNull(response.getMemoryLookup()); |
| 131 | + assertEquals("Status check and update", response.getSummaryForLLM()); |
| 132 | + assertEquals("Status updated", response.getResponseForUser()); |
| 133 | + } |
| 134 | + |
| 135 | + @Test |
| 136 | + void testLLMResponseWithEmptyMemoryLookup() { |
| 137 | + // Given & When |
| 138 | + LLMResponse response = LLMResponse.builder() |
| 139 | + .previousOperation("operation1") |
| 140 | + .nextOperation("operation2") |
| 141 | + .memoryLookup("") |
| 142 | + .summaryForLLM("Summary") |
| 143 | + .responseForUser("Response") |
| 144 | + .build(); |
| 145 | + |
| 146 | + // Then |
| 147 | + assertEquals("", response.getMemoryLookup()); |
| 148 | + assertNotNull(response.getMemoryLookup()); |
| 149 | + } |
| 150 | +} |
0 commit comments