forked from Mirror/ollama4j
		
	Updated tests
This commit is contained in:
		@@ -1,21 +1,15 @@
 | 
				
			|||||||
package io.github.amithkoujalgi.ollama4j.integrationtests;
 | 
					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.OllamaAPI;
 | 
				
			||||||
import io.github.amithkoujalgi.ollama4j.core.exceptions.OllamaBaseException;
 | 
					import io.github.amithkoujalgi.ollama4j.core.exceptions.OllamaBaseException;
 | 
				
			||||||
import io.github.amithkoujalgi.ollama4j.core.models.ModelDetail;
 | 
					import java.io.IOException;
 | 
				
			||||||
import io.github.amithkoujalgi.ollama4j.core.models.OllamaAsyncResultCallback;
 | 
					import java.net.ConnectException;
 | 
				
			||||||
import io.github.amithkoujalgi.ollama4j.core.models.OllamaResult;
 | 
					import java.net.URISyntaxException;
 | 
				
			||||||
import io.github.amithkoujalgi.ollama4j.core.types.OllamaModelType;
 | 
					 | 
				
			||||||
import org.junit.jupiter.api.BeforeEach;
 | 
					import org.junit.jupiter.api.BeforeEach;
 | 
				
			||||||
import org.junit.jupiter.api.Test;
 | 
					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 {
 | 
					class TestRealAPIs {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -27,10 +21,17 @@ class TestRealAPIs {
 | 
				
			|||||||
    ollamaAPI = new OllamaAPI(ollamaHost);
 | 
					    ollamaAPI = new OllamaAPI(ollamaHost);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @Test
 | 
				
			||||||
 | 
					  void testWrongEndpoint() {
 | 
				
			||||||
 | 
					    OllamaAPI ollamaAPI = new OllamaAPI("http://wrong-host:11434");
 | 
				
			||||||
 | 
					    assertThrows(ConnectException.class, ollamaAPI::listModels);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Test
 | 
					  @Test
 | 
				
			||||||
  void testListModels() {
 | 
					  void testListModels() {
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
      assertNotNull(ollamaAPI.listModels());
 | 
					      assertNotNull(ollamaAPI.listModels());
 | 
				
			||||||
 | 
					      ollamaAPI.listModels().forEach(System.out::println);
 | 
				
			||||||
    } catch (IOException | OllamaBaseException | InterruptedException | URISyntaxException e) {
 | 
					    } catch (IOException | OllamaBaseException | InterruptedException | URISyntaxException e) {
 | 
				
			||||||
      throw new RuntimeException(e);
 | 
					      throw new RuntimeException(e);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,9 +14,9 @@ import java.util.ArrayList;
 | 
				
			|||||||
import org.junit.jupiter.api.Test;
 | 
					import org.junit.jupiter.api.Test;
 | 
				
			||||||
import org.mockito.Mockito;
 | 
					import org.mockito.Mockito;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class TestMockedAPIs {
 | 
					class TestMockedAPIs {
 | 
				
			||||||
  @Test
 | 
					  @Test
 | 
				
			||||||
  public void testMockPullModel() {
 | 
					  void testMockPullModel() {
 | 
				
			||||||
    OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
 | 
					    OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
 | 
				
			||||||
    String model = OllamaModelType.LLAMA2;
 | 
					    String model = OllamaModelType.LLAMA2;
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
@@ -29,7 +29,7 @@ public class TestMockedAPIs {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Test
 | 
					  @Test
 | 
				
			||||||
  public void testListModels() {
 | 
					  void testListModels() {
 | 
				
			||||||
    OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
 | 
					    OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
      when(ollamaAPI.listModels()).thenReturn(new ArrayList<>());
 | 
					      when(ollamaAPI.listModels()).thenReturn(new ArrayList<>());
 | 
				
			||||||
@@ -41,7 +41,7 @@ public class TestMockedAPIs {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Test
 | 
					  @Test
 | 
				
			||||||
  public void testCreateModel() {
 | 
					  void testCreateModel() {
 | 
				
			||||||
    OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
 | 
					    OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
 | 
				
			||||||
    String model = OllamaModelType.LLAMA2;
 | 
					    String model = OllamaModelType.LLAMA2;
 | 
				
			||||||
    String modelFilePath = "/somemodel";
 | 
					    String modelFilePath = "/somemodel";
 | 
				
			||||||
@@ -55,7 +55,7 @@ public class TestMockedAPIs {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Test
 | 
					  @Test
 | 
				
			||||||
  public void testDeleteModel() {
 | 
					  void testDeleteModel() {
 | 
				
			||||||
    OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
 | 
					    OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
 | 
				
			||||||
    String model = OllamaModelType.LLAMA2;
 | 
					    String model = OllamaModelType.LLAMA2;
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
@@ -68,7 +68,7 @@ public class TestMockedAPIs {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Test
 | 
					  @Test
 | 
				
			||||||
  public void testGetModelDetails() {
 | 
					  void testGetModelDetails() {
 | 
				
			||||||
    OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
 | 
					    OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
 | 
				
			||||||
    String model = OllamaModelType.LLAMA2;
 | 
					    String model = OllamaModelType.LLAMA2;
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
@@ -81,7 +81,7 @@ public class TestMockedAPIs {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Test
 | 
					  @Test
 | 
				
			||||||
  public void testGenerateEmbeddings() {
 | 
					  void testGenerateEmbeddings() {
 | 
				
			||||||
    OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
 | 
					    OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
 | 
				
			||||||
    String model = OllamaModelType.LLAMA2;
 | 
					    String model = OllamaModelType.LLAMA2;
 | 
				
			||||||
    String prompt = "some prompt text";
 | 
					    String prompt = "some prompt text";
 | 
				
			||||||
@@ -95,7 +95,7 @@ public class TestMockedAPIs {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Test
 | 
					  @Test
 | 
				
			||||||
  public void testAsk() {
 | 
					  void testAsk() {
 | 
				
			||||||
    OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
 | 
					    OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
 | 
				
			||||||
    String model = OllamaModelType.LLAMA2;
 | 
					    String model = OllamaModelType.LLAMA2;
 | 
				
			||||||
    String prompt = "some prompt text";
 | 
					    String prompt = "some prompt text";
 | 
				
			||||||
@@ -109,7 +109,7 @@ public class TestMockedAPIs {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Test
 | 
					  @Test
 | 
				
			||||||
  public void testAskAsync() {
 | 
					  void testAskAsync() {
 | 
				
			||||||
    OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
 | 
					    OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
 | 
				
			||||||
    String model = OllamaModelType.LLAMA2;
 | 
					    String model = OllamaModelType.LLAMA2;
 | 
				
			||||||
    String prompt = "some prompt text";
 | 
					    String prompt = "some prompt text";
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user