Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: using 'wiremock' as default name on @InjectWireMock (refs #50) #51

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/main/java/org/wiremock/spring/InjectWireMock.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
import java.lang.annotation.Target;

/**
* Injects WireMock instance previously configured on the class or field level with {@link
* ConfigureWireMock}.
* Injects WireMock instance previously configured on the class or field level
* with {@link ConfigureWireMock}.
*
* @author Maciej Walkowiak
*/
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Target({ ElementType.FIELD, ElementType.PARAMETER })
@Retention(RetentionPolicy.RUNTIME)
public @interface InjectWireMock {

/**
* The name of WireMock instance to inject.
*
* @return the name of WireMock instance to inject.
*/
String value();
/**
* The name of WireMock instance to inject.
*
* @return the name of WireMock instance to inject.
*/
String value() default "wiremock";
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,30 @@
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.get;

import com.github.tomakehurst.wiremock.WireMockServer;
import io.restassured.RestAssured;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.wiremock.spring.EnableWireMock;
import org.wiremock.spring.InjectWireMock;

import com.github.tomakehurst.wiremock.WireMockServer;

import io.restassured.RestAssured;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EnableWireMock
class InjectWireMockTest {
class InjectNamedWireMockTest {

@InjectWireMock("wiremock")
private WireMockServer wireMockServer;
@InjectWireMock
private WireMockServer wireMockServer;

@Value("${wiremock.server.baseUrl}")
private String wiremockUrl;
@Value("${wiremock.server.baseUrl}")
private String wiremockUrl;

@Test
void returnsTodos() {
this.wireMockServer.stubFor(get("/ping").willReturn(aResponse().withStatus(200)));
@Test
void returnsTodos() {
this.wireMockServer.stubFor(get("/ping").willReturn(aResponse().withStatus(200)));

RestAssured.when().get(this.wiremockUrl + "/ping").then().statusCode(200);
}
RestAssured.when().get(this.wiremockUrl + "/ping").then().statusCode(200);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package app;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.get;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.wiremock.spring.ConfigureWireMock;
import org.wiremock.spring.EnableWireMock;
import org.wiremock.spring.InjectWireMock;

import com.github.tomakehurst.wiremock.WireMockServer;

import io.restassured.RestAssured;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EnableWireMock(@ConfigureWireMock(name = "mywiremock"))
class InjectDefaultWireMockTest {

@InjectWireMock("mywiremock")
private WireMockServer wireMockServer;

@Value("${wiremock.server.baseUrl}")
private String wiremockUrl;

@Test
void returnsTodos() {
this.wireMockServer.stubFor(get("/ping").willReturn(aResponse().withStatus(200)));

RestAssured.when().get(this.wiremockUrl + "/ping").then().statusCode(200);
}
}
Loading