use of io.vertx.ext.web.validation.impl.parameter.ParameterProcessorImpl 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.ParameterProcessorImpl 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.ParameterProcessorImpl 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.ParameterProcessorImpl 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.ParameterProcessorImpl in project vertx-web by vert-x3.
the class JsonParameterProcessorGenerator method generate.
@Override
public ParameterProcessor generate(JsonObject parameter, JsonObject fakeSchema, JsonPointer parameterPointer, ParameterLocation parsedLocation, String parsedStyle, GeneratorContext context) {
JsonObject originalSchema = (JsonObject) SCHEMA_POINTER.queryJsonOrDefault(parameter, new JsonObject());
SchemaHolder schemas = context.getSchemaHolder(originalSchema, context.fakeSchema(fakeSchema), parameterPointer.copy().append("content").append("application/json").append("schema"));
return new ParameterProcessorImpl(parameter.getString("name"), parsedLocation, !parameter.getBoolean("required", false), new SingleValueParameterParser(parsedLocation.lowerCaseIfNeeded(parameter.getString("name")), ValueParser.JSON_PARSER), schemas.getValidator());
}
Aggregations