-
-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update readme on JUnit 5 WebFlux support #1373
- Loading branch information
Ronald Holshausen
committed
Jun 16, 2021
1 parent
d81b2b8
commit 510af92
Showing
2 changed files
with
81 additions
and
2 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
52 changes: 52 additions & 0 deletions
52
...r/junit5spring/src/test/java/au/com/dius/pact/provider/spring/junit5/WebfluxPactTest.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,52 @@ | ||
package au.com.dius.pact.provider.spring.junit5; | ||
|
||
import au.com.dius.pact.provider.junit5.PactVerificationContext; | ||
import au.com.dius.pact.provider.junitsupport.Provider; | ||
import au.com.dius.pact.provider.junitsupport.loader.PactFolder; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.TestTemplate; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import org.springframework.web.reactive.function.server.RequestPredicates; | ||
import org.springframework.web.reactive.function.server.RouterFunction; | ||
import org.springframework.web.reactive.function.server.RouterFunctions; | ||
import org.springframework.web.reactive.function.server.ServerRequest; | ||
import org.springframework.web.reactive.function.server.ServerResponse; | ||
import reactor.core.publisher.Mono; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@SpringBootTest | ||
@Provider("myAwesomeService") | ||
@PactFolder("pacts") | ||
public class WebfluxPactTest { | ||
|
||
public static class Handler { | ||
public Mono<ServerResponse> handleRequest(ServerRequest request) { | ||
return ServerResponse.noContent().build(); | ||
} | ||
} | ||
|
||
static class Router { | ||
public RouterFunction<ServerResponse> route(Handler handler) { | ||
return RouterFunctions | ||
.route(RequestPredicates.GET("/data").and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), | ||
handler::handleRequest) | ||
.andRoute(RequestPredicates.GET("/async-data").and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), | ||
handler::handleRequest); | ||
} | ||
} | ||
|
||
@BeforeEach | ||
void setup(PactVerificationContext context) { | ||
Handler handler = new Handler(); | ||
context.setTarget(new WebFluxTarget(new Router().route(handler))); | ||
} | ||
|
||
@TestTemplate | ||
@ExtendWith(PactVerificationSpringProvider.class) | ||
void pactVerificationTestTemplate(PactVerificationContext context) { | ||
context.verifyInteraction(); | ||
} | ||
} |