Skip to content

Commit

Permalink
chore: example with meta annotation (refs #58)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Oct 23, 2024
1 parent fdf5647 commit 4c710d7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
18 changes: 18 additions & 0 deletions wiremock-spring-boot-example/src/test/java/app/MetaAnnotation.java
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 {}
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);
}
}

0 comments on commit 4c710d7

Please sign in to comment.