use of io.vertx.ext.web.validation.impl.parameter.ParameterProcessor in project vertx-web by vert-x3.
the class ParameterProcessorUnitTest method testParsingFailure.
@Test
public void testParsingFailure() {
ParameterProcessor processor = new ParameterProcessorImpl("myParam", ParameterLocation.QUERY, false, mockedParser, mockedValidator);
when(mockedParser.parseParameter(any())).thenThrow(new MalformedValueException("bla"));
assertThatCode(() -> processor.process(new HashMap<>())).isInstanceOf(ParameterProcessorException.class).hasFieldOrPropertyWithValue("errorType", ParameterProcessorException.ParameterProcessorErrorType.PARSING_ERROR).hasFieldOrPropertyWithValue("location", ParameterLocation.QUERY).hasFieldOrPropertyWithValue("parameterName", "myParam").hasCauseInstanceOf(MalformedValueException.class);
}
use of io.vertx.ext.web.validation.impl.parameter.ParameterProcessor in project vertx-web by vert-x3.
the class ParameterProcessorUnitTest method testValidationFailure.
@Test
public void testValidationFailure(VertxTestContext testContext) {
ParameterProcessor processor = new ParameterProcessorImpl("myParam", ParameterLocation.QUERY, true, mockedParser, mockedValidator);
when(mockedParser.parseParameter(any())).thenReturn("aaa");
when(mockedValidator.validate(any())).thenReturn(Future.failedFuture(ValidationException.createException("aaa", "aaa", "aaa")));
processor.process(new HashMap<>()).onComplete(testContext.failing(throwable -> {
testContext.verify(() -> {
assertThat(throwable).isInstanceOf(ParameterProcessorException.class).hasFieldOrPropertyWithValue("errorType", ParameterProcessorException.ParameterProcessorErrorType.VALIDATION_ERROR).hasFieldOrPropertyWithValue("location", ParameterLocation.QUERY).hasFieldOrPropertyWithValue("parameterName", "myParam").hasCauseInstanceOf(ValidationException.class);
});
testContext.completeNow();
}));
}
use of io.vertx.ext.web.validation.impl.parameter.ParameterProcessor in project vertx-web by vert-x3.
the class ParameterProcessorUnitTest method testOptionalParam.
@Test
public void testOptionalParam(VertxTestContext testContext) {
ParameterProcessor processor = new ParameterProcessorImpl("myParam", ParameterLocation.QUERY, true, mockedParser, mockedValidator);
when(mockedParser.parseParameter(any())).thenReturn(null);
when(mockedValidator.getDefault()).thenReturn(Future.succeededFuture());
processor.process(new HashMap<>()).onComplete(testContext.succeeding(value -> {
testContext.verify(() -> assertThat(value).isNull());
testContext.completeNow();
}));
}
use of io.vertx.ext.web.validation.impl.parameter.ParameterProcessor in project vertx-web by vert-x3.
the class ParameterProcessorUnitTest method testValidation.
@Test
public void testValidation(VertxTestContext testContext) {
ParameterProcessor processor = new ParameterProcessorImpl("myParam", ParameterLocation.QUERY, true, mockedParser, mockedValidator);
when(mockedParser.parseParameter(any())).thenReturn("aaa");
when(mockedValidator.validate(any())).thenReturn(Future.succeededFuture(RequestParameter.create("aaa")));
processor.process(new HashMap<>()).onComplete(testContext.succeeding(rp -> {
testContext.verify(() -> {
assertThat(rp.isString()).isTrue();
assertThat(rp.getString()).isEqualTo("aaa");
});
testContext.completeNow();
}));
}
use of io.vertx.ext.web.validation.impl.parameter.ParameterProcessor in project vertx-web by vert-x3.
the class ParameterProcessorIntegrationTest method testJsonParam.
@Test
public void testJsonParam(VertxTestContext testContext) {
ParameterProcessor processor = Parameters.jsonParam("myParam", TestSchemas.SAMPLE_OBJECT_SCHEMA_BUILDER).create(ParameterLocation.QUERY, parser);
Map<String, List<String>> map = new HashMap<>();
map.put("myParam", Collections.singletonList(TestSchemas.VALID_OBJECT.encode()));
processor.process(map).onComplete(testContext.succeeding(rp -> {
testContext.verify(() -> {
assertThat(rp.isJsonObject()).isTrue();
assertThat(rp.getJsonObject()).isEqualTo(TestSchemas.VALID_OBJECT);
});
testContext.completeNow();
}));
}
Aggregations