Search in sources :

Example 11 with BodyProcessor

use of io.vertx.ext.web.validation.impl.body.BodyProcessor in project vertx-web by vert-x3.

the class JsonBodyProcessorImplTest method testContentTypeCheck.

@Test
public void testContentTypeCheck() {
    BodyProcessor processor = Bodies.json(TestSchemas.SAMPLE_OBJECT_SCHEMA_BUILDER).create(parser);
    assertThat(processor.canProcess("application/json")).isTrue();
    assertThat(processor.canProcess("application/json; charset=utf-8")).isTrue();
    assertThat(processor.canProcess("application/superapplication+json")).isTrue();
}
Also used : BodyProcessor(io.vertx.ext.web.validation.impl.body.BodyProcessor) Test(org.junit.jupiter.api.Test)

Example 12 with BodyProcessor

use of io.vertx.ext.web.validation.impl.body.BodyProcessor in project vertx-web by vert-x3.

the class TextPlainBodyProcessorTest method testString.

@Test
public void testString(VertxTestContext testContext) {
    when(mockedContext.getBodyAsString()).thenReturn(TestSchemas.VALID_STRING);
    BodyProcessor processor = Bodies.textPlain(TestSchemas.SAMPLE_STRING_SCHEMA_BUILDER).create(parser);
    processor.process(mockedContext).onComplete(testContext.succeeding(rp -> {
        testContext.verify(() -> {
            assertThat(rp.isString()).isTrue();
            assertThat(rp.getString()).isEqualTo(TestSchemas.VALID_STRING);
        });
        testContext.completeNow();
    }));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) HttpServerRequest(io.vertx.core.http.HttpServerRequest) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Mock(org.mockito.Mock) BodyProcessor(io.vertx.ext.web.validation.impl.body.BodyProcessor) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Vertx(io.vertx.core.Vertx) HttpHeaders(io.vertx.core.http.HttpHeaders) SchemaParser(io.vertx.json.schema.SchemaParser) RoutingContext(io.vertx.ext.web.RoutingContext) Mockito.when(org.mockito.Mockito.when) Bodies(io.vertx.ext.web.validation.builder.Bodies) VertxExtension(io.vertx.junit5.VertxExtension) SchemaRouter(io.vertx.json.schema.SchemaRouter) BodyProcessorException(io.vertx.ext.web.validation.BodyProcessorException) TestSchemas(io.vertx.ext.web.validation.testutils.TestSchemas) Test(org.junit.jupiter.api.Test) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) MalformedValueException(io.vertx.ext.web.validation.MalformedValueException) SchemaRouterOptions(io.vertx.json.schema.SchemaRouterOptions) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) Draft7SchemaParser(io.vertx.json.schema.draft7.Draft7SchemaParser) BodyProcessor(io.vertx.ext.web.validation.impl.body.BodyProcessor) Test(org.junit.jupiter.api.Test)

Example 13 with BodyProcessor

use of io.vertx.ext.web.validation.impl.body.BodyProcessor in project vertx-web by vert-x3.

the class TextPlainBodyProcessorTest method testNullBody.

@Test
public void testNullBody() {
    when(mockerServerRequest.getHeader(HttpHeaders.CONTENT_TYPE)).thenReturn("text/plain");
    when(mockedContext.request()).thenReturn(mockerServerRequest);
    when(mockedContext.getBodyAsString()).thenReturn(null);
    BodyProcessor processor = Bodies.textPlain(TestSchemas.SAMPLE_STRING_SCHEMA_BUILDER).create(parser);
    assertThatCode(() -> processor.process(mockedContext)).isInstanceOf(BodyProcessorException.class).hasFieldOrPropertyWithValue("actualContentType", "text/plain").hasCauseInstanceOf(MalformedValueException.class);
}
Also used : BodyProcessor(io.vertx.ext.web.validation.impl.body.BodyProcessor) Test(org.junit.jupiter.api.Test)

Aggregations

BodyProcessor (io.vertx.ext.web.validation.impl.body.BodyProcessor)13 Test (org.junit.jupiter.api.Test)12 SchemaParser (io.vertx.json.schema.SchemaParser)9 Vertx (io.vertx.core.Vertx)8 HttpHeaders (io.vertx.core.http.HttpHeaders)8 HttpServerRequest (io.vertx.core.http.HttpServerRequest)8 RoutingContext (io.vertx.ext.web.RoutingContext)8 BodyProcessorException (io.vertx.ext.web.validation.BodyProcessorException)8 MalformedValueException (io.vertx.ext.web.validation.MalformedValueException)8 Bodies (io.vertx.ext.web.validation.builder.Bodies)8 TestSchemas (io.vertx.ext.web.validation.testutils.TestSchemas)8 SchemaRouter (io.vertx.json.schema.SchemaRouter)8 SchemaRouterOptions (io.vertx.json.schema.SchemaRouterOptions)8 Draft7SchemaParser (io.vertx.json.schema.draft7.Draft7SchemaParser)8 VertxExtension (io.vertx.junit5.VertxExtension)8 VertxTestContext (io.vertx.junit5.VertxTestContext)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)8 Mock (org.mockito.Mock)8