From afb8d217470fd3e26aad2246755d591709708b27 Mon Sep 17 00:00:00 2001 From: Amith Koujalgi Date: Thu, 14 Dec 2023 17:30:14 +0530 Subject: [PATCH] Added surefire and failsafe plugins --- .github/workflows/build-on-pr-create.yml | 4 +- .github/workflows/maven-publish.yml | 2 +- .github/workflows/publish-javadoc.yml | 2 +- Makefile | 5 + pom.xml | 325 ++++++++++-------- .../integrationtests/TestRealAPIs.java | 121 +++++++ .../{ => unittests}/TestMockedAPIs.java | 2 +- 7 files changed, 321 insertions(+), 140 deletions(-) create mode 100644 Makefile create mode 100644 src/test/java/io/github/amithkoujalgi/ollama4j/integrationtests/TestRealAPIs.java rename src/test/java/io/github/amithkoujalgi/ollama4j/{ => unittests}/TestMockedAPIs.java (98%) diff --git a/.github/workflows/build-on-pr-create.yml b/.github/workflows/build-on-pr-create.yml index 248f068..9c6a982 100644 --- a/.github/workflows/build-on-pr-create.yml +++ b/.github/workflows/build-on-pr-create.yml @@ -28,7 +28,7 @@ jobs: settings-path: ${{ github.workspace }} # location for the settings.xml file - name: Build with Maven - run: mvn -U -B clean package --file pom.xml + run: mvn --file pom.xml -U clean package - name: Run Tests - run: mvn -U clean verify --file pom.xml \ No newline at end of file + run: mvn --file pom.xml -U clean test -Punit-tests \ No newline at end of file diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index 8d1f95c..eb7397b 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -34,7 +34,7 @@ jobs: # run: mvn -U clean verify --file pom.xml - name: Build with Maven - run: mvn -U -B clean verify package --file pom.xml + run: mvn --file pom.xml -U clean package -Punit-tests - name: Set up Apache Maven Central (Overwrite settings.xml) uses: actions/setup-java@v3 diff --git a/.github/workflows/publish-javadoc.yml b/.github/workflows/publish-javadoc.yml index 9878a24..59e9c77 100644 --- a/.github/workflows/publish-javadoc.yml +++ b/.github/workflows/publish-javadoc.yml @@ -39,7 +39,7 @@ jobs: server-id: github # Value of the distributionManagement/repository/id field of the pom.xml settings-path: ${{ github.workspace }} # location for the settings.xml file - name: Build with Maven - run: mvn -U -B clean package --file pom.xml + run: mvn --file pom.xml -U clean package - name: Setup Pages uses: actions/configure-pages@v3 - name: Upload artifact diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..62dc4df --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +ut: + mvn clean test -Punit-tests + +it: + mvn clean verify -Pintegration-tests \ No newline at end of file diff --git a/pom.xml b/pom.xml index e977d1f..4dc4902 100644 --- a/pom.xml +++ b/pom.xml @@ -1,148 +1,203 @@ - 4.0.0 + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - io.github.amithkoujalgi - ollama4j - 1.0-SNAPSHOT + io.github.amithkoujalgi + ollama4j + 1.0-SNAPSHOT - Ollama4j - Java library for interacting with Ollama API. - https://github.com/amithkoujalgi/ollama4j + Ollama4j + Java library for interacting with Ollama API. + https://github.com/amithkoujalgi/ollama4j - - 11 - 11 - UTF-8 - + + 11 + 11 + UTF-8 + 3.0.0-M5 + 3.0.0-M5 + - - - Amith Koujalgi - koujalgi.amith@gmail.com - Sonatype - https://www.sonatype.com - - + + + Amith Koujalgi + koujalgi.amith@gmail.com + Sonatype + https://www.sonatype.com + + - - - MIT License - https://raw.githubusercontent.com/amithkoujalgi/ollama4j/main/LICENSE - - + + + MIT License + https://raw.githubusercontent.com/amithkoujalgi/ollama4j/main/LICENSE + + - - scm:git:git@github.com:amithkoujalgi/ollama4j.git - scm:git:https://github.com/amithkoujalgi/ollama4j.git - https://github.com/amithkoujalgi/ollama4j/tree/main - + + scm:git:git@github.com:amithkoujalgi/ollama4j.git + scm:git:https://github.com/amithkoujalgi/ollama4j.git + https://github.com/amithkoujalgi/ollama4j/tree/main + - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.8 - true - - ossrh - https://s01.oss.sonatype.org/ - true - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.5 - - - sign-artifacts - deploy - - sign - - - - - --pinentry-mode - loopback - - - - - - - + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.8 + true + + ossrh + https://s01.oss.sonatype.org/ + true + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + deploy + + sign + + + + + --pinentry-mode + loopback + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + ${skipUnitTests} + + **/unittests/*.java + + + - - - com.fasterxml.jackson.core - jackson-databind - 2.15.3 - - - ch.qos.logback - logback-classic - 1.3.11 - test - - - org.slf4j - slf4j-api - 2.0.9 - - - org.junit.jupiter - junit-jupiter-api - 5.10.0 - test - - - org.mockito - mockito-core - 4.1.0 - test - - + + + org.apache.maven.plugins + maven-failsafe-plugin + ${maven-failsafe-plugin.version} + + + **/integrationtests/*.java + + + **/unittests/*.java + + + + + + integration-test + verify + + + + - - - ossrh - https://s01.oss.sonatype.org/content/repositories/snapshots - - - ossrh - https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ - - + + + + + + com.fasterxml.jackson.core + jackson-databind + 2.15.3 + + + ch.qos.logback + logback-classic + 1.3.11 + test + + + org.slf4j + slf4j-api + 2.0.9 + + + org.junit.jupiter + junit-jupiter-api + 5.10.0 + test + + + org.mockito + mockito-core + 4.1.0 + test + + + + + + ossrh + https://s01.oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + + unit-tests + + unit + false + + + + integration-tests + + integration + true + + + \ No newline at end of file diff --git a/src/test/java/io/github/amithkoujalgi/ollama4j/integrationtests/TestRealAPIs.java b/src/test/java/io/github/amithkoujalgi/ollama4j/integrationtests/TestRealAPIs.java new file mode 100644 index 0000000..77f0633 --- /dev/null +++ b/src/test/java/io/github/amithkoujalgi/ollama4j/integrationtests/TestRealAPIs.java @@ -0,0 +1,121 @@ +package io.github.amithkoujalgi.ollama4j.integrationtests; + +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 org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.ArrayList; + +import static org.mockito.Mockito.*; + +public class TestRealAPIs { + @Test + public void testMockPullModel() { + OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class); + String model = OllamaModelType.LLAMA2; + try { + doNothing().when(ollamaAPI).pullModel(model); + ollamaAPI.pullModel(model); + verify(ollamaAPI, times(1)).pullModel(model); + } catch (IOException | OllamaBaseException | InterruptedException | URISyntaxException e) { + throw new RuntimeException(e); + } + } + + @Test + public void testListModels() { + OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class); + try { + when(ollamaAPI.listModels()).thenReturn(new ArrayList<>()); + ollamaAPI.listModels(); + verify(ollamaAPI, times(1)).listModels(); + } catch (IOException | OllamaBaseException | InterruptedException | URISyntaxException e) { + throw new RuntimeException(e); + } + } + + @Test + public void testCreateModel() { + OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class); + String model = OllamaModelType.LLAMA2; + String modelFilePath = "/somemodel"; + try { + doNothing().when(ollamaAPI).createModel(model, modelFilePath); + ollamaAPI.createModel(model, modelFilePath); + verify(ollamaAPI, times(1)).createModel(model, modelFilePath); + } catch (IOException | OllamaBaseException | InterruptedException e) { + throw new RuntimeException(e); + } + } + + @Test + public void testDeleteModel() { + OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class); + String model = OllamaModelType.LLAMA2; + try { + doNothing().when(ollamaAPI).deleteModel(model, true); + ollamaAPI.deleteModel(model, true); + verify(ollamaAPI, times(1)).deleteModel(model, true); + } catch (IOException | OllamaBaseException | InterruptedException e) { + throw new RuntimeException(e); + } + } + + @Test + public void testGetModelDetails() { + OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class); + String model = OllamaModelType.LLAMA2; + try { + when(ollamaAPI.getModelDetails(model)).thenReturn(new ModelDetail()); + ollamaAPI.getModelDetails(model); + verify(ollamaAPI, times(1)).getModelDetails(model); + } catch (IOException | OllamaBaseException | InterruptedException e) { + throw new RuntimeException(e); + } + } + + @Test + public void testGenerateEmbeddings() { + OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class); + String model = OllamaModelType.LLAMA2; + String prompt = "some prompt text"; + try { + when(ollamaAPI.generateEmbeddings(model, prompt)).thenReturn(new ArrayList<>()); + ollamaAPI.generateEmbeddings(model, prompt); + verify(ollamaAPI, times(1)).generateEmbeddings(model, prompt); + } catch (IOException | OllamaBaseException | InterruptedException e) { + throw new RuntimeException(e); + } + } + + @Test + public void testAsk() { + OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class); + String model = OllamaModelType.LLAMA2; + String prompt = "some prompt text"; + try { + when(ollamaAPI.ask(model, prompt)).thenReturn(new OllamaResult("", 0)); + ollamaAPI.ask(model, prompt); + verify(ollamaAPI, times(1)).ask(model, prompt); + } catch (IOException | OllamaBaseException | InterruptedException e) { + throw new RuntimeException(e); + } + } + + @Test + public void testAskAsync() { + OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class); + String model = OllamaModelType.LLAMA2; + String prompt = "some prompt text"; + when(ollamaAPI.askAsync(model, prompt)).thenReturn(new OllamaAsyncResultCallback(null, null, null)); + ollamaAPI.askAsync(model, prompt); + verify(ollamaAPI, times(1)).askAsync(model, prompt); + } +} diff --git a/src/test/java/io/github/amithkoujalgi/ollama4j/TestMockedAPIs.java b/src/test/java/io/github/amithkoujalgi/ollama4j/unittests/TestMockedAPIs.java similarity index 98% rename from src/test/java/io/github/amithkoujalgi/ollama4j/TestMockedAPIs.java rename to src/test/java/io/github/amithkoujalgi/ollama4j/unittests/TestMockedAPIs.java index f9a2f09..d4c0c13 100644 --- a/src/test/java/io/github/amithkoujalgi/ollama4j/TestMockedAPIs.java +++ b/src/test/java/io/github/amithkoujalgi/ollama4j/unittests/TestMockedAPIs.java @@ -1,4 +1,4 @@ -package io.github.amithkoujalgi.ollama4j; +package io.github.amithkoujalgi.ollama4j.unittests; import io.github.amithkoujalgi.ollama4j.core.OllamaAPI; import io.github.amithkoujalgi.ollama4j.core.exceptions.OllamaBaseException;