Skip to content

Commit

Permalink
Provide sample usage of the remote plugin and citrus remote, which ca…
Browse files Browse the repository at this point in the history
…n also be used for testing.
  • Loading branch information
turing85 committed Sep 3, 2024
1 parent b9d9d65 commit 3587e0c
Show file tree
Hide file tree
Showing 10 changed files with 541 additions and 0 deletions.
366 changes: 366 additions & 0 deletions citrus-remote-sample/pom.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.citrusframework.remote.sample;

/**
* Dummy class so that the main artifact is non-empty and present.
*/
@SuppressWarnings("unused")
public class Dummy {
}
41 changes: 41 additions & 0 deletions citrus-remote-sample/src/test/container/Containerfile.temurin
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
ARG TEMURIN_IMAGE="docker.io/eclipse-temurin:21.0.4_7-jre-alpine@sha256:b16f1192681ea43bd6f5c435a1bf30e59fcbee560ee2c497f42118003f42d804"

FROM ${TEMURIN_IMAGE} as runner
ARG JAR=target/*-citrus-tests.jar
ARG APP_DIR=/deployment
ARG UID=1001

USER root

WORKDIR ${APP_DIR}
RUN chmod -R 777 ${APP_DIR}
COPY --chmod=755 ${JAR} ${APP_DIR}/app.jar

USER ${UID}:${UID}

ENTRYPOINT [ \
"java", \
"-jar", \
"app.jar" \
]

CMD [ \
"--skipTests", \
"true", \
"--duration", \
"9223372036854775807" \
]

EXPOSE 4567/tcp

HEALTHCHECK \
--interval=30s \
--retries=3 \
--timeout=5s \
CMD \
wget \
--quiet \
--spider \
--tries=1 \
localhost:4567/health \
|| exit 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.citrusframework.remote.sample.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Configuration
@Import({Http.class})
public class ConfigRoot {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.citrusframework.remote.sample.config;

import org.citrusframework.dsl.endpoint.CitrusEndpoints;
import org.citrusframework.http.client.HttpClient;
import org.citrusframework.http.server.HttpServer;
import org.springframework.context.annotation.Bean;

import java.time.Duration;

public class Http {
private static final int SERVER_PORT = 8081;

@Bean
public HttpClient httpClient() {
return CitrusEndpoints.http()
.client()
.requestUrl("http://localhost:%d".formatted(SERVER_PORT))
.build();
}

@Bean
public HttpServer httpServer() {
return CitrusEndpoints.http()
.server()
.port(SERVER_PORT)
.timeout(Duration.ofSeconds(10).toMillis())
.autoStart(true)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.citrusframework.remote.sample.entrypoint;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.io.IoBuilder;
import org.citrusframework.remote.CitrusRemoteServer;

public class CustomEntrypoint {
public static void main(String... args) {
System.setOut(IoBuilder
.forLogger(LogManager.getLogger("system.out"))
.buildPrintStream());
CitrusRemoteServer.main(args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.citrusframework.remote.sample.http;

import org.citrusframework.TestCaseRunner;
import org.citrusframework.annotations.CitrusResource;
import org.citrusframework.annotations.CitrusTest;
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.testng.annotations.Optional;
import org.testng.annotations.Test;

import static org.citrusframework.container.Async.Builder.async;
import static org.citrusframework.http.actions.HttpActionBuilder.http;

public class TextTestIT extends TestNGCitrusSpringSupport {
@Test
@CitrusTest
public void test(@Optional @CitrusResource TestCaseRunner runner) {
runner.variable("body", "citrus:randomString(10, MIXED, true)");
runner.given(async().actions(
http().server("httpServer")
.receive()
.get("/get/text")
.message()
.accept(MediaType.TEXT_PLAIN_VALUE),
http().server("httpServer")
.send()
.response(HttpStatus.OK)
.message()
.contentType(MediaType.TEXT_PLAIN_VALUE)
.body("${body}")));

runner.when(http()
.client("httpClient")
.send()
.get("/get/text")
.message()
.accept(MediaType.TEXT_PLAIN_VALUE));

runner.then(http()
.client("httpClient")
.receive()
.response(HttpStatus.OK)
.message()
.contentType(MediaType.TEXT_PLAIN_VALUE)
.body("${body}"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
citrus.spring.java.config = org.citrusframework.remote.sample.config.ConfigRoot
23 changes: 23 additions & 0 deletions citrus-remote-sample/src/test/resources/log4j2.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name = Log4j2PropertiesConfig
status = info

property.LOG_DATEFORMAT_PATTERN = yyyy-MM-dd HH:mm:ss.SSS
property.CONSOLE_LOG_PATTERN = %d{${sys:LOG_DATEFORMAT_PATTERN}} %highlight{%5p} --- [%15.15t] %-40.40c{1.} : %msg%n%throwable
property.FILE_LOG_PATTERN = %d{${sys:LOG_DATEFORMAT_PATTERN}} %5p --- [%15.15t] %-40.40c{1.} : %msg%n%throwable

appender.console.type = Console
appender.console.layout.pattern = ${sys:CONSOLE_LOG_PATTERN}
appender.console.layout.type = PatternLayout
appender.console.name = STDOUT

appender.file.layout.type = PatternLayout
appender.file.layout.pattern = ${sys:FILE_LOG_PATTERN}
appender.file.fileName = target/logs/citrus.log
appender.file.type = File
appender.file.append = false
appender.file.name = FILE

rootLogger.appenderRef.stdout.ref = STDOUT
rootLogger.appenderRef.file.ref = FILE
rootLogger.appenderRefs = stdout, file
rootLogger.level = info
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<modules>
<module>citrus-remote-server</module>
<module>citrus-remote-maven-plugin</module>
<module>citrus-remote-sample</module>
</modules>

<dependencyManagement>
Expand Down

0 comments on commit 3587e0c

Please sign in to comment.