Java Code Examples for org.springframework.test.web.reactive.server.WebTestClient

The following examples show how to use org.springframework.test.web.reactive.server.WebTestClient. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@BeforeEach
public void setUp() {
	this.service = new BookStoreService(repository);

	BookStoreController bookStoreController = new BookStoreController(service);
	BookController bookController = new BookController(service);

	this.client = WebTestClient.bindToController(bookStoreController, bookController)
			.build();

	this.bookStoreId = service.createBookStore()
			.flatMap(bookStore -> service.putBookInStore(bookStore.getId(),
					new Book(BOOK1_ISBN, BOOK1_TITLE, BOOK1_AUTHOR))
					.then(service.putBookInStore(bookStore.getId(),
							new Book(BOOK2_ISBN, BOOK2_TITLE, BOOK2_AUTHOR)))
					.thenReturn(bookStore.getId()))
			.block();
}
 
Example 2
private WebTestClient.BodyContentSpec getAndVerifyProduct(String productIdPath, HttpStatus expectedStatus) {
	return client.get()
		.uri("/product" + productIdPath)
		.accept(APPLICATION_JSON_UTF8)
		.exchange()
		.expectStatus().isEqualTo(expectedStatus)
		.expectHeader().contentType(APPLICATION_JSON_UTF8)
		.expectBody();
}
 
Example 3
@Before
public void setup() {
    this.rest = WebTestClient
        .bindToApplicationContext(this.context)
        .configureClient()
        .build();
}
 
Example 4
Source Project: spring-analysis-note   Source File: ExchangeMutatorTests.java    License: MIT License 5 votes vote down vote up
@Override
public void afterConfigurerAdded(WebTestClient.Builder builder,
		@Nullable WebHttpHandlerBuilder httpHandlerBuilder,
		@Nullable ClientHttpConnector connector) {

	Assert.notNull(httpHandlerBuilder, "Not a mock server");
	httpHandlerBuilder.filters(filters -> {
		filters.removeIf(filter -> filter instanceof IdentityFilter);
		filters.add(0, this.filter);
	});
}
 
Example 5
Source Project: spring-analysis-note   Source File: ApplicationContextTests.java    License: MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {

	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
	context.register(WebConfig.class);
	context.refresh();

	this.client = WebTestClient.bindToApplicationContext(context).build();
}
 
Example 6
@Before
public void setup() {
    this.client = WebTestClient
        .bindToApplicationContext(this.context)
        .configureClient()
        .baseUrl("https://api.example.com")
        .filter(documentationConfiguration(restDocumentation))
        .build();
}
 
Example 7
private WebTestClient.BodyContentSpec getAndVerifyReviewsByProductId(String productIdQuery, HttpStatus expectedStatus) {
	return client.get()
		.uri("/review" + productIdQuery)
		.accept(APPLICATION_JSON_UTF8)
		.exchange()
		.expectStatus().isEqualTo(expectedStatus)
		.expectHeader().contentType(APPLICATION_JSON_UTF8)
		.expectBody();
}
 
Example 8
@BeforeAll
public void setup() {
    this.client = WebTestClient
            .bindToApplicationContext(this.context)
            .configureClient()
            .build();
}
 
Example 9
@BeforeEach
public void setup() {
    this.rest = WebTestClient
        .bindToServer()
        .responseTimeout(Duration.ofDays(1))
        .baseUrl("http://localhost:8080")
        .build();
}
 
Example 10
Source Project: tutorials   Source File: WebTestClientIntegrationTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testWebTestClientWithServerURL() {
    WebTestClient.bindToServer()
        .baseUrl("http://localhost:" + port)
        .build()
        .get()
        .uri("/resource")
        .exchange()
        .expectStatus()
        .isOk()
        .expectBody();
}
 
