Skip to content

Commit

Permalink
Moved to new language
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddenton committed Aug 20, 2024
1 parent 846d710 commit f90e79d
Show file tree
Hide file tree
Showing 49 changed files with 47 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
project: [ connect-pattern, custom-adapter-and-fake, extending-connect-adapters, using-connect-adapters ]
project: [ connect-pattern, custom-api-client-and-fake, extending-connect-api-clients, using-connect-api-clients ]
steps:
- uses: actions/[email protected]
- name: Setup Java
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
These sample projects are designed to demonstrate how easy it is to use the various features of [http4k Connect](https://github.com/http4k/http4k-connect) in isolation. They are all entirely self-contained and can be run locally or using the included script to run them in a Docker container.

- **connect-pattern** : Code accompanying [the post](https://dentondav.id/posts/2021/02/smash-your-adapter-monolith) describing the basic Connect pattern and how it is structured. It only relies on [http4k](https://http4k.org) as a basic implementation platform.
- **extending-connect-adapters** : Shows how to extend the library adapters (in this case GitHub) with custom Action classes.
- **using-connect-adapters** : How to use the library adapters (in this case AWS KMS) and Fake which ship with http4k-connect.
- **custom-adapter-and-fake** : Implementing your own custom http4k-connect compliant adapter and a Fake HTTP system to connect to, along with examples of testing techniques. Also demonstrates the usage of the Kapt compile-time code-generators in a custom adapter.
- **developing-openai-plugins** : Using the http4k-connect-openai-plugin SDK to create OpenAI plugins. This example includes the same example using all of the different OpenAI plugin styles, and installs them into the `FakeOpenAI` so you can interact with them in an authorised way through an OpenAPI interface.
- **fakes-in-official-aws-sdk**: How to use fake AWS adapters with the official V2 AWS SDK in your tests.
- **extending-connect-api-clients** : Shows how to extend the library API Clients (in this case GitHub) with custom Action classes.
- **using-connect-api-clients** : How to use the library API Clients (in this case AWS KMS) and Fake which ship with http4k-connect.
- **custom-api-clients-and-fake** : Implementing your own custom http4k-connect compliant api-clients and a Fake HTTP system to connect to, along with examples of testing techniques. Also demonstrates the usage of the Kapt compile-time code-generators in a custom api-clients.
- **fakes-in-official-aws-sdk**: How to use fake AWS API Clients with the official V2 AWS SDK in your tests.
2 changes: 1 addition & 1 deletion connect-pattern/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
junit_version=5.9.3
kotlin_version=1.9.23
kotlin_version=2.0.10
mockk_version=1.10.5
http4k_version=5.28.0.0
http4k_connect_version=5.21.0.0
2 changes: 1 addition & 1 deletion connect-pattern/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
9 changes: 0 additions & 9 deletions custom-adapter-and-fake/README.md

This file was deleted.

9 changes: 0 additions & 9 deletions custom-adapter-and-fake/src/main/kotlin/ExpensesClient.kt

This file was deleted.

File renamed without changes.
9 changes: 9 additions & 0 deletions custom-api-client-and-fake/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Custom http4k-connect API Clients

This example shows how to:

1. create a basic custom Connect API Client
2. how to generate helper code for the API Client extension functions using KSP.
3. create a Fake HTTP version of the external system which can be used in-memory of over a socket,
4. various testing techniques for API Clients

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
junit_version=5.9.3
kotlin_version=1.9.23
kotlin_version=2.0.10
mockk_version=1.10.5
http4k_version=5.28.0.0
http4k_connect_version=5.21.0.0
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions custom-api-client-and-fake/src/main/kotlin/Expenses.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import actions.GetMyExpenses
import client.ExpensesSystem

/**
* This is a simple domain wrapper for our client.ExpensesSystem adapter
*/
class Expenses(private val expensesSystem: ExpensesSystem) {
fun countExpenses(name: String) = expensesSystem(GetMyExpenses(name)).expenses.size
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import org.http4k.connect.Action

/**
* This is the interface which will encapsulate all Actions
* for the adapter.ExpensesSystem
* for the client.ExpensesSystem
*/
interface ExpensesAction<T> : Action<T>
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package adapter
package client

import actions.ExpensesAction
import org.http4k.connect.Http4kConnectAdapter
import org.http4k.connect.Http4kConnectApiClient

/**
* The main system interface. The Annotation is used by Kapt
* to generate the friendly extension functions.
*/
@Http4kConnectAdapter
@Http4kConnectApiClient
interface ExpensesSystem {
operator fun <R : Any> invoke(action: ExpensesAction<R>): R

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package adapter
package client

import actions.ExpensesAction
import org.http4k.client.JavaHttpClient
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import actions.ExpenseReport
import actions.addExpense
import actions.getMyExpenses
import adapter.ExpensesSystem
import adapter.Http
import client.ExpensesSystem
import client.Http
import com.natpryce.hamkrest.assertion.assertThat
import com.natpryce.hamkrest.equalTo
import com.natpryce.hamkrest.throws
Expand Down Expand Up @@ -49,12 +49,12 @@ class ExpensesSystemAdapterFakeTests {
expensesSystem.addExpense("Bob", 123)
expensesSystem.addExpense("Alice", 456)
expensesSystem.addExpense("Bob", 789)
assertThat(ExpensesClient(expensesSystem).countExpenses("Bob"), equalTo(2))
assertThat(Expenses(expensesSystem).countExpenses("Bob"), equalTo(2))
}

@Test
fun `can find out what happens when get expenses call fails`() {
fakeExpensesSystem.misbehave(ReturnStatus(I_M_A_TEAPOT))
assertThat({ ExpensesClient(expensesSystem).countExpenses("Bob") }, throws<RuntimeException>())
assertThat({ Expenses(expensesSystem).countExpenses("Bob") }, throws<RuntimeException>())
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import actions.ExpenseReport
import actions.GetMyExpenses
import actions.getMyExpenses
import adapter.ExpensesSystem
import client.ExpensesSystem
import com.natpryce.hamkrest.assertion.assertThat
import com.natpryce.hamkrest.equalTo
import io.mockk.every
Expand All @@ -21,7 +21,7 @@ class ExpensesSystemAdapterMockTests {
every { mockExpensesSystem.getMyExpenses("Bob") } returns
ExpenseReport("Bob", listOf(Expense(1, "Expense 0", 66)))

assertThat(ExpensesClient(mockExpensesSystem).countExpenses("Bob"), equalTo(1))
assertThat(Expenses(mockExpensesSystem).countExpenses("Bob"), equalTo(1))
}

@Test
Expand All @@ -31,6 +31,6 @@ class ExpensesSystemAdapterMockTests {
every { mockExpensesSystem(any<GetMyExpenses>()) } returns
ExpenseReport("Bob", listOf(Expense(1, "Expense 0", 66)))

assertThat(ExpensesClient(mockExpensesSystem).countExpenses("Bob"), equalTo(1))
assertThat(Expenses(mockExpensesSystem).countExpenses("Bob"), equalTo(1))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ class ExpensesSystemAdapterStubTests {
expensesSystem.addExpense("Bob", 123)
expensesSystem.addExpense("Alice", 456)
expensesSystem.addExpense("Bob", 789)
assertThat(ExpensesClient(expensesSystem).countExpenses("Bob"), equalTo(2))
assertThat(Expenses(expensesSystem).countExpenses("Bob"), equalTo(2))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import actions.AddExpense
import actions.ExpenseReport
import actions.ExpensesAction
import actions.GetMyExpenses
import adapter.ExpensesSystem
import client.ExpensesSystem
import model.Expense
import org.http4k.connect.storage.InMemory
import org.http4k.connect.storage.Storage
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
junit_version=5.9.3
kotlin_version=1.9.23
kotlin_version=2.0.10
mockk_version=1.10.5
http4k_version=5.28.0.0
http4k_connect_version=5.21.0.0
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion fakes-in-official-aws-sdk/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
kotlin_version=1.9.23
kotlin_version=2.0.10
aws_sdk_version=2.20.103
http4k_version=5.28.0.0
http4k_connect_version=5.21.0.0
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
junit_version=5.9.3
kotlin_version=1.9.23
kotlin_version=2.0.10
mockk_version=1.10.5
http4k_version=5.28.0.0
http4k_connect_version=5.21.0.0
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
File renamed without changes.
File renamed without changes.

0 comments on commit f90e79d

Please sign in to comment.