-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20035 from dimas-b/inject-wiremock
Support injecting OIDC WireMockServer into tests
- Loading branch information
Showing
4 changed files
with
88 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
24 changes: 24 additions & 0 deletions
24
test-framework/oidc-server/src/main/java/io/quarkus/test/oidc/server/OidcWireMock.java
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,24 @@ | ||
package io.quarkus.test.oidc.server; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer; | ||
|
||
/** | ||
* Used to specify that the field should be injected with the {@link WireMockServer} | ||
* server that provides mock HTTP API for OIDC clients. | ||
* <p> | ||
* Note: for this injection to work the test must use {@link OidcWiremockTestResource}. | ||
* </p> | ||
* <p> | ||
* The main purpose of injecting the {@link WireMockServer} is for tests to be able | ||
* to mock extra URLs not covered by {@link OidcWiremockTestResource}. | ||
* </p> | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.FIELD) | ||
public @interface OidcWireMock { | ||
} |
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
32 changes: 32 additions & 0 deletions
32
...rver/src/test/java/io/quarkus/test/oidc/server/OidcWiremockTestResourceInjectionTest.java
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,32 @@ | ||
package io.quarkus.test.oidc.server; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer; | ||
|
||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.common.TestResourceManager; | ||
|
||
/** | ||
* Validates the injection of {@link WireMockServer} objects into test instances by {@link OidcWiremockTestResource}. | ||
*/ | ||
class OidcWiremockTestResourceInjectionTest { | ||
|
||
@Test | ||
void testWireMockServerInjection() { | ||
TestResourceManager manager = new TestResourceManager(CustomTest.class); | ||
manager.start(); | ||
|
||
CustomTest test = new CustomTest(); | ||
manager.inject(test); | ||
assertNotNull(test.server); | ||
} | ||
|
||
@QuarkusTestResource(OidcWiremockTestResource.class) | ||
public static class CustomTest { | ||
@OidcWireMock | ||
WireMockServer server; | ||
} | ||
} |