Example 11
private WebTestClient.BodyContentSpec getAndVerifyRecommendationsByProductId(String productIdQuery, HttpStatus expectedStatus) {
	return client.get()
		.uri("/recommendation" + productIdQuery)
		.accept(APPLICATION_JSON_UTF8)
		.exchange()
		.expectStatus().isEqualTo(expectedStatus)
		.expectHeader().contentType(APPLICATION_JSON_UTF8)
		.expectBody();
}
 
Example 12
@Test
public void testUpdateStoryOnBoard() throws Exception {

    WebTestClient.bindToController( this.controller )
            .build()
            .put()
            .uri(  "/boards/{boardUuid}/stories/{storyUuid}?name={name}", boardUuid, storyUuid, "Updated Story Name" )
            .exchange()
            .expectStatus().isAccepted();

}
 
Example 13
@Before
public void setup() {
    this.rest = WebTestClient
        .bindToApplicationContext(this.context)
        .configureClient()
        .build();
}
 
Example 14
@Test
public void shouldRedirectWithConfiguredParams() throws Exception {
	WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/swagger-ui.html").exchange()
			.expectStatus().isTemporaryRedirect();

	responseSpec.expectHeader()
			.value("Location", Matchers.is("/webjars/swagger-ui/index.html?configUrl=/baf/batz/swagger-config"));

	webTestClient.get().uri("/baf/batz/swagger-config").exchange()
			.expectStatus().isOk().expectBody().jsonPath("$.validatorUrl").isEqualTo("/foo/validate");
}
 
Example 15
private WebTestClient.BodyContentSpec getAndVerifyProduct(String productIdPath, HttpStatus expectedStatus) {
	return client.get()
		.uri("/product" + productIdPath)
		.accept(APPLICATION_JSON_UTF8)
		.exchange()
		.expectStatus().isEqualTo(expectedStatus)
		.expectHeader().contentType(APPLICATION_JSON_UTF8)
		.expectBody();
}
 
Example 16
private WebTestClient.BodyContentSpec getAndVerifyReviewsByProductId(String productIdQuery, HttpStatus expectedStatus) {
	return client.get()
		.uri("/review" + productIdQuery)
		.accept(APPLICATION_JSON_UTF8)
		.exchange()
		.expectStatus().isEqualTo(expectedStatus)
		.expectHeader().contentType(APPLICATION_JSON_UTF8)
		.expectBody();
}
 
Example 17
private WebTestClient.BodyContentSpec getAndVerifyProduct(String productIdPath, HttpStatus expectedStatus) {
	return client.get()
		.uri("/product" + productIdPath)
		.accept(APPLICATION_JSON_UTF8)
		.exchange()
		.expectStatus().isEqualTo(expectedStatus)
		.expectHeader().contentType(APPLICATION_JSON_UTF8)
		.expectBody();
}
 
Example 18
@Test
public void shouldRedirectWithConfigUrlIgnoringQueryParams() throws Exception {

	WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/swagger-ui.html").exchange()
			.expectStatus().isTemporaryRedirect();
	responseSpec.expectHeader()
			.value("Location", Matchers.is("/webjars/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config&layout=BaseLayout"));

}
 
Example 19
@Before
public void setup() {
    this.rest = WebTestClient
        .bindToApplicationContext(this.context)
        .configureClient()
        .build();
}
 
Example 20
@Before
public void setup() {
    this.rest = WebTestClient
        .bindToApplicationContext(this.context)
        .apply(springSecurity())
        .configureClient()
        .filter(basicAuthentication())
        .build();
}
 
Example 21
Source Project: java-technology-stack   Source File: ApplicationContextTests.java    License: MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {

	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
	context.register(WebConfig.class);
	context.refresh();

	this.client = WebTestClient.bindToApplicationContext(context).build();
}
 
