diff --git a/modules/kogito-swf/common/scripts/added/build-app.sh b/modules/kogito-swf/common/scripts/added/build-app.sh index fdc5fc24c..762c791e6 100755 --- a/modules/kogito-swf/common/scripts/added/build-app.sh +++ b/modules/kogito-swf/common/scripts/added/build-app.sh @@ -20,7 +20,7 @@ fi SUPPORTED_FILES=(".yaml" ".yml" ".json" ".properties" ".mvn/jvm.config") log_info "-> Copying files from ${resources_path}, if any..." if [ ! -z "${resources_path}" ]; then - find "${resources_path}" -regex '.*\.\(yaml\|yml\|json\|properties\)$' -exec cp -v {} src/main/resources/ \; + cd "${resources_path}" && find . -regex '.*\.\(yaml\|yml\|json\|properties\)$' | sed 's|^./||' | xargs cp -v --parents -t "${swf_home_dir}"/src/main/resources/ && cd - find "${resources_path}" -name 'jvm.config' -exec echo "--> found {}" \; -exec mkdir -p .mvn \; -exec cp -v {} .mvn/ \; else log_warning "-> Nothing to copy from ${resources_path}" diff --git a/tests/shell/kogito-swf-builder/RunTests.java b/tests/shell/kogito-swf-builder/RunTests.java index f2dee5a80..8c5705028 100644 --- a/tests/shell/kogito-swf-builder/RunTests.java +++ b/tests/shell/kogito-swf-builder/RunTests.java @@ -46,9 +46,9 @@ public class RunTests { private Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(LOGGER); @Container - private GenericContainer builtImage = new GenericContainer( + private GenericContainer greetBuiltImage = new GenericContainer( new ImageFromDockerfile("dev.local/jbang-test/swf-test:" + Math.round(Math.random() * 1000000.00)) - .withDockerfile(Paths.get(getScriptDirPath(), "resources", "Dockerfile")) + .withDockerfile(Paths.get(getScriptDirPath(), "resources/greet", "Dockerfile")) .withBuildArg("BUILDER_IMAGE_TAG", getTestImage())) .withExposedPorts(8080) .waitingFor(Wait.forHttp("/jsongreet")) @@ -56,9 +56,9 @@ public class RunTests { @Test public void testBuiltContainerAnswerCorrectly() throws URISyntaxException, IOException, InterruptedException { - builtImage.start(); + greetBuiltImage.start(); HttpRequest request = HttpRequest.newBuilder() - .uri(new URI("http://" + builtImage.getHost() + ":" + builtImage.getFirstMappedPort() + "/jsongreet")) + .uri(new URI("http://" + greetBuiltImage.getHost() + ":" + greetBuiltImage.getFirstMappedPort() + "/jsongreet")) .header("Content-Type", "application/json") .header("Accept", "application/json") .timeout(Duration.ofSeconds(10)) @@ -67,6 +67,32 @@ public void testBuiltContainerAnswerCorrectly() throws URISyntaxException, IOExc .build(); HttpResponse 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 response = HttpClient.newHttpClient().send(request, BodyHandlers.ofString()); + assertEquals(201, response.statusCode()); + greetWithInputSchemaBuiltImage.stop(); } public static void main(String... args) throws Exception { diff --git a/tests/shell/kogito-swf-builder/resources/.mvn/jvm.config b/tests/shell/kogito-swf-builder/resources/greet-with-inputschema/.mvn/jvm.config similarity index 100% rename from tests/shell/kogito-swf-builder/resources/.mvn/jvm.config rename to tests/shell/kogito-swf-builder/resources/greet-with-inputschema/.mvn/jvm.config diff --git a/tests/shell/kogito-swf-builder/resources/greet-with-inputschema/Dockerfile b/tests/shell/kogito-swf-builder/resources/greet-with-inputschema/Dockerfile new file mode 100644 index 000000000..88e1fc8a7 --- /dev/null +++ b/tests/shell/kogito-swf-builder/resources/greet-with-inputschema/Dockerfile @@ -0,0 +1,40 @@ +ARG BUILDER_IMAGE_TAG="quay.io/kiegroup/kogito-swf-builder:2.0" + +FROM ${BUILDER_IMAGE_TAG} AS builder + +# Kogito user +USER 1001 + +ARG QUARKUS_PACKAGE_TYPE="jar" +ARG SCRIPT_DEBUG="true" +ARG MAVEN_DOWNLOAD_OUTPUT="true" +ARG MAVEN_OFFLINE_MODE="true" + +# Copy from build context to resources directory +COPY ./ ./resources/ + +# Build app with given resources +RUN "${KOGITO_HOME}"/launch/build-app.sh './resources' + +#============================= +# Runtime Run +#============================= +FROM registry.access.redhat.com/ubi8/openjdk-11-runtime:latest + +ARG QUARKUS_LAUNCH_DEVMODE=false + +ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' +# Default name is 'serverless-workflow-project' +ARG PROJECT_ARTIFACT_ID='serverless-workflow-project' + +# We make four distinct layers so if there are application changes the library layers can be re-used +COPY --from=builder --chown=185 /home/kogito/${PROJECT_ARTIFACT_ID}/target/quarkus-app/lib/ /deployments/lib/ +COPY --from=builder --chown=185 /home/kogito/${PROJECT_ARTIFACT_ID}/target/quarkus-app/*.jar /deployments/ +COPY --from=builder --chown=185 /home/kogito/${PROJECT_ARTIFACT_ID}/target/quarkus-app/app/ /deployments/app/ +COPY --from=builder --chown=185 /home/kogito/${PROJECT_ARTIFACT_ID}/target/quarkus-app/quarkus/ /deployments/quarkus/ + +EXPOSE 8080 +USER 185 +ENV AB_JOLOKIA_OFF="" +ENV JAVA_OPTS="-Dquarkus.http.host=0.0.0.0 -Dquarkus.http.port=8080 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" diff --git a/tests/shell/kogito-swf-builder/resources/greet-with-inputschema/greet.sw.json b/tests/shell/kogito-swf-builder/resources/greet-with-inputschema/greet.sw.json new file mode 100644 index 000000000..183e2101f --- /dev/null +++ b/tests/shell/kogito-swf-builder/resources/greet-with-inputschema/greet.sw.json @@ -0,0 +1,89 @@ +{ + "id": "greeting", + "description": "Greeting example on k8s!", + "version": "0.0.1", + "start": { + "stateName": "ChooseOnLanguage" + }, + "dataInputSchema": { + "schema": "schemas/input.json", + "failOnValidationErrors": true + }, + "specVersion": "0.8", + "expressionLang": "jq", + "states": [ + { + "name": "ChooseOnLanguage", + "type": "switch", + "defaultCondition": { + "transition": { + "nextState": "GreetInEnglish" + } + }, + "dataConditions": [ + { + "condition": "${ .language == \"English\" }", + "transition": { + "nextState": "GreetInEnglish" + } + }, + { + "condition": "${ .language == \"Spanish\" }", + "transition": { + "nextState": "GreetInSpanish" + } + } + ] + }, + { + "name": "GreetInEnglish", + "type": "inject", + "transition": { + "nextState": "GreetPerson" + }, + "data": { + "greeting": "Hello from JSON Workflow, " + } + }, + { + "name": "GreetInSpanish", + "type": "inject", + "transition": { + "nextState": "GreetPerson" + }, + "data": { + "greeting": "Saludos desde JSON Workflow, " + } + }, + { + "name": "GreetPerson", + "type": "operation", + "end": { + "terminate": true + }, + "actionMode": "sequential", + "actions": [ + { + "name": "greetAction", + "functionRef": { + "refName": "greetFunction", + "arguments": { + "message": ".greeting+.name" + }, + "invoke": "sync" + }, + "actionDataFilter": { + "useResults": true + } + } + ] + } + ], + "functions": [ + { + "name": "greetFunction", + "operation": "sysout", + "type": "custom" + } + ] +} \ No newline at end of file diff --git a/tests/shell/kogito-swf-builder/resources/greet-with-inputschema/schemas/input.json b/tests/shell/kogito-swf-builder/resources/greet-with-inputschema/schemas/input.json new file mode 100644 index 000000000..1874fd25b --- /dev/null +++ b/tests/shell/kogito-swf-builder/resources/greet-with-inputschema/schemas/input.json @@ -0,0 +1,16 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "language": { + "type": "string" + }, + "name": { + "type": "string" + } + }, + "required": [ + "language", + "name" + ] +} \ No newline at end of file diff --git a/tests/shell/kogito-swf-builder/resources/greet/.mvn/jvm.config b/tests/shell/kogito-swf-builder/resources/greet/.mvn/jvm.config new file mode 100644 index 000000000..df7809fac --- /dev/null +++ b/tests/shell/kogito-swf-builder/resources/greet/.mvn/jvm.config @@ -0,0 +1 @@ +-Xms1024m \ No newline at end of file diff --git a/tests/shell/kogito-swf-builder/resources/Dockerfile b/tests/shell/kogito-swf-builder/resources/greet/Dockerfile similarity index 100% rename from tests/shell/kogito-swf-builder/resources/Dockerfile rename to tests/shell/kogito-swf-builder/resources/greet/Dockerfile diff --git a/tests/shell/kogito-swf-builder/resources/greet.sw.json b/tests/shell/kogito-swf-builder/resources/greet/greet.sw.json similarity index 100% rename from tests/shell/kogito-swf-builder/resources/greet.sw.json rename to tests/shell/kogito-swf-builder/resources/greet/greet.sw.json