Skip to content

Commit 4915e9c

Browse files
committed
Ollama: ut for OllamaApiBuilder
Signed-off-by: lambochen <[email protected]>
1 parent 3846d75 commit 4915e9c

File tree

1 file changed

+68
-0
lines changed
  • auto-configurations/models/spring-ai-autoconfigure-model-ollama/src/test/java/org/springframework/ai/model/ollama/autoconfigure

1 file changed

+68
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package org.springframework.ai.model.ollama.autoconfigure;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.ai.ollama.api.OllamaApi;
5+
6+
import static org.assertj.core.api.Assertions.assertThat;
7+
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
8+
9+
/**
10+
* @author lambochen
11+
*/
12+
public class OllamaApiBuilderTests {
13+
14+
@Test
15+
void fullBuilder() {
16+
OllamaApi ollamaApi = OllamaApi.builder()
17+
.baseUrl("http://localhost:11434")
18+
.chatPath("/api/chat")
19+
.embedPath("/api/embeddings")
20+
.listModelsPath("/api/tags")
21+
.showModelPath("/api/show")
22+
.copyModelPath("/api/copy")
23+
.deleteModelPath("/api/delete")
24+
.pullModelPath("/api/pull")
25+
.build();
26+
27+
assertThat(ollamaApi).isNotNull();
28+
}
29+
30+
@Test
31+
void defaultBuilder() {
32+
OllamaApi ollamaApi = OllamaApi.builder().build();
33+
assertThat(ollamaApi).isNotNull();
34+
}
35+
36+
@Test
37+
void invalidPath() {
38+
assertThatThrownBy(() -> OllamaApi.builder().chatPath("").build()).isInstanceOf(IllegalArgumentException.class);
39+
assertThatThrownBy(() -> OllamaApi.builder().embedPath("").build())
40+
.isInstanceOf(IllegalArgumentException.class);
41+
assertThatThrownBy(() -> OllamaApi.builder().listModelsPath("").build())
42+
.isInstanceOf(IllegalArgumentException.class);
43+
assertThatThrownBy(() -> OllamaApi.builder().showModelPath("").build())
44+
.isInstanceOf(IllegalArgumentException.class);
45+
assertThatThrownBy(() -> OllamaApi.builder().copyModelPath("").build())
46+
.isInstanceOf(IllegalArgumentException.class);
47+
assertThatThrownBy(() -> OllamaApi.builder().deleteModelPath("").build())
48+
.isInstanceOf(IllegalArgumentException.class);
49+
assertThatThrownBy(() -> OllamaApi.builder().pullModelPath("").build())
50+
.isInstanceOf(IllegalArgumentException.class);
51+
52+
assertThatThrownBy(() -> OllamaApi.builder().chatPath(null).build())
53+
.isInstanceOf(IllegalArgumentException.class);
54+
assertThatThrownBy(() -> OllamaApi.builder().embedPath(null).build())
55+
.isInstanceOf(IllegalArgumentException.class);
56+
assertThatThrownBy(() -> OllamaApi.builder().listModelsPath(null).build())
57+
.isInstanceOf(IllegalArgumentException.class);
58+
assertThatThrownBy(() -> OllamaApi.builder().showModelPath(null).build())
59+
.isInstanceOf(IllegalArgumentException.class);
60+
assertThatThrownBy(() -> OllamaApi.builder().copyModelPath(null).build())
61+
.isInstanceOf(IllegalArgumentException.class);
62+
assertThatThrownBy(() -> OllamaApi.builder().deleteModelPath(null).build())
63+
.isInstanceOf(IllegalArgumentException.class);
64+
assertThatThrownBy(() -> OllamaApi.builder().pullModelPath(null).build())
65+
.isInstanceOf(IllegalArgumentException.class);
66+
}
67+
68+
}

0 commit comments

Comments
 (0)