-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make SonataFlow images deps available offline, fix jbang setup and deps
Signed-off-by: Ricardo Zanini <[email protected]>
- Loading branch information
1 parent
5621502
commit 4513faf
Showing
12 changed files
with
244 additions
and
141 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,21 @@ | ||
# Tests in Shell | ||
|
||
## Running Tests With JBang | ||
|
||
- Install JBang | ||
- Install VSCode Red Hat's Java plugin | ||
- Install VSCode JBang plugin | ||
|
||
You can then edit the files in `kogito-swf-builder` and `kogito-swf-devmode` with intellisense. | ||
|
||
The `run.sh` should be used to run the tests since it must set a few env vars. To run from your terminal, try: | ||
|
||
```shell | ||
tests/shell/run.sh kogito-swf-devmode quay.io/kiegroup/kogito-swf-devmode:999-SNAPSHOT | ||
``` | ||
|
||
The first argument is the test case to run and the second, the image. | ||
|
||
Under the hood, it uses [Junit's Console Launcher](https://junit.org/junit5/docs/current/user-guide/#running-tests-console-launcher) tool to run the tests from the command line. | ||
|
||
Update this file with new findings, and don't remove the `.vscode` folder. It's useful to run JBang from the IDE. |
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,22 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "java", | ||
"name": "RunTests-port-4004", | ||
"request": "attach", | ||
"hostName": "localhost", | ||
"port": 4004 | ||
}, | ||
{ | ||
"type": "java", | ||
"name": "Debug (Launch) - RunTests", | ||
"request": "launch", | ||
"mainClass": "RunTests", | ||
"projectName": "RunTests" | ||
} | ||
] | ||
} |
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,18 @@ | ||
{ | ||
"java.import.gradle.enabled": false, | ||
"java.import.maven.enabled": false, | ||
"java.eclipse.downloadSources": true, | ||
"files.exclude": { | ||
"bin/": true, | ||
".eclipse/": true, | ||
".project": true, | ||
".classpath": true, | ||
"build.gradle": true | ||
}, | ||
"java.completion.importOrder": [ | ||
"", | ||
"javax", | ||
"java", | ||
"#" | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
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
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,121 @@ | ||
///usr/bin/env jbang "$0" "$@" ; exit $? | ||
|
||
//DEPS org.slf4j:slf4j-simple:2.0.9 | ||
|
||
// Junit console to start the test engine: | ||
//DEPS org.junit.platform:junit-platform-console:1.10.1 | ||
|
||
// engine to run the tests (tests are written with Junit5): | ||
//DEPS org.junit.jupiter:junit-jupiter-engine:5.10.1 | ||
|
||
// testcontainers | ||
//DEPS org.testcontainers:testcontainers:1.19.3 | ||
//DEPS org.testcontainers:junit-jupiter:1.19.3 | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.net.http.HttpClient; | ||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpResponse; | ||
import java.net.http.HttpResponse.BodyHandlers; | ||
import java.nio.file.Paths; | ||
import java.time.Duration; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.platform.console.ConsoleLauncher; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.output.Slf4jLogConsumer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
import org.testcontainers.images.builder.ImageFromDockerfile; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
@Testcontainers | ||
public class RunTests { | ||
|
||
private static Logger LOGGER = LoggerFactory.getLogger(RunTests.class); | ||
|
||
private Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(LOGGER); | ||
|
||
@Container | ||
private GenericContainer greetBuiltImage = new GenericContainer( | ||
new ImageFromDockerfile( | ||
"dev.local/jbang-test/swf-test:" + Math.round(Math.random() * 1000000.00)) | ||
.withDockerfile(Paths.get(getScriptDirPath(), "resources/greet", "Dockerfile")) | ||
.withBuildArg("BUILDER_IMAGE_TAG", getTestImage())) | ||
.withExposedPorts(8080) | ||
.waitingFor(Wait.forHttp("/jsongreet")) | ||
.withLogConsumer(logConsumer); | ||
|
||
@Test | ||
public void testBuiltContainerAnswerCorrectly() throws URISyntaxException, IOException, InterruptedException { | ||
greetBuiltImage.start(); | ||
HttpRequest request = HttpRequest.newBuilder() | ||
.uri(new URI("http://" + greetBuiltImage.getHost() + ":" | ||
+ greetBuiltImage.getFirstMappedPort() + "/jsongreet")) | ||
.header("Content-Type", "application/json") | ||
.header("Accept", "application/json") | ||
.timeout(Duration.ofSeconds(10)) | ||
.POST(HttpRequest.BodyPublishers | ||
.ofString("{\"workflowdata\" : {\"name\": \"John\", \"language\": \"English\"}}")) | ||
.build(); | ||
HttpResponse<String> response = HttpClient.newHttpClient().send(request, BodyHandlers.ofString()); | ||
assertEquals(201, response.statusCode()); | ||
greetBuiltImage.stop(); | ||
} | ||
|
||
@Container | ||
private GenericContainer greetWithInputSchemaBuiltImage = new GenericContainer( | ||
new ImageFromDockerfile( | ||
"dev.local/jbang-test/swf-test:" + Math.round(Math.random() * 1000000.00)) | ||
.withDockerfile(Paths.get(getScriptDirPath(), | ||
"resources/greet-with-inputschema", "Dockerfile")) | ||
.withBuildArg("BUILDER_IMAGE_TAG", getTestImage())) | ||
.withExposedPorts(8080) | ||
.waitingFor(Wait.forHttp("/greeting")) | ||
.withLogConsumer(logConsumer); | ||
|
||
@Test | ||
public void testBuiltContainerWithInputSchemaAnswerCorrectly() | ||
throws URISyntaxException, IOException, InterruptedException { | ||
greetWithInputSchemaBuiltImage.start(); | ||
HttpRequest request = HttpRequest.newBuilder() | ||
.uri(new URI("http://" + greetWithInputSchemaBuiltImage.getHost() + ":" | ||
+ greetWithInputSchemaBuiltImage.getFirstMappedPort() + "/greeting")) | ||
.header("Content-Type", "application/json") | ||
.header("Accept", "application/json") | ||
.timeout(Duration.ofSeconds(10)) | ||
.POST(HttpRequest.BodyPublishers | ||
.ofString("{\"name\": \"John\", \"language\": \"English\"}")) | ||
.build(); | ||
HttpResponse<String> response = HttpClient.newHttpClient().send(request, BodyHandlers.ofString()); | ||
assertEquals(201, response.statusCode()); | ||
greetWithInputSchemaBuiltImage.stop(); | ||
} | ||
|
||
public static void main(String... args) throws Exception { | ||
// Log docker build. Source: | ||
// https://github.com/testcontainers/testcontainers-java/issues/3093 | ||
System.setProperty( | ||
"org.slf4j.simpleLogger.log.com.github.dockerjava.api.command.BuildImageResultCallback", | ||
"debug"); | ||
ConsoleLauncher.main("--select-class=" + RunTests.class.getName(), | ||
"--reports-dir=" + Paths.get(getOutputDir()).toString()); | ||
} | ||
|
||
static String getTestImage() { | ||
return System.getenv("TEST_IMAGE"); | ||
} | ||
|
||
static String getOutputDir() { | ||
return System.getenv("OUTPUT_DIR"); | ||
} | ||
|
||
static String getScriptDirPath() { | ||
return System.getenv("TESTS_SCRIPT_DIR_PATH"); | ||
} | ||
} |
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,22 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "java", | ||
"name": "RunTests-port-4004", | ||
"request": "attach", | ||
"hostName": "localhost", | ||
"port": 4004 | ||
}, | ||
{ | ||
"type": "java", | ||
"name": "Debug (Launch) - RunTests", | ||
"request": "launch", | ||
"mainClass": "RunTests", | ||
"projectName": "RunTests" | ||
} | ||
] | ||
} |
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,18 @@ | ||
{ | ||
"java.import.gradle.enabled": false, | ||
"java.import.maven.enabled": false, | ||
"java.eclipse.downloadSources": true, | ||
"files.exclude": { | ||
"bin/": true, | ||
".eclipse/": true, | ||
".project": true, | ||
".classpath": true, | ||
"build.gradle": true | ||
}, | ||
"java.completion.importOrder": [ | ||
"", | ||
"javax", | ||
"java", | ||
"#" | ||
] | ||
} |
Oops, something went wrong.