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();
}
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();
}));
}
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);
}
Aggregations