Search in sources :

Example 6 with ParameterProcessorImpl

use of io.vertx.ext.web.validation.impl.parameter.ParameterProcessorImpl in project vertx-web by vert-x3.

the class ParameterProcessorUnitTest method testRequiredParam.

@Test
public void testRequiredParam() {
    ParameterProcessor processor = new ParameterProcessorImpl("myParam", ParameterLocation.QUERY, false, mockedParser, mockedValidator);
    when(mockedParser.parseParameter(any())).thenReturn(null);
    assertThatCode(() -> processor.process(new HashMap<>())).isInstanceOf(ParameterProcessorException.class).hasFieldOrPropertyWithValue("errorType", ParameterProcessorException.ParameterProcessorErrorType.MISSING_PARAMETER_WHEN_REQUIRED_ERROR).hasFieldOrPropertyWithValue("location", ParameterLocation.QUERY).hasFieldOrPropertyWithValue("parameterName", "myParam").hasNoCause();
}
Also used : ParameterProcessor(io.vertx.ext.web.validation.impl.parameter.ParameterProcessor) ParameterProcessorImpl(io.vertx.ext.web.validation.impl.parameter.ParameterProcessorImpl) Test(org.junit.jupiter.api.Test)

Example 7 with ParameterProcessorImpl

use of io.vertx.ext.web.validation.impl.parameter.ParameterProcessorImpl in project vertx-web by vert-x3.

the class ParameterProcessorUnitTest method testOptionalParamWithDefault.

@Test
public void testOptionalParamWithDefault(VertxTestContext testContext) {
    ParameterProcessor processor = new ParameterProcessorImpl("myParam", ParameterLocation.QUERY, true, mockedParser, mockedValidator);
    when(mockedParser.parseParameter(any())).thenReturn(null);
    when(mockedValidator.getDefault()).thenReturn(Future.succeededFuture("bla"));
    processor.process(new HashMap<>()).onComplete(testContext.succeeding(value -> {
        testContext.verify(() -> assertThat(value.getString()).isEqualTo("bla"));
        testContext.completeNow();
    }));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ValidationException(io.vertx.json.schema.ValidationException) RequestParameter(io.vertx.ext.web.validation.RequestParameter) ParameterParser(io.vertx.ext.web.validation.impl.parameter.ParameterParser) ParameterProcessorImpl(io.vertx.ext.web.validation.impl.parameter.ParameterProcessorImpl) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ParameterProcessor(io.vertx.ext.web.validation.impl.parameter.ParameterProcessor) Vertx(io.vertx.core.Vertx) SchemaParser(io.vertx.json.schema.SchemaParser) Mockito.when(org.mockito.Mockito.when) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) SchemaRouter(io.vertx.json.schema.SchemaRouter) Test(org.junit.jupiter.api.Test) ParameterProcessorException(io.vertx.ext.web.validation.ParameterProcessorException) ValueValidator(io.vertx.ext.web.validation.impl.validator.ValueValidator) 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) ParameterProcessor(io.vertx.ext.web.validation.impl.parameter.ParameterProcessor) HashMap(java.util.HashMap) ParameterProcessorImpl(io.vertx.ext.web.validation.impl.parameter.ParameterProcessorImpl) Test(org.junit.jupiter.api.Test)

Aggregations

ParameterProcessorImpl (io.vertx.ext.web.validation.impl.parameter.ParameterProcessorImpl)7 ParameterProcessor (io.vertx.ext.web.validation.impl.parameter.ParameterProcessor)6 Test (org.junit.jupiter.api.Test)6 MalformedValueException (io.vertx.ext.web.validation.MalformedValueException)5 Future (io.vertx.core.Future)4 Vertx (io.vertx.core.Vertx)4 ParameterProcessorException (io.vertx.ext.web.validation.ParameterProcessorException)4 RequestParameter (io.vertx.ext.web.validation.RequestParameter)4 ParameterParser (io.vertx.ext.web.validation.impl.parameter.ParameterParser)4 ValueValidator (io.vertx.ext.web.validation.impl.validator.ValueValidator)4 SchemaParser (io.vertx.json.schema.SchemaParser)4 SchemaRouter (io.vertx.json.schema.SchemaRouter)4 SchemaRouterOptions (io.vertx.json.schema.SchemaRouterOptions)4 ValidationException (io.vertx.json.schema.ValidationException)4 Draft7SchemaParser (io.vertx.json.schema.draft7.Draft7SchemaParser)4 VertxExtension (io.vertx.junit5.VertxExtension)4 VertxTestContext (io.vertx.junit5.VertxTestContext)4 HashMap (java.util.HashMap)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Assertions.assertThatCode (org.assertj.core.api.Assertions.assertThatCode)4