Skip to content

Commit

Permalink
feat: ConnectWireMock annotation introduced (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
chberger authored Nov 17, 2023
1 parent 99f8ef9 commit 18ea4e9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 30 deletions.
7 changes: 3 additions & 4 deletions docs/modules/ROOT/pages/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,16 @@ In addition, you might want to configure `WireMock` programmatically. To do so,
</dependency>
----

After that, you are able to inject a `WireMock` reference along with your test execution lifecycle has shown below:
After that, a `WireMock` reference can be injected along with your test execution lifecycle has shown below:
[source,java]
----
@QuarkusTest
@QuarkusTestResource(WireMockServerTestResource.class)
@ConnectWireMock
class WireMockDevServiceResourceTest {
private static final String MOCK_MSG = "Hello from WireMock!";
@InjectWireMock
WireMock wiremock;
WireMock wiremock; // will be injected automatically when the class has been annotated with @ConnectWireMock
@Test
void testHelloEndpoint() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkiverse.wiremock.devservices;
package io.quarkiverse.wiremock.devservice;

import io.quarkus.test.junit.QuarkusIntegrationTest;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkiverse.wiremock.devservices;
package io.quarkiverse.wiremock.devservice;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
Expand All @@ -11,19 +11,14 @@

import com.github.tomakehurst.wiremock.client.WireMock;

import io.quarkiverse.wiremock.devservice.InjectWireMock;
import io.quarkiverse.wiremock.devservice.WireMockServerTestResource;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
@QuarkusTestResource(WireMockServerTestResource.class)
@ConnectWireMock
class WireMockDevServiceResourceTest {

private static final String MOCK_MSG = "Hello from WireMock!";

@InjectWireMock
WireMock wiremock;
WireMock wiremock; // will be injected automatically when the class has been annotated with @ConnectWireMock

@Test
void testHelloEndpoint() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkiverse.wiremock.devservice;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import io.quarkus.test.common.QuarkusTestResource;

@QuarkusTestResource(value = WireMockServerConnector.class, restrictToAnnotatedClass = true)
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
public @interface ConnectWireMock {
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import com.github.tomakehurst.wiremock.client.WireMock;

import io.quarkus.test.common.DevServicesContext;
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
import io.quarkus.test.common.QuarkusTestResourceConfigurableLifecycleManager;

public class WireMockServerTestResource
implements QuarkusTestResourceLifecycleManager, DevServicesContext.ContextAware {
public class WireMockServerConnector
implements QuarkusTestResourceConfigurableLifecycleManager<ConnectWireMock>, DevServicesContext.ContextAware {

private static final Logger LOGGER = Logger.getLogger(WireMockServerTestResource.class);
private static final Logger LOGGER = Logger.getLogger(WireMockServerConnector.class);
private static final String CONFIG_TEMPLATE = "%%dev,test.%s.%s";
WireMock wiremock;

Expand All @@ -33,8 +33,7 @@ public void stop() {

@Override
public void inject(TestInjector testInjector) {
testInjector.injectIntoFields(wiremock,
new TestInjector.AnnotatedAndMatchesType(InjectWireMock.class, WireMock.class));
testInjector.injectIntoFields(wiremock, new TestInjector.MatchesType(WireMock.class));
}

@Override
Expand Down

0 comments on commit 18ea4e9

Please sign in to comment.