@Test public void resolveArgument() throws Exception { Map<String, String> uriTemplateVars = new HashMap<>(); uriTemplateVars.put("name", "value"); this.exchange.getAttributes().put(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars); BindingContext bindingContext = new BindingContext(); Mono<Object> mono = this.resolver.resolveArgument(this.paramNamedString, bindingContext, this.exchange); Object result = mono.block(); assertEquals("value", result); }
@Test public void resolveArgumentNotRequired() throws Exception { Map<String, String> uriTemplateVars = new HashMap<>(); uriTemplateVars.put("name", "value"); this.exchange.getAttributes().put(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars); BindingContext bindingContext = new BindingContext(); Mono<Object> mono = this.resolver.resolveArgument(this.paramNotRequired, bindingContext, this.exchange); Object result = mono.block(); assertEquals("value", result); }
@Test public void resolveArgumentWrappedAsOptional() throws Exception { Map<String, String> uriTemplateVars = new HashMap<>(); uriTemplateVars.put("name", "value"); this.exchange.getAttributes().put(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars); ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer(); initializer.setConversionService(new DefaultFormattingConversionService()); BindingContext bindingContext = new BindingContext(initializer); Mono<Object> mono = this.resolver.resolveArgument(this.paramOptional, bindingContext, this.exchange); Object result = mono.block(); assertEquals(Optional.of("value"), result); }
@Test public void wrapEmptyWithOptional() throws Exception { BindingContext bindingContext = new BindingContext(); Mono<Object> mono = this.resolver.resolveArgument(this.paramOptional, bindingContext, this.exchange); StepVerifier.create(mono) .consumeNextWith(value -> { assertTrue(value instanceof Optional); assertFalse(((Optional<?>) value).isPresent()); }) .expectComplete() .verify(); }
@Test public void nullIfNotRequired() throws Exception { BindingContext bindingContext = new BindingContext(); Mono<Object> mono = this.resolver.resolveArgument(this.paramNotRequired, bindingContext, this.exchange); StepVerifier.create(mono) .expectNextCount(0) .expectComplete() .verify(); }
@Test public void handleMissingValue() throws Exception { BindingContext bindingContext = new BindingContext(); Mono<Object> mono = this.resolver.resolveArgument(this.paramNamedString, bindingContext, this.exchange); StepVerifier.create(mono) .expectNextCount(0) .expectError(ServerErrorException.class) .verify(); }