mirror of
				https://github.com/amithkoujalgi/ollama4j.git
				synced 2025-11-04 02:20:50 +01:00 
			
		
		
		
	Added surefire and failsafe plugins
This commit is contained in:
		
							
								
								
									
										4
									
								
								.github/workflows/build-on-pr-create.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.github/workflows/build-on-pr-create.yml
									
									
									
									
										vendored
									
									
								
							@@ -28,7 +28,7 @@ jobs:
 | 
				
			|||||||
          settings-path: ${{ github.workspace }} # location for the settings.xml file
 | 
					          settings-path: ${{ github.workspace }} # location for the settings.xml file
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      - name: Build with Maven
 | 
					      - name: Build with Maven
 | 
				
			||||||
        run: mvn -U -B clean package --file pom.xml
 | 
					        run: mvn --file pom.xml -U clean package
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      - name: Run Tests
 | 
					      - name: Run Tests
 | 
				
			||||||
        run: mvn -U clean verify --file pom.xml
 | 
					        run: mvn --file pom.xml -U clean test -Punit-tests
 | 
				
			||||||
							
								
								
									
										2
									
								
								.github/workflows/maven-publish.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/maven-publish.yml
									
									
									
									
										vendored
									
									
								
							@@ -34,7 +34,7 @@ jobs:
 | 
				
			|||||||
      #        run: mvn -U clean verify --file pom.xml
 | 
					      #        run: mvn -U clean verify --file pom.xml
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      - name: Build with Maven
 | 
					      - 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)
 | 
					      - name: Set up Apache Maven Central (Overwrite settings.xml)
 | 
				
			||||||
        uses: actions/setup-java@v3
 | 
					        uses: actions/setup-java@v3
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								.github/workflows/publish-javadoc.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/publish-javadoc.yml
									
									
									
									
										vendored
									
									
								
							@@ -39,7 +39,7 @@ jobs:
 | 
				
			|||||||
          server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
 | 
					          server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
 | 
				
			||||||
          settings-path: ${{ github.workspace }} # location for the settings.xml file
 | 
					          settings-path: ${{ github.workspace }} # location for the settings.xml file
 | 
				
			||||||
      - name: Build with Maven
 | 
					      - name: Build with Maven
 | 
				
			||||||
        run: mvn -U -B clean package --file pom.xml
 | 
					        run: mvn --file pom.xml -U clean package
 | 
				
			||||||
      - name: Setup Pages
 | 
					      - name: Setup Pages
 | 
				
			||||||
        uses: actions/configure-pages@v3
 | 
					        uses: actions/configure-pages@v3
 | 
				
			||||||
      - name: Upload artifact
 | 
					      - name: Upload artifact
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										5
									
								
								Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								Makefile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					ut:
 | 
				
			||||||
 | 
						mvn clean test -Punit-tests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					it:
 | 
				
			||||||
 | 
						mvn clean verify -Pintegration-tests
 | 
				
			||||||
							
								
								
									
										55
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										55
									
								
								pom.xml
									
									
									
									
									
								
							@@ -16,6 +16,8 @@
 | 
				
			|||||||
    <maven.compiler.source>11</maven.compiler.source>
 | 
					    <maven.compiler.source>11</maven.compiler.source>
 | 
				
			||||||
    <maven.compiler.target>11</maven.compiler.target>
 | 
					    <maven.compiler.target>11</maven.compiler.target>
 | 
				
			||||||
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 | 
					    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 | 
				
			||||||
 | 
					    <maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
 | 
				
			||||||
 | 
					    <maven-failsafe-plugin.version>3.0.0-M5</maven-failsafe-plugin.version>
 | 
				
			||||||
  </properties>
 | 
					  </properties>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <developers>
 | 
					  <developers>
 | 
				
			||||||
