Search in sources :

Example 71 with MockServerHttpRequest

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.

the class DefaultPartHttpMessageReaderTests method testBrowser.

private void testBrowser(DefaultPartHttpMessageReader reader, Resource resource, String boundary) throws InterruptedException {
    MockServerHttpRequest request = createRequest(resource, boundary);
    Flux<Part> result = reader.read(forClass(Part.class), request, emptyMap());
    CountDownLatch latch = new CountDownLatch(3);
    StepVerifier.create(result).consumeNextWith(part -> testBrowserFormField(part, "text1", "a")).as("text1").consumeNextWith(part -> testBrowserFormField(part, "text2", "b")).as("text2").consumeNextWith(part -> testBrowserFile(part, "file1", "a.txt", LOREM_IPSUM, latch)).as("file1").consumeNextWith(part -> testBrowserFile(part, "file2", "a.txt", LOREM_IPSUM, latch)).as("file2-1").consumeNextWith(part -> testBrowserFile(part, "file2", "b.txt", MUSPI_MEROL, latch)).as("file2-2").verifyComplete();
    latch.await();
}
Also used : MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 72 with MockServerHttpRequest

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.

the class DefaultPartHttpMessageReaderTests method tooManyParts.

@Test
public void tooManyParts() throws InterruptedException {
    MockServerHttpRequest request = createRequest(new ClassPathResource("simple.multipart", getClass()), "simple-boundary");
    DefaultPartHttpMessageReader reader = new DefaultPartHttpMessageReader();
    reader.setMaxParts(1);
    Flux<Part> result = reader.read(forClass(Part.class), request, emptyMap());
    CountDownLatch latch = new CountDownLatch(1);
    StepVerifier.create(result).consumeNextWith(part -> testPart(part, null, "This is implicitly typed plain ASCII text.\r\nIt does NOT end with a linebreak.", latch)).as("Part 1").expectError(DecodingException.class).verify();
    latch.await();
}
Also used : StepVerifier(reactor.test.StepVerifier) NettyDataBufferFactory(org.springframework.core.io.buffer.NettyDataBufferFactory) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ClassPathResource(org.springframework.core.io.ClassPathResource) DecodingException(org.springframework.core.codec.DecodingException) Retention(java.lang.annotation.Retention) DataBufferUtils.release(org.springframework.core.io.buffer.DataBufferUtils.release) DataBufferUtils(org.springframework.core.io.buffer.DataBufferUtils) Nullable(org.springframework.lang.Nullable) Collections.singletonMap(java.util.Collections.singletonMap) Arguments.arguments(org.junit.jupiter.params.provider.Arguments.arguments) Path(java.nio.file.Path) MethodSource(org.junit.jupiter.params.provider.MethodSource) Resource(org.springframework.core.io.Resource) Collections.emptyMap(java.util.Collections.emptyMap) Files(java.nio.file.Files) ResolvableType.forClass(org.springframework.core.ResolvableType.forClass) UTF_8(java.nio.charset.StandardCharsets.UTF_8) MediaType(org.springframework.http.MediaType) IOException(java.io.IOException) Target(java.lang.annotation.Target) Mono(reactor.core.publisher.Mono) ElementType(java.lang.annotation.ElementType) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator) Arguments(org.junit.jupiter.params.provider.Arguments) DataBuffer(org.springframework.core.io.buffer.DataBuffer) BaseSubscriber(reactor.core.publisher.BaseSubscriber) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) Flux(reactor.core.publisher.Flux) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) DataBufferFactory(org.springframework.core.io.buffer.DataBufferFactory) Subscription(org.reactivestreams.Subscription) Exceptions(reactor.core.Exceptions) Collections(java.util.Collections) RetentionPolicy(java.lang.annotation.RetentionPolicy) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) DecodingException(org.springframework.core.codec.DecodingException) CountDownLatch(java.util.concurrent.CountDownLatch) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 73 with MockServerHttpRequest

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.

the class DefaultPartHttpMessageReaderTests method noEndBody.

@ParameterizedDefaultPartHttpMessageReaderTest
public void noEndBody(String displayName, DefaultPartHttpMessageReader reader) {
    MockServerHttpRequest request = createRequest(new ClassPathResource("no-end-body.multipart", getClass()), "boundary");
    Flux<Part> result = reader.read(forClass(Part.class), request, emptyMap());
    StepVerifier.create(result).expectError(DecodingException.class).verify();
}
Also used : MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) DecodingException(org.springframework.core.codec.DecodingException) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 74 with MockServerHttpRequest

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.

the class DefaultPartHttpMessageReaderTests method cancelBodyThenPart.

@ParameterizedDefaultPartHttpMessageReaderTest
public void cancelBodyThenPart(String displayName, DefaultPartHttpMessageReader reader) {
    MockServerHttpRequest request = createRequest(new ClassPathResource("simple.multipart", getClass()), "simple-boundary");
    Flux<Part> result = reader.read(forClass(Part.class), request, emptyMap());
    StepVerifier.create(result, 1).consumeNextWith(part -> part.content().subscribe(new CancelSubscriber())).thenCancel().verify();
}
Also used : MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 75 with MockServerHttpRequest

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.

the class DefaultPartHttpMessageReaderTests method quotedBoundary.

@ParameterizedDefaultPartHttpMessageReaderTest
public void quotedBoundary(String displayName, DefaultPartHttpMessageReader reader) throws InterruptedException {
    MockServerHttpRequest request = createRequest(new ClassPathResource("simple.multipart", getClass()), "\"simple-boundary\"");
    Flux<Part> result = reader.read(forClass(Part.class), request, emptyMap());
    CountDownLatch latch = new CountDownLatch(2);
    StepVerifier.create(result).consumeNextWith(part -> testPart(part, null, "This is implicitly typed plain ASCII text.\r\nIt does NOT end with a linebreak.", latch)).as("Part 1").consumeNextWith(part -> testPart(part, null, "This is explicitly typed plain ASCII text.\r\nIt DOES end with a linebreak.\r\n", latch)).as("Part 2").verifyComplete();
    latch.await();
}
Also used : MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) CountDownLatch(java.util.concurrent.CountDownLatch) ClassPathResource(org.springframework.core.io.ClassPathResource)

Aggregations

MockServerHttpRequest (org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest)182 Test (org.junit.jupiter.api.Test)160 MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)101 Mono (reactor.core.publisher.Mono)52 DataBuffer (org.springframework.core.io.buffer.DataBuffer)51 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)50 Collections (java.util.Collections)48 StepVerifier (reactor.test.StepVerifier)46 HttpHeaders (org.springframework.http.HttpHeaders)39 Flux (reactor.core.publisher.Flux)37 MediaType (org.springframework.http.MediaType)34 ServerWebExchange (org.springframework.web.server.ServerWebExchange)34 MultiValueMap (org.springframework.util.MultiValueMap)33 HttpStatus (org.springframework.http.HttpStatus)31 StandardCharsets (java.nio.charset.StandardCharsets)29 MockServerHttpResponse (org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse)29 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)27 ClassPathResource (org.springframework.core.io.ClassPathResource)25 DefaultDataBuffer (org.springframework.core.io.buffer.DefaultDataBuffer)24 Optional (java.util.Optional)23