Skip to content

Commit 706f586

Browse files
authored
Merge pull request #141 from aguibert/quarkus-module
Add Quarkus module
2 parents 9b24ea1 + 66fd979 commit 706f586

36 files changed

Lines changed: 1209 additions & 65 deletions

File tree

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
language: java
22
jdk:
33
- oraclejdk11
4+
services:
5+
- docker
6+
cache:
7+
directories:
8+
- $HOME/.m2
9+
- $HOME/.gradle/caches/modules-2/files/2.1/
10+
- $HOME/.gradle/wrapper/
411
script:
512
- ./gradlew clean build

core/src/main/java/org/microshed/testing/ApplicationEnvironment.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
import java.util.ServiceLoader;
2424
import java.util.Set;
2525

26+
import org.slf4j.Logger;
27+
import org.slf4j.LoggerFactory;
28+
2629
/**
2730
* Defines an approach for configuring and starting the test enviornment. Examples of a test environment might be:
2831
* <ul>
@@ -81,10 +84,17 @@ public static ApplicationEnvironment load() {
8184
}
8285
}
8386

87+
Logger LOG = LoggerFactory.getLogger(ApplicationEnvironment.class);
88+
8489
// If nothing explicitly defined in sysprops or env, check ServiceLoader
8590
Set<ApplicationEnvironment> envs = new HashSet<>();
8691
ServiceLoader.load(ApplicationEnvironment.class).forEach(envs::add);
8792
Optional<ApplicationEnvironment> selectedEnv = envs.stream()
93+
.map(env -> {
94+
if (LOG.isDebugEnabled())
95+
LOG.debug("Found ApplicationEnvironment " + env.getClass() + " with priority=" + env.getPriority() + ", available=" + env.isAvailable());
96+
return env;
97+
})
8898
.filter(env -> env.isAvailable())
8999
.sorted((c1, c2) -> c1.getClass().getCanonicalName().compareTo(c2.getClass().getCanonicalName()))
90100
.sorted((c1, c2) -> Integer.compare(c2.getPriority(), c1.getPriority()))
@@ -139,4 +149,8 @@ public default int getPriority() {
139149
*/
140150
public String getApplicationURL();
141151

152+
public default boolean configureRestAssured() {
153+
return true;
154+
}
155+
142156
}

