-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: example with meta annotation (refs #58)
- Loading branch information
1 parent
fdf5647
commit 4c710d7
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
wiremock-spring-boot-example/src/test/java/app/MetaAnnotation.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,18 @@ | ||
package app; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.wiremock.spring.ConfigureWireMock; | ||
import org.wiremock.spring.EnableWireMock; | ||
|
||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@SpringBootTest | ||
@EnableWireMock( | ||
@ConfigureWireMock( | ||
baseUrlProperties = {"customUrl", "sameCustomUrl"}, | ||
portProperties = "customPort")) | ||
public @interface MetaAnnotation {} |
37 changes: 37 additions & 0 deletions
37
wiremock-spring-boot-example/src/test/java/app/MetaAnnotationTest.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,37 @@ | ||
package app; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.get; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.github.tomakehurst.wiremock.client.WireMock; | ||
import io.restassured.RestAssured; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Value; | ||
|
||
@MetaAnnotation | ||
class MetaAnnotationTest { | ||
|
||
@Value("${customUrl}") | ||
private String customUrl; | ||
|
||
@Value("${sameCustomUrl}") | ||
private String sameCustomUrl; | ||
|
||
@Value("${customPort}") | ||
private String customPort; | ||
|
||
@BeforeEach | ||
public void before() { | ||
WireMock.stubFor(get("/the_custom_prop_mock").willReturn(aResponse().withStatus(202))); | ||
} | ||
|
||
@Test | ||
void test() { | ||
assertThat(this.customUrl).isEqualTo(this.sameCustomUrl); | ||
|
||
RestAssured.baseURI = this.customUrl; | ||
RestAssured.when().get("/the_custom_prop_mock").then().statusCode(202); | ||
} | ||
} |