Updated tests

This commit is contained in:
Amith Koujalgi 2023-12-14 18:22:53 +05:30
parent a0d6a5ef97
commit 74b03dcb87
2 changed files with 22 additions and 21 deletions

View File

@ -1,21 +1,15 @@
package io.github.amithkoujalgi.ollama4j.integrationtests;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import io.github.amithkoujalgi.ollama4j.core.OllamaAPI;
import io.github.amithkoujalgi.ollama4j.core.exceptions.OllamaBaseException;
import io.github.amithkoujalgi.ollama4j.core.models.ModelDetail;
import io.github.amithkoujalgi.ollama4j.core.models.OllamaAsyncResultCallback;
import io.github.amithkoujalgi.ollama4j.core.models.OllamaResult;
import io.github.amithkoujalgi.ollama4j.core.types.OllamaModelType;
import java.io.IOException;
import java.net.ConnectException;
import java.net.URISyntaxException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.*;
class TestRealAPIs {
@ -27,10 +21,17 @@ class TestRealAPIs {
ollamaAPI = new OllamaAPI(ollamaHost);
}
@Test
void testWrongEndpoint() {
OllamaAPI ollamaAPI = new OllamaAPI("http://wrong-host:11434");
assertThrows(ConnectException.class, ollamaAPI::listModels);
}
@Test
void testListModels() {
try {
assertNotNull(ollamaAPI.listModels());
ollamaAPI.listModels().forEach(System.out::println);
} catch (IOException | OllamaBaseException | InterruptedException | URISyntaxException e) {
throw new RuntimeException(e);
}

View File

@ -14,9 +14,9 @@ import java.util.ArrayList;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
public class TestMockedAPIs {
class TestMockedAPIs {
@Test
public void testMockPullModel() {
void testMockPullModel() {
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
String model = OllamaModelType.LLAMA2;
try {
@ -29,7 +29,7 @@ public class TestMockedAPIs {
}
@Test
public void testListModels() {
void testListModels() {
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
try {
when(ollamaAPI.listModels()).thenReturn(new ArrayList<>());
@ -41,7 +41,7 @@ public class TestMockedAPIs {
}
@Test
public void testCreateModel() {
void testCreateModel() {
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
String model = OllamaModelType.LLAMA2;
String modelFilePath = "/somemodel";
@ -55,7 +55,7 @@ public class TestMockedAPIs {
}
@Test
public void testDeleteModel() {
void testDeleteModel() {
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
String model = OllamaModelType.LLAMA2;
try {
@ -68,7 +68,7 @@ public class TestMockedAPIs {
}
@Test
public void testGetModelDetails() {
void testGetModelDetails() {
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
String model = OllamaModelType.LLAMA2;
try {
@ -81,7 +81,7 @@ public class TestMockedAPIs {
}
@Test
public void testGenerateEmbeddings() {
void testGenerateEmbeddings() {
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
String model = OllamaModelType.LLAMA2;
String prompt = "some prompt text";
@ -95,7 +95,7 @@ public class TestMockedAPIs {
}
@Test
public void testAsk() {
void testAsk() {
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
String model = OllamaModelType.LLAMA2;
String prompt = "some prompt text";
@ -109,7 +109,7 @@ public class TestMockedAPIs {
}
@Test
public void testAskAsync() {
void testAskAsync() {
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
String model = OllamaModelType.LLAMA2;
String prompt = "some prompt text";