core/src/main/java/org/microshed/testing/ManuallyStartedConfiguration.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class ManuallyStartedConfiguration implements ApplicationEnvironment {
3030
// public static final String RUNTIME_URL_PROPERTY = "MICROSHED_TEST_RUNTIME_URL";
3131
public static final String MANUAL_ENALBED = "microshed_manual_env";
3232

33+
private static String runtimeURL;
34+
3335
@Override
3436
public boolean isAvailable() {
3537
if (!Boolean.valueOf(resolveProperty(MANUAL_ENALBED)))
@@ -45,13 +47,21 @@ public int getPriority() {
4547
return ApplicationEnvironment.DEFAULT_PRIORITY - 10;
4648
}
4749

50+
public static void setRuntimeURL(String url) {
51+
runtimeURL = url;
52+
}
53+
4854
public static String getRuntimeURL() {
55+
if (runtimeURL != null)
56+
return runtimeURL;
57+
4958
String host = resolveProperty(MICROSHED_HOSTNAME);
5059
String httpPort = resolveProperty(MICROSHED_HTTP_PORT);
5160
String httpsPort = resolveProperty(MICROSHED_HTTPS_PORT);
52-
if (host.isEmpty() && (httpPort.isEmpty() || httpsPort.isEmpty()))
61+
if (host.isEmpty() && (httpPort.isEmpty() || httpsPort.isEmpty())) {
5362
throw new IllegalStateException("The properties '" + MICROSHED_HOSTNAME + "' and '" + MICROSHED_HTTP_PORT + "' or '" +
5463
MICROSHED_HTTPS_PORT + "' must be set in order to use this ApplicationEnvironment");
64+
}
5565

5666
// Prefer HTTPS if set
5767
if (!httpsPort.isEmpty()) {

core/src/main/java/org/microshed/testing/jaxrs/RestClientBuilder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class RestClientBuilder {
5454
* @param appContextRoot The protocol, hostname, port, and application root path for the REST Client
5555
* For example, <code>http://localhost:8080/myapp/</code>. If unspecified, the app context
5656
* root will be automatically detected by {@link ApplicationEnvironment#getApplicationURL()}
57+
* @return The same builder instance
5758
*/
5859
public RestClientBuilder withAppContextRoot(String appContextRoot) {
5960
Objects.requireNonNull(appContextRoot, "Supplied 'appContextRoot' must not be null");
@@ -66,6 +67,7 @@ public RestClientBuilder withAppContextRoot(String appContextRoot) {
6667
* endpoint is deployed at <code>http://localhost:8080/myapp/hello</code> and the app context root
6768
* is <code>http://localhost:8080/myapp/</code>, then the jaxrsPath is <code>hello</code>. If
6869
* unspecified, the JAX-RS path will be automatically detected by annotation scanning.
70+
* @return The same builder instance
6971
*/
7072
public RestClientBuilder withJaxrsPath(String jaxrsPath) {
7173
Objects.requireNonNull(jaxrsPath, "Supplied 'jaxrsPath' must not be null");
@@ -75,6 +77,7 @@ public RestClientBuilder withJaxrsPath(String jaxrsPath) {
7577

7678
/**
7779
* @param jwt The JWT (Json Web Token) to apply as an Authorization header
80+
* @return The same builder instance
7881
*/
7982
public RestClientBuilder withJwt(String jwt) {
8083
Objects.requireNonNull(jwt, "Supplied 'jwt' must not be null");
@@ -86,6 +89,7 @@ public RestClientBuilder withJwt(String jwt) {
8689
* @param providers One or more providers to apply. Providers typically implement
8790
* {@link MessageBodyReader} and/or {@link MessageBodyWriter}. If unspecified,
8891
* the {@link JsonBProvider} will be applied.
92+
* @return The same builder instance
8993
*/
9094
public RestClientBuilder withProviders(Class<?>... providers) {
9195
this.providers = Arrays.asList(providers);

core/src/main/java/org/microshed/testing/jupiter/MicroShedTestExtension.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ private static String createJwtIfNeeded(Field restClientField) {
103103

104104
@SuppressWarnings({ "unchecked", "rawtypes" })
105105
private static void configureRestAssured(ApplicationEnvironment config) {
106+
if (!config.configureRestAssured())
107+
return;
108+
106109
Class<?> RestAssured = tryLoad("io.restassured.RestAssured");
107110
if (RestAssured == null)
108111
return;
@@ -139,7 +142,7 @@ private static void configureRestAssured(ApplicationEnvironment config) {
139142
LOG.debug("Regsitered JSONB ObjectMapper for REST Assured");
140143
} catch (IllegalArgumentException e) {
141144
// Prior to RestAssured 4.2.0 the ObjectMapperType.JSONB enum is not available
142-
LOG.debug("Unable to configure JSON-B object mapper for REST Assured", e);
145+
LOG.debug("Unable to configure JSON-B object mapper for REST Assured due to: " + e.getMessage());
143146
} catch (Exception e) {
144147
LOG.warn("Unable to configure JSON-B object mapper for REST Assured", e);
145148
}

core/src/main/java/org/microshed/testing/jwt/JwtBuilder.java

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public class JwtBuilder {
4646
private JwtClaims claims = null;
4747
private JsonWebSignature jws = null;
4848
static RsaJsonWebKey rsajwk = null;
49-
static JwtBuilder me = null;
5049

5150
// init the single public:private key pair that we will re-use.
5251
private static void init() {
@@ -72,38 +71,38 @@ private static String pemEncode(Key publicKey) {
7271
}
7372

7473
public static String buildJwt(String subject, String issuer, String[] claims) throws JoseException, MalformedClaimException {
75-
me = new JwtBuilder();
74+
JwtBuilder builder = new JwtBuilder();
7675
init();
77-
me.claims = new JwtClaims();
78-
me.jws = new JsonWebSignature();
76+
builder.claims = new JwtClaims();
77+
builder.jws = new JsonWebSignature();
7978

80-
me.jws.setKeyIdHeaderValue(rsajwk.getKeyId());
81-
me.jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA256);
79+
builder.jws.setKeyIdHeaderValue(rsajwk.getKeyId());
80+
builder.jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA256);
8281
// The JWT is signed using the private key, get the key we'll use every time.
83-
me.jws.setKey(rsajwk.getPrivateKey());
82+
builder.jws.setKey(rsajwk.getPrivateKey());
8483
if (subject != null) {
85-
me.claims.setClaim("sub", subject);
86-
me.claims.setClaim("upn", subject);
84+
builder.claims.setClaim("sub", subject);
85+
builder.claims.setClaim("upn", subject);
8786
}
88-
me.claims.setIssuer(issuer == null ? JwtConfig.DEFAULT_ISSUER : issuer);
89-
me.claims.setExpirationTimeMinutesInTheFuture(60);
90-
setClaims(claims);
91-
if (me.claims.getIssuedAt() == null) {
92-
me.claims.setIssuedAtToNow();
87+
builder.claims.setIssuer(issuer == null ? JwtConfig.DEFAULT_ISSUER : issuer);
88+
builder.claims.setExpirationTimeMinutesInTheFuture(60);
89+
setClaims(builder, claims);
90+
if (builder.claims.getIssuedAt() == null) {
91+
builder.claims.setIssuedAtToNow();
9392
}
94-
me.jws.setPayload(me.claims.toJson());
95-
return me.jws.getCompactSerialization();
93+
builder.jws.setPayload(builder.claims.toJson());
94+
return builder.jws.getCompactSerialization();
9695
}
9796

98-
private static void setClaims(String[] claims) throws MalformedClaimException {
97+
private static void setClaims(JwtBuilder builder, String[] claims) throws MalformedClaimException {
9998
for (String claim : claims) {
10099
if (!claim.contains("="))
101100
throw new MalformedClaimException("Claim did not contain an equals sign (=). Each claim must be of the form 'key=value'");
102101
int loc = claim.indexOf('=');
103102
String claimName = claim.substring(0, loc);
104103
Object claimValue = claim.substring(loc + 1);
105104
claimValue = handleArrays((String) claimValue);
106-
setClaim(claimName, claimValue);
105+
builder.claims.setClaim(claimName, claimValue);
107106
}
108107
}
109108

@@ -115,7 +114,4 @@ private static Object handleArrays(String claimValue) {
115114
return elements;
116115
}
117116

118-
private static void setClaim(String name, Object value) {
119-
me.claims.setClaim(name, value);
120-
}
121117
}

docs/features/01_SupportedRuntimes.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,29 @@ Example Dockerfile:
8080
FROM jboss/wildfly
8181
ADD build/libs/myservice.war /opt/jboss/wildfly/standalone/deployments/
8282
```
83+
84+
## [Quarkus](https://quarkus.io/)
85+
86+
INFO: The Quarkus module does not require the application to be tested with a container like the other
87+
runtime modules do. Instead, it is mainly used for integrating other services with Quarkus.
88+
89+
Maven Dependency:
90+
91+
```xml
92+
<dependency>
93+
<groupId>org.microshed</groupId>
94+
<artifactId>microshed-testing-quarkus</artifactId>
95+
<version>0.6.2</version>
96+
</dependency>
97+
```
98+
99+
Java test class:
100+
101+
```java
102+
import org.microshed.testing.jupiter.MicroShedTest;
103+
import io.quarkus.test.junit.QuarkusTest;
104+
105+
@MicroShedTest
106+
@QuarkusTest
107+
public class ExampleResourceTest {
108+
```

docs/features/98_Examples.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ Sometimes code is worth a thousand words. Here are some pointers to working exam
1919

2020
- [Testing an application with OpenLiberty](https://github.com/MicroShed/microshed-testing/tree/master/sample-apps/liberty-app)
2121
- [Testing an application with Payara Micro](https://github.com/MicroShed/microshed-testing/tree/master/sample-apps/payara-app)
22-
- [Testing an application with Wildfly](https://github.com/MicroShed/microshed-testing/tree/master/sample-apps/wildfly-app)
22+
- [Testing an application with Wildfly](https://github.com/MicroShed/microshed-testing/tree/master/sample-apps/wildfly-app)
23+
- [Testing an application with Quarkus](https://github.com/MicroShed/microshed-testing/tree/master/sample-apps/quarkus-app)

modules/payara-micro/src/main/resources/log4j.properties

Lines changed: 0 additions & 10 deletions
This file was deleted.

modules/payara-server/src/main/resources/log4j.properties

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)