Example 22
Source Project: java-technology-stack   Source File: HttpServerTests.java    License: MIT License 5 votes vote down vote up
@Before
public void start() throws Exception {
	HttpHandler httpHandler = RouterFunctions.toHttpHandler(
			route(GET("/test"), request -> ServerResponse.ok().syncBody("It works!")));

	this.server = new ReactorHttpServer();
	this.server.setHandler(httpHandler);
	this.server.afterPropertiesSet();
	this.server.start();

	this.client = WebTestClient.bindToServer()
			.baseUrl("http://localhost:" + this.server.getPort())
			.build();
}
 
Example 23
Source Project: java-technology-stack   Source File: RouterFunctionTests.java    License: MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {

	RouterFunction<?> route = route(GET("/test"), request ->
			ServerResponse.ok().syncBody("It works!"));

	this.testClient = WebTestClient.bindToRouterFunction(route).build();
}
 
Example 24
@BeforeClass
public static void setUpClass() {
    when(jobOperations.getJobsAndTasks()).thenReturn(Collections.emptyList());

    baseURI = jaxRsServer.getBaseURI() + ApplicationSlaManagementEndpoint.PATH_API_V2_MANAGEMENT_APPLICATIONS + '/';
    testClient = WebTestClient.bindToServer()
            .baseUrl(baseURI)
            .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
            .build();
}
 
Example 25
@Test
public void shouldRegisterBean() {
    given(mockFactory.getBeanNamesForType(WebTestClient.class, false, false))
        .willReturn(new String[]{});

    registrar.postProcessBeanDefinitionRegistry(mockRegistry);

    ArgumentCaptor<RootBeanDefinition> definitionCaptor = ArgumentCaptor.forClass(RootBeanDefinition.class);
    verify(mockRegistry).registerBeanDefinition(eq(WebTestClient.class.getName()), definitionCaptor.capture());

    RootBeanDefinition definition = definitionCaptor.getValue();
    assertThat(definition.getBeanClass()).isEqualTo(WebTestClient.class);
    assertThat(definition.getInstanceSupplier()).isInstanceOf(VertxWebTestClientSupplier.class);
    assertThat(definition.isLazyInit()).isTrue();
}
 
Example 26
@BeforeAll
public void setup() {
    this.client = WebTestClient
        .bindToController(this.ctrl)
        .configureClient()
        .build();
}
 
Example 27
private WebTestClient.BodyContentSpec getAndVerifyReviewsByProductId(String productIdQuery, HttpStatus expectedStatus) {
	return client.get()
		.uri("/review" + productIdQuery)
		.accept(APPLICATION_JSON_UTF8)
		.exchange()
		.expectStatus().isEqualTo(expectedStatus)
		.expectHeader().contentType(APPLICATION_JSON_UTF8)
		.expectBody();
}
 
Example 28
@BeforeEach
public void setUp() {
	instance = new SpringApplicationBuilder().sources(AdminReactiveApplicationTest.TestAdminApplication.class)
			.web(WebApplicationType.REACTIVE).run("--server.port=0", "--eureka.client.enabled=false");

	localPort = instance.getEnvironment().getProperty("local.server.port", Integer.class, 0);

	this.client = WebTestClient.bindToServer().baseUrl("http://localhost:" + localPort).build();
	this.register_as_test = "{ \"name\": \"test\", \"healthUrl\": \"http://localhost:" + localPort
			+ "/application/health\" }";
	this.register_as_twice = "{ \"name\": \"twice\", \"healthUrl\": \"http://localhost:" + localPort
			+ "/application/health\" }";
}
 
Example 29
@Test
public void testRenameBoard() throws Exception {

    WebTestClient.bindToController( this.controller )
            .build()
            .patch()
            .uri(  "/boards/{boardUuid}?name={name}", boardUuid, "New Name" )
            .exchange()
            .expectStatus().isAccepted();

}
 
Example 30
@BeforeAll
public void setup() {
    this.disposableServer = this.httpServer.bindNow();
    this.client = WebTestClient
            .bindToServer()
            .responseTimeout(Duration.ofDays(1))
            .baseUrl("http://localhost:" + this.port)
            .build();
}