@@ -100,6 +102,42 @@
 | 
				
			|||||||
          </execution>
 | 
					          </execution>
 | 
				
			||||||
        </executions>
 | 
					        </executions>
 | 
				
			||||||
      </plugin>
 | 
					      </plugin>
 | 
				
			||||||
 | 
					      <!-- Surefire Plugin for Unit Tests -->
 | 
				
			||||||
 | 
					      <plugin>
 | 
				
			||||||
 | 
					        <groupId>org.apache.maven.plugins</groupId>
 | 
				
			||||||
 | 
					        <artifactId>maven-surefire-plugin</artifactId>
 | 
				
			||||||
 | 
					        <version>${maven-surefire-plugin.version}</version>
 | 
				
			||||||
 | 
					        <configuration>
 | 
				
			||||||
 | 
					          <skipTests>${skipUnitTests}</skipTests>
 | 
				
			||||||
 | 
					          <includes>
 | 
				
			||||||
 | 
					            <include>**/unittests/*.java</include>
 | 
				
			||||||
 | 
					          </includes>
 | 
				
			||||||
 | 
					        </configuration>
 | 
				
			||||||
 | 
					      </plugin>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      <!-- Failsafe Plugin for Integration Tests -->
 | 
				
			||||||
 | 
					      <plugin>
 | 
				
			||||||
 | 
					        <groupId>org.apache.maven.plugins</groupId>
 | 
				
			||||||
 | 
					        <artifactId>maven-failsafe-plugin</artifactId>
 | 
				
			||||||
 | 
					        <version>${maven-failsafe-plugin.version}</version>
 | 
				
			||||||
 | 
					        <configuration>
 | 
				
			||||||
 | 
					          <includes>
 | 
				
			||||||
 | 
					            <include>**/integrationtests/*.java</include>
 | 
				
			||||||
 | 
					          </includes>
 | 
				
			||||||
 | 
					          <excludes>
 | 
				
			||||||
 | 
					            <exclude>**/unittests/*.java</exclude>
 | 
				
			||||||
 | 
					          </excludes>
 | 
				
			||||||
 | 
					        </configuration>
 | 
				
			||||||
 | 
					        <executions>
 | 
				
			||||||
 | 
					          <execution>
 | 
				
			||||||
 | 
					            <goals>
 | 
				
			||||||
 | 
					              <goal>integration-test</goal>
 | 
				
			||||||
 | 
					              <goal>verify</goal>
 | 
				
			||||||
 | 
					            </goals>
 | 
				
			||||||
 | 
					          </execution>
 | 
				
			||||||
 | 
					        </executions>
 | 
				
			||||||
 | 
					      </plugin>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    </plugins>
 | 
					    </plugins>
 | 
				
			||||||
  </build>
 | 
					  </build>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -145,4 +183,21 @@
 | 
				
			|||||||
    </repository>
 | 
					    </repository>
 | 
				
			||||||
  </distributionManagement>
 | 
					  </distributionManagement>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <profiles>
 | 
				
			||||||
 | 
					    <profile>
 | 
				
			||||||
 | 
					      <id>unit-tests</id>
 | 
				
			||||||
 | 
					      <properties>
 | 
				
			||||||
 | 
					        <test.env>unit</test.env>
 | 
				
			||||||
 | 
					        <skipUnitTests>false</skipUnitTests>
 | 
				
			||||||
 | 
					      </properties>
 | 
				
			||||||
 | 
					    </profile>
 | 
				
			||||||
 | 
					    <profile>
 | 
				
			||||||
 | 
					      <id>integration-tests</id>
 | 
				
			||||||
 | 
					      <properties>
 | 
				
			||||||
 | 
					        <test.env>integration</test.env>
 | 
				
			||||||
 | 
					        <skipUnitTests>true</skipUnitTests>
 | 
				
			||||||
 | 
					      </properties>
 | 
				
			||||||
 | 
					    </profile>
 | 
				
			||||||
 | 
					  </profiles>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
</project>
 | 
					</project>
 | 
				
			||||||
@@ -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);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -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.OllamaAPI;
 | 
				
			||||||
import io.github.amithkoujalgi.ollama4j.core.exceptions.OllamaBaseException;
 | 
					import io.github.amithkoujalgi.ollama4j.core.exceptions.OllamaBaseException;
 | 
				
			||||||
		Reference in New Issue
	
	Block a user