Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 39 additions & 23 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,49 @@ on:
branches: [ "master" ]

permissions:
contents: read
contents: write
pull-requests: write

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: maven

- name: Build and Test with Maven
run: mvn -B test

- name: Add JaCoCo PR Comment
uses: madrapps/jacoco-report@v1.6.1
if: github.event_name == 'pull_request'
with:
paths: ${{ github.workspace }}/target/site/jacoco/jacoco.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 80
min-coverage-changed-files: 80
title: 'Code Coverage Report'
update-comment: true
- uses: actions/checkout@v4

- name: Set up JDK 25
uses: actions/setup-java@v4
with:
java-version: '25'
distribution: 'temurin'
cache: maven

- name: Build and Test with Maven
run: mvn -B test

- name: Add JaCoCo PR Comment
uses: madrapps/jacoco-report@v1.6.1
if: github.event_name == 'pull_request'
with:
paths: ${{ github.workspace }}/target/site/jacoco/jacoco.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 80
min-coverage-changed-files: 80
title: 'Code Coverage Report'
update-comment: true

- name: Generate JaCoCo Badge
uses: cicirello/jacoco-badge-generator@v2
if: github.ref == 'refs/heads/master'
with:
badges-directory: .github/badges
generate-branches-badge: true

- name: Commit and push badge
if: github.ref == 'refs/heads/master'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .github/badges
git diff --staged --quiet || git commit -m "chore: update coverage badge [skip ci]"
git push
33 changes: 29 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.release>25</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down Expand Up @@ -44,16 +43,21 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<version>3.5.0</version>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.11</version>
<version>0.8.13</version>
<executions>
<execution>
<goals>
Expand All @@ -67,6 +71,27 @@
<goal>report</goal>
</goals>
</execution>
<execution>
<id>check</id>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.50</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
59 changes: 59 additions & 0 deletions src/test/java/de/asedem/service/CopyServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package de.asedem.service;

import de.asedem.Ollama;
import de.asedem.exception.OllamaConnectionException;
import de.asedem.rest.HttpMethode;
import de.asedem.rest.Rest;
import de.asedem.rest.RestResponse;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.*;

class CopyServiceTest {

@Test
void testMethodCall() {

final Ollama ollama = Ollama.initDefault();

try (MockedStatic<Rest> utilities = Mockito.mockStatic(Rest.class)) {
utilities.when(() -> Rest.requestSync(ollama.buildUrl("/api/copy"),
HttpMethode.POST, new CopyService.CopyRequest("llama2:latest", "llama2:copy")))
.thenReturn(new RestResponse(200, ""));

assertTrue(ollama.copy("llama2:latest", "llama2:copy"));
}
}

@Test
void testFalseIfNotSuccessful() {

final Ollama ollama = Ollama.initDefault();

try (MockedStatic<Rest> utilities = Mockito.mockStatic(Rest.class)) {
utilities.when(() -> Rest.requestSync(ollama.buildUrl("/api/copy"),
HttpMethode.POST, new CopyService.CopyRequest("llama2:latest", "llama2:copy")))
.thenReturn(new RestResponse(404, ""));

assertFalse(ollama.copy("llama2:latest", "llama2:copy"));
}
}

@Test
void testException() {

final Ollama ollama = Ollama.initDefault();

try (MockedStatic<Rest> utilities = Mockito.mockStatic(Rest.class)) {
utilities.when(() -> Rest.requestSync(ollama.buildUrl("/api/copy"),
HttpMethode.POST, new CopyService.CopyRequest("llama2:latest", "llama2:copy")))
.thenThrow(new IOException());

assertThrows(OllamaConnectionException.class, () -> ollama.copy("llama2:latest", "llama2:copy"));
}
}
}
59 changes: 59 additions & 0 deletions src/test/java/de/asedem/service/DeleteServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package de.asedem.service;

import de.asedem.Ollama;
import de.asedem.exception.OllamaConnectionException;
import de.asedem.rest.HttpMethode;
import de.asedem.rest.Rest;
import de.asedem.rest.RestResponse;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.*;

class DeleteServiceTest {

@Test
void testMethodCall() {

final Ollama ollama = Ollama.initDefault();

try (MockedStatic<Rest> utilities = Mockito.mockStatic(Rest.class)) {
utilities.when(() -> Rest.requestSync(ollama.buildUrl("/api/delete"),
HttpMethode.POST, new DeleteService.DeleteRequest("llama2:latest")))
.thenReturn(new RestResponse(200, ""));

assertTrue(ollama.delete("llama2:latest"));
}
}

@Test
void testFalseIfNotSuccessful() {

final Ollama ollama = Ollama.initDefault();

try (MockedStatic<Rest> utilities = Mockito.mockStatic(Rest.class)) {
utilities.when(() -> Rest.requestSync(ollama.buildUrl("/api/delete"),
HttpMethode.POST, new DeleteService.DeleteRequest("llama2:latest")))
.thenReturn(new RestResponse(404, ""));

assertFalse(ollama.delete("llama2:latest"));
}
}

@Test
void testException() {

final Ollama ollama = Ollama.initDefault();

try (MockedStatic<Rest> utilities = Mockito.mockStatic(Rest.class)) {
utilities.when(() -> Rest.requestSync(ollama.buildUrl("/api/delete"),
HttpMethode.POST, new DeleteService.DeleteRequest("llama2:latest")))
.thenThrow(new IOException());

assertThrows(OllamaConnectionException.class, () -> ollama.delete("llama2:latest"));
}
}
}
56 changes: 56 additions & 0 deletions src/test/java/de/asedem/service/ShowInfoServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package de.asedem.service;

import de.asedem.Ollama;
import de.asedem.exception.OllamaConnectionException;
import de.asedem.model.ModelInfo;
import de.asedem.rest.HttpMethode;
import de.asedem.rest.Rest;
import de.asedem.rest.RestResponse;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.*;

class ShowInfoServiceTest {

@Test
void testMethodCall() {

final Ollama ollama = Ollama.initDefault();

try (MockedStatic<Rest> utilities = Mockito.mockStatic(Rest.class)) {
utilities.when(() -> Rest.requestSync(ollama.buildUrl("/api/show"), HttpMethode.POST, "llama2:latest"))
.thenReturn(new RestResponse(200, """
{
"license": "MIT",
"modelfile": "# Modelfile",
"parameters": "num_ctx 4096",
"template": "{{ .Prompt }}"
}
"""));

final ModelInfo modelInfo = ollama.showInfo("llama2:latest");

assertEquals("MIT", modelInfo.license());
assertEquals("# Modelfile", modelInfo.modelFile());
assertEquals("num_ctx 4096", modelInfo.parameters());
assertEquals("{{ .Prompt }}", modelInfo.template());
}
}

@Test
void testException() {

final Ollama ollama = Ollama.initDefault();

try (MockedStatic<Rest> utilities = Mockito.mockStatic(Rest.class)) {
utilities.when(() -> Rest.requestSync(ollama.buildUrl("/api/show"), HttpMethode.POST, "llama2:latest"))
.thenThrow(new IOException());

assertThrows(OllamaConnectionException.class, () -> ollama.showInfo("llama2:latest"));
}
}
}
Loading