Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wiremock #2

Merged
merged 5 commits into from
Nov 2, 2024
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
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ indent_size = 4
max_line_length = 100
ij_kotlin_name_count_to_use_star_import = 999
ij_kotlin_name_count_to_use_star_import_for_members = 999
ktlint_function_naming_ignore_when_annotated_with = "Test"
3 changes: 2 additions & 1 deletion .idea/externalDependencies.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
-Dkotlin.compiler.incremental=true
-Dmaven.install.skip=true
-T12C
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
build:
mvn clean verify site
lint:
# brew install ktlint
ktlint --format
23 changes: 7 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
# awesome-kotlin-maven-template
# Finchly
## Helper utilities for integration testing

[![Kotlin CI with Maven](https://github.com/kpavlov/awesome-kotlin-maven-template/actions/workflows/maven.yml/badge.svg?branch=main)](https://github.com/kpavlov/awesome-kotlin-maven-template/actions/workflows/maven.yml)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/644f664ad05a4a009b299bc24c8be4b8)](https://app.codacy.com/gh/kpavlov/langchain4j-kotlin/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[![Codacy Coverage](https://app.codacy.com/project/badge/Coverage/644f664ad05a4a009b299bc24c8be4b8)](https://app.codacy.com/gh/kpavlov/langchain4j-kotlin/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
[![Kotlin CI with Maven](https://github.com/kpavlov/finchly/actions/workflows/maven.yml/badge.svg?branch=main)](https://github.com/kpavlov/finchly/actions/workflows/maven.yml)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/3aa0b5847e70494d9795ff98aa14b386)](https://app.codacy.com/gh/kpavlov/langchain4j-kotlin/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[![Codacy Coverage](https://app.codacy.com/project/badge/Coverage/3aa0b5847e70494d9795ff98aa14b386)](https://app.codacy.com/gh/kpavlov/langchain4j-kotlin/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)

![logo](docs/finchly-logo.webp)

## How to run

Create `.env` file in root directory and add your API keys:

```dotenv
OPENAI_API_KEY=sk-xxxxx
```
## How to build

Building project locally:
```shell
Expand All @@ -22,8 +18,3 @@ or
make build
```

## Acknowledgements

Training data from Project Gutenberg:

- [CAPTAIN BLOOD By Rafael Sabatini](https://www.gutenberg.org/cache/epub/1965/pg1965.txt)
10 changes: 5 additions & 5 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>me.kpavlov.project</groupId>
<artifactId>project-aggregator</artifactId>
<groupId>me.kpavlov.finchly</groupId>
<artifactId>aggregator</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>bom</artifactId>
<packaging>pom</packaging>

<name>Project :: BOM</name>
<description>Bill of Materials POM for getting full, complete set of compatible versions of LangChain4j modules
<name>Finchly :: BOM</name>
<description>Bill of Materials POM for getting full, complete set of compatible versions of Finchly modules
</description>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>me.kpavlov.project</groupId>
<artifactId>core</artifactId>
<artifactId>wiremock</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>
Expand Down
8 changes: 8 additions & 0 deletions detekt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
style:
active: true
MethodName:
active: true
ignoreOverriddenFunctions: true
excludeAnnotatedMethodsOrClasses:
- "org.junit.jupiter.api.Test"
ignoreTestFiles: true
Binary file added docs/finchly-logo.webp
Binary file not shown.
35 changes: 26 additions & 9 deletions parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>me.kpavlov.project</groupId>
<groupId>me.kpavlov.finchly</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Project :: Parent POM</name>
<description>Parent POM for Project modules</description>
<url>https://github.com/kpavlov/awesome-kotlin-maven-template</url>
<url>https://github.com/kpavlov/finchly</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -22,10 +22,12 @@
<java.compiler.release>${java.version}</java.compiler.release>
<argLine></argLine>
<!-- Dependencies -->
<assertk.versopn>0.28.1</assertk.versopn>
<kotlinx.version>1.9.0</kotlinx.version>
<junit.version>5.11.3</junit.version>
<awaitility.version>4.2.2</awaitility.version>
<dotenv-kotlin.version>6.4.2</dotenv-kotlin.version>
<wiremock.version>3.9.2</wiremock.version>
</properties>

<repositories>
Expand All @@ -36,6 +38,8 @@
</repositories>

<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<pluginManagement>
<plugins>
<plugin>
Expand All @@ -46,7 +50,6 @@
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
<arg>-Werror</arg>
</args>
</configuration>
<executions>
Expand Down Expand Up @@ -156,24 +159,38 @@
<version>${kotlinx.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.willowtreeapps.assertk</groupId>
<artifactId>assertk-jvm</artifactId>
<version>${assertk.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.willowtreeapps.assertk</groupId>
<artifactId>assertk-coroutines-jvm</artifactId>
<version>${assertk.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
<scope>test</scope>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<!-- Test Dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
<groupId>com.willowtreeapps.assertk</groupId>
<artifactId>assertk-jvm</artifactId>
<version>${assertk.versopn}</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
15 changes: 12 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,29 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>me.kpavlov.project</groupId>
<artifactId>project-aggregator</artifactId>
<groupId>me.kpavlov.finchly</groupId>
<artifactId>aggregator</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Project :: Aggregator</name>

<modules>
<module>parent</module>
<module>bom</module>
<module>core</module>
<module>wiremock</module>
<module>reports</module>
</modules>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.21.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
2 changes: 1 addition & 1 deletion renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"packageRules": [
{
"matchPackageNames": [
"me.kpavlov.project"
"me.kpavlov.finchly"
],
"enabled": false
},
Expand Down
10 changes: 5 additions & 5 deletions reports/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>me.kpavlov.project</groupId>
<artifactId>project-aggregator</artifactId>
<groupId>me.kpavlov.finchly</groupId>
<artifactId>aggregator</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>reports</artifactId>
<packaging>pom</packaging>
<name>Project :: Reports</name>
<name>Finchly :: Reports</name>

<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

<dependencies>
<dependency>
<groupId>me.kpavlov.project</groupId>
<artifactId>core</artifactId>
<groupId>me.kpavlov.finchly</groupId>
<artifactId>wiremock</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>
Expand Down
26 changes: 26 additions & 0 deletions wiremock/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>me.kpavlov.finchly</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

<artifactId>wiremock</artifactId>
<name>Finchly :: Wiremock</name>

<dependencies>
<!-- https://mvnrepository.com/artifact/org.wiremock/wiremock-standalone -->
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock-standalone</artifactId>
<version>${wiremock.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package me.kpavlov.finchly.wiremock

import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.VerificationException

/**
* Base class for managing a WireMock server instance.
*
* The server is started upon initialization.
* Provides utility methods for managing stub mappings and verifying unmatched requests.
*
* @param mock The WireMock server instance to manage.
*/
public abstract class BaseWiremock(
protected val mock: WireMockServer,
) {
init {
mock.start()
}

/**
* Retrieves the port number on which the WireMock server instance is running.
*
* @return the port number on which the WireMock server instance is listening.
*/
public fun port(): Int = mock.port()

/**
* Removes a specific stub mapping from the WireMock server.
*
* @param mapping The stub mapping to remove.
*/
public fun resetStub(mapping: com.github.tomakehurst.wiremock.stubbing.StubMapping) {
mock.removeStub(mapping)
}

/**
* Resets all the stub mappings in the WireMock server instance.
*
* This function clears all the stub mappings that have been set up in the WireMock server.
* After calling this method, the server will no longer have any of the previously configured stubs.
*/
public fun resetAllStubs() {
mock.resetAll()
}

/**
* Verifies that there are no unmatched requests for the WireMock server.
*
* This function checks the WireMock server for any requests that were not matched against
* any stub mappings. If there are unmatched requests, it will find near misses and throw an
* appropriate `VerificationException`.
*
* @throws VerificationException if there are unmatched requests or near misses.
*/
public fun verifyNoUnmatchedRequests() {
val unmatchedRequests = mock.findAllUnmatchedRequests()
if (unmatchedRequests.isEmpty()) {
return
}
println("Unmatched requests: $unmatchedRequests")
val nearMisses = mock.findNearMissesForAllUnmatchedRequests()
if (nearMisses.isEmpty()) {
throw VerificationException.forUnmatchedRequests(unmatchedRequests)
} else {
throw VerificationException.forUnmatchedNearMisses(nearMisses)
}
}
}
Loading