-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testcontainers for Java: Add showcase examples for different scenarios
- Loading branch information
Showing
18 changed files
with
938 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Testcontainers for Java | ||
on: | ||
|
||
pull_request: | ||
branches: [ main ] | ||
paths: | ||
- '.github/workflows/testcontainers-java.yml' | ||
- 'testing/testcontainers/java/**' | ||
push: | ||
branches: [ main ] | ||
paths: | ||
- '.github/workflows/testcontainers-java.yml' | ||
- 'testing/testcontainers/java/**' | ||
|
||
# Allow job to be triggered manually. | ||
workflow_dispatch: | ||
|
||
# Cancel in-progress jobs when pushing to the same branch. | ||
concurrency: | ||
cancel-in-progress: true | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
|
||
jobs: | ||
test: | ||
name: "CrateDB: ${{ matrix.cratedb-version }} | ||
on ${{ matrix.os }}" | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ "ubuntu-latest" ] | ||
|
||
steps: | ||
|
||
- name: Acquire sources | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Java | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: "temurin" | ||
java-version: "17" | ||
cache: "gradle" | ||
|
||
- name: Run software tests | ||
run: | | ||
cd testing/testcontainers/java | ||
./gradlew check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.gradle/ | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
build/ | ||
out/ | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
####################### | ||
Testcontainers for Java | ||
####################### | ||
|
||
*How to run integration tests of Java applications with CrateDB.* | ||
|
||
|
||
***** | ||
About | ||
***** | ||
|
||
Introduction | ||
============ | ||
|
||
`Testcontainers for Java`_ is a Java library that supports JUnit tests, | ||
providing lightweight, throwaway instances of common databases suitable | ||
for integration testing scenarios. | ||
|
||
The `Testcontainers CrateDB Module`_ will provide your application test | ||
framework with a single-node CrateDB instance. You will be able to choose | ||
the `CrateDB OCI image`_ variant by version, or by selecting the ``nightly`` | ||
release. | ||
|
||
What's inside | ||
============= | ||
|
||
This directory includes different canonical examples how to use those | ||
components within test harnesses of custom applications. Currently, | ||
all test cases are based on JUnit 4. | ||
|
||
|
||
***** | ||
Usage | ||
***** | ||
|
||
1. Make sure Java 17 is installed. | ||
2. Run CrateDB:: | ||
|
||
docker run -it --rm --publish=4200:4200 --publish=5432:5432 \ | ||
crate:latest -Cdiscovery.type=single-node | ||
|
||
3. Invoke example application:: | ||
|
||
./gradlew run --args="jdbc:crate://localhost:5432/" | ||
./gradlew run --args="jdbc:postgresql://localhost:5432/" | ||
|
||
3. Invoke software tests:: | ||
|
||
# Run all tests. | ||
./gradlew test | ||
|
||
# Run individual tests. | ||
./gradlew test --tests TestFunctionScope | ||
|
||
# Run test case showing how to select CrateDB version per environment variable. | ||
export CRATEDB_VERSION=nightly | ||
./gradlew test --tests TestSharedSingletonMatrix | ||
|
||
|
||
.. _CrateDB OCI image: https://hub.docker.com/_/crate | ||
.. _Testcontainers for Java: https://github.com/testcontainers/testcontainers-java | ||
.. _Testcontainers CrateDB Module: https://www.testcontainers.org/modules/databases/cratedb/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* An example application for demonstrating "Testcontainers for Java" with CrateDB and the PostgreSQL JDBC driver. | ||
*/ | ||
|
||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
} | ||
} | ||
|
||
plugins { | ||
id 'application' | ||
id 'com.adarshr.test-logger' version '3.2.0' | ||
id 'idea' | ||
id 'java' | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
mavenLocal() | ||
} | ||
|
||
dependencies { | ||
implementation 'org.postgresql:postgresql:42.6.0' | ||
implementation 'io.crate:crate-jdbc:2.6.0' | ||
implementation 'org.slf4j:slf4j-api:2.0.7' | ||
implementation 'org.slf4j:slf4j-simple:2.0.7' | ||
testImplementation 'junit:junit:4.13.2' | ||
testImplementation 'org.testcontainers:testcontainers:1.18.0' | ||
testImplementation 'org.testcontainers:cratedb:1.18.0' | ||
testImplementation 'org.testcontainers:postgresql:1.18.0' | ||
} | ||
|
||
java { | ||
toolchain { | ||
languageVersion = JavaLanguageVersion.of(17) | ||
} | ||
} | ||
|
||
jar { | ||
archiveBaseName = 'cratedb-example-testcontainers-java' | ||
archiveVersion = '0.0.1-SNAPSHOT' | ||
} | ||
|
||
sourceSets { | ||
main { | ||
java.srcDirs += [ | ||
"src/generated/java", | ||
"src/main/java", | ||
] | ||
} | ||
} | ||
|
||
test { | ||
dependsOn 'cleanTest' | ||
} | ||
|
||
apply plugin: "java" | ||
apply plugin: "application" | ||
|
||
application { | ||
mainClass = 'io.crate.example.testing.Application' | ||
} | ||
|
||
ext.javaMainClass = "io.crate.example.testing.Application" | ||
|
||
|
||
idea.module.inheritOutputDirs = true | ||
processResources.destinationDir = compileJava.destinationDir | ||
compileJava.dependsOn processResources |
Binary file not shown.
5 changes: 5 additions & 0 deletions
5
testing/testcontainers/java/gradle/wrapper/gradle-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.