use of io.vertx.ext.web.validation.impl.body.BodyProcessor in project vertx-web by vert-x3.
the class JsonBodyProcessorImplTest method testNull.
@Test
public void testNull(VertxTestContext testContext) {
when(mockedContext.getBody()).thenReturn(Buffer.buffer("null"));
BodyProcessor processor = Bodies.json(schema().withKeyword("type", "null")).create(parser);
processor.process(mockedContext).onComplete(testContext.succeeding(rp -> {
testContext.verify(() -> {
assertThat(rp.isNull()).isTrue();
});
testContext.completeNow();
}));
}
use of io.vertx.ext.web.validation.impl.body.BodyProcessor in project vertx-web by vert-x3.
the class JsonBodyProcessorImplTest method testInvalidJsonArray.
@Test
public void testInvalidJsonArray(VertxTestContext testContext) {
when(mockerServerRequest.getHeader(HttpHeaders.CONTENT_TYPE)).thenReturn("application/json");
when(mockedContext.request()).thenReturn(mockerServerRequest);
when(mockedContext.getBody()).thenReturn(TestSchemas.INVALID_ARRAY.toBuffer());
BodyProcessor processor = Bodies.json(TestSchemas.SAMPLE_ARRAY_SCHEMA_BUILDER).create(parser);
processor.process(mockedContext).onComplete(testContext.failing(err -> {
testContext.verify(() -> {
assertThat(err).isInstanceOf(BodyProcessorException.class).hasFieldOrPropertyWithValue("actualContentType", "application/json").hasCauseInstanceOf(ValidationException.class);
});
testContext.completeNow();
}));
}
use of io.vertx.ext.web.validation.impl.body.BodyProcessor in project vertx-web by vert-x3.
the class JsonBodyProcessorImplTest method testJsonArray.
@Test
public void testJsonArray(VertxTestContext testContext) {
when(mockedContext.getBody()).thenReturn(TestSchemas.VALID_ARRAY.toBuffer());
BodyProcessor processor = Bodies.json(TestSchemas.SAMPLE_ARRAY_SCHEMA_BUILDER).create(parser);
processor.process(mockedContext).onComplete(testContext.succeeding(rp -> {
testContext.verify(() -> {
assertThat(rp.isJsonArray()).isTrue();
assertThat(rp.getJsonArray()).isEqualTo(TestSchemas.VALID_ARRAY);
});
testContext.completeNow();
}));
}
use of io.vertx.ext.web.validation.impl.body.BodyProcessor in project vertx-web by vert-x3.
the class FormBodyProcessorImplTest method testFormBodyProcessorParsingFailure.
@Test
public void testFormBodyProcessorParsingFailure(VertxTestContext testContext) {
ObjectSchemaBuilder schemaBuilder = TestSchemas.SAMPLE_OBJECT_SCHEMA_BUILDER;
MultiMap map = MultiMap.caseInsensitiveMultiMap();
map.add("someNumbers", "1.1");
map.add("someNumbers", "2.2");
map.add("oneNumber", "3.3");
map.add("someIntegers", "1");
map.add("someIntegers", "hello");
map.add("oneInteger", "3");
map.add("aBoolean", "true");
when(mockedServerRequest.getHeader(HttpHeaders.CONTENT_TYPE)).thenReturn("application/x-www-form-urlencoded");
when(mockedServerRequest.formAttributes()).thenReturn(map);
when(mockedContext.request()).thenReturn(mockedServerRequest);
BodyProcessor processor = Bodies.formUrlEncoded(schemaBuilder).create(parser);
assertThat(processor.canProcess("application/x-www-form-urlencoded")).isTrue();
processor.process(mockedContext).onComplete(testContext.failing(err -> {
testContext.verify(() -> {
assertThat(err).isInstanceOf(BodyProcessorException.class).hasFieldOrPropertyWithValue("actualContentType", "application/x-www-form-urlencoded").hasCauseInstanceOf(MalformedValueException.class);
});
testContext.completeNow();
}));
}
use of io.vertx.ext.web.validation.impl.body.BodyProcessor in project vertx-web by vert-x3.
the class JsonBodyProcessorImplTest method testJsonObject.
@Test
public void testJsonObject(VertxTestContext testContext) {
when(mockedContext.getBody()).thenReturn(TestSchemas.VALID_OBJECT.toBuffer());
BodyProcessor processor = Bodies.json(TestSchemas.SAMPLE_OBJECT_SCHEMA_BUILDER).create(parser);
processor.process(mockedContext).onComplete(testContext.succeeding(rp -> {
testContext.verify(() -> {
assertThat(rp.isJsonObject()).isTrue();
assertThat(rp.getJsonObject()).isEqualTo(TestSchemas.VALID_OBJECT);
});
testContext.completeNow();
}));
}
Aggregations