|
19 | 19 | import org.junit.jupiter.api.Test;
|
20 | 20 | import org.mockito.Mockito;
|
21 | 21 |
|
| 22 | +import org.springframework.ai.chat.prompt.PromptTemplate; |
22 | 23 | import org.springframework.ai.vectorstore.VectorStore;
|
| 24 | +import reactor.core.scheduler.Scheduler; |
23 | 25 |
|
| 26 | +import static org.assertj.core.api.Assertions.assertThat; |
24 | 27 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
25 | 28 |
|
26 | 29 | /**
|
@@ -91,4 +94,116 @@ void whenDefaultTopKIsNegativeThenThrow() {
|
91 | 94 | .hasMessageContaining("topK must be greater than 0");
|
92 | 95 | }
|
93 | 96 |
|
| 97 | + @Test |
| 98 | + void whenBuilderWithValidVectorStoreThenSuccess() { |
| 99 | + VectorStore vectorStore = Mockito.mock(VectorStore.class); |
| 100 | + |
| 101 | + VectorStoreChatMemoryAdvisor advisor = VectorStoreChatMemoryAdvisor.builder(vectorStore).build(); |
| 102 | + |
| 103 | + assertThat(advisor).isNotNull(); |
| 104 | + } |
| 105 | + |
| 106 | + @Test |
| 107 | + void whenBuilderWithAllValidParametersThenSuccess() { |
| 108 | + VectorStore vectorStore = Mockito.mock(VectorStore.class); |
| 109 | + Scheduler scheduler = Mockito.mock(Scheduler.class); |
| 110 | + PromptTemplate systemPromptTemplate = Mockito.mock(PromptTemplate.class); |
| 111 | + |
| 112 | + VectorStoreChatMemoryAdvisor advisor = VectorStoreChatMemoryAdvisor.builder(vectorStore) |
| 113 | + .conversationId("test-conversation") |
| 114 | + .scheduler(scheduler) |
| 115 | + .systemPromptTemplate(systemPromptTemplate) |
| 116 | + .defaultTopK(5) |
| 117 | + .build(); |
| 118 | + |
| 119 | + assertThat(advisor).isNotNull(); |
| 120 | + } |
| 121 | + |
| 122 | + @Test |
| 123 | + void whenDefaultConversationIdIsBlankThenThrow() { |
| 124 | + VectorStore vectorStore = Mockito.mock(VectorStore.class); |
| 125 | + |
| 126 | + assertThatThrownBy(() -> VectorStoreChatMemoryAdvisor.builder(vectorStore).conversationId(" ").build()) |
| 127 | + .isInstanceOf(IllegalArgumentException.class) |
| 128 | + .hasMessageContaining("defaultConversationId cannot be null or empty"); |
| 129 | + } |
| 130 | + |
| 131 | + @Test |
| 132 | + void whenBuilderWithValidConversationIdThenSuccess() { |
| 133 | + VectorStore vectorStore = Mockito.mock(VectorStore.class); |
| 134 | + |
| 135 | + VectorStoreChatMemoryAdvisor advisor = VectorStoreChatMemoryAdvisor.builder(vectorStore) |
| 136 | + .conversationId("valid-id") |
| 137 | + .build(); |
| 138 | + |
| 139 | + assertThat(advisor).isNotNull(); |
| 140 | + } |
| 141 | + |
| 142 | + @Test |
| 143 | + void whenBuilderWithValidTopKThenSuccess() { |
| 144 | + VectorStore vectorStore = Mockito.mock(VectorStore.class); |
| 145 | + |
| 146 | + VectorStoreChatMemoryAdvisor advisor = VectorStoreChatMemoryAdvisor.builder(vectorStore) |
| 147 | + .defaultTopK(10) |
| 148 | + .build(); |
| 149 | + |
| 150 | + assertThat(advisor).isNotNull(); |
| 151 | + } |
| 152 | + |
| 153 | + @Test |
| 154 | + void whenBuilderWithMinimumTopKThenSuccess() { |
| 155 | + VectorStore vectorStore = Mockito.mock(VectorStore.class); |
| 156 | + |
| 157 | + VectorStoreChatMemoryAdvisor advisor = VectorStoreChatMemoryAdvisor.builder(vectorStore).defaultTopK(1).build(); |
| 158 | + |
| 159 | + assertThat(advisor).isNotNull(); |
| 160 | + } |
| 161 | + |
| 162 | + @Test |
| 163 | + void whenBuilderWithLargeTopKThenSuccess() { |
| 164 | + VectorStore vectorStore = Mockito.mock(VectorStore.class); |
| 165 | + |
| 166 | + VectorStoreChatMemoryAdvisor advisor = VectorStoreChatMemoryAdvisor.builder(vectorStore) |
| 167 | + .defaultTopK(1000) |
| 168 | + .build(); |
| 169 | + |
| 170 | + assertThat(advisor).isNotNull(); |
| 171 | + } |
| 172 | + |
| 173 | + @Test |
| 174 | + void whenBuilderCalledMultipleTimesWithSameVectorStoreThenSuccess() { |
| 175 | + VectorStore vectorStore = Mockito.mock(VectorStore.class); |
| 176 | + |
| 177 | + VectorStoreChatMemoryAdvisor advisor1 = VectorStoreChatMemoryAdvisor.builder(vectorStore).build(); |
| 178 | + VectorStoreChatMemoryAdvisor advisor2 = VectorStoreChatMemoryAdvisor.builder(vectorStore).build(); |
| 179 | + |
| 180 | + assertThat(advisor1).isNotNull(); |
| 181 | + assertThat(advisor2).isNotNull(); |
| 182 | + assertThat(advisor1).isNotSameAs(advisor2); |
| 183 | + } |
| 184 | + |
| 185 | + @Test |
| 186 | + void whenBuilderWithCustomSchedulerThenSuccess() { |
| 187 | + VectorStore vectorStore = Mockito.mock(VectorStore.class); |
| 188 | + Scheduler customScheduler = Mockito.mock(Scheduler.class); |
| 189 | + |
| 190 | + VectorStoreChatMemoryAdvisor advisor = VectorStoreChatMemoryAdvisor.builder(vectorStore) |
| 191 | + .scheduler(customScheduler) |
| 192 | + .build(); |
| 193 | + |
| 194 | + assertThat(advisor).isNotNull(); |
| 195 | + } |
| 196 | + |
| 197 | + @Test |
| 198 | + void whenBuilderWithCustomSystemPromptTemplateThenSuccess() { |
| 199 | + VectorStore vectorStore = Mockito.mock(VectorStore.class); |
| 200 | + PromptTemplate customTemplate = Mockito.mock(PromptTemplate.class); |
| 201 | + |
| 202 | + VectorStoreChatMemoryAdvisor advisor = VectorStoreChatMemoryAdvisor.builder(vectorStore) |
| 203 | + .systemPromptTemplate(customTemplate) |
| 204 | + .build(); |
| 205 | + |
| 206 | + assertThat(advisor).isNotNull(); |
| 207 | + } |
| 208 | + |
94 | 209 | }
|
0 commit comments