Consistent naming of HandlerMethodArgumentResolver implementations
Includes combined imports of assertion methods and related polishing. Closes #22889
This commit is contained in:
parent
30bbf91dba
commit
28039057fd
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -101,7 +101,7 @@ public abstract class HandlerMethodArgumentResolverSupport implements HandlerMet
|
|||
|
||||
private IllegalStateException buildReactiveWrapperException(MethodParameter parameter) {
|
||||
return new IllegalStateException(getClass().getSimpleName() +
|
||||
" doesn't support reactive type wrapper: " + parameter.getGenericParameterType());
|
||||
" does not support reactive type wrapper: " + parameter.getGenericParameterType());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -178,7 +178,7 @@ class ControllerMethodResolver {
|
|||
result.add(new MatrixVariableMethodArgumentResolver(beanFactory, adapterRegistry));
|
||||
result.add(new MatrixVariableMapMethodArgumentResolver(adapterRegistry));
|
||||
if (!readers.isEmpty()) {
|
||||
result.add(new RequestBodyArgumentResolver(readers, adapterRegistry));
|
||||
result.add(new RequestBodyMethodArgumentResolver(readers, adapterRegistry));
|
||||
result.add(new RequestPartMethodArgumentResolver(readers, adapterRegistry));
|
||||
}
|
||||
if (supportDataBinding) {
|
||||
|
@ -196,18 +196,18 @@ class ControllerMethodResolver {
|
|||
result.add(new ContinuationHandlerMethodArgumentResolver());
|
||||
}
|
||||
if (!readers.isEmpty()) {
|
||||
result.add(new HttpEntityArgumentResolver(readers, adapterRegistry));
|
||||
result.add(new HttpEntityMethodArgumentResolver(readers, adapterRegistry));
|
||||
}
|
||||
result.add(new ModelArgumentResolver(adapterRegistry));
|
||||
result.add(new ModelMethodArgumentResolver(adapterRegistry));
|
||||
if (supportDataBinding) {
|
||||
result.add(new ErrorsMethodArgumentResolver(adapterRegistry));
|
||||
}
|
||||
result.add(new ServerWebExchangeArgumentResolver(adapterRegistry));
|
||||
result.add(new PrincipalArgumentResolver(adapterRegistry));
|
||||
result.add(new ServerWebExchangeMethodArgumentResolver(adapterRegistry));
|
||||
result.add(new PrincipalMethodArgumentResolver(adapterRegistry));
|
||||
if (requestMappingMethod) {
|
||||
result.add(new SessionStatusMethodArgumentResolver());
|
||||
}
|
||||
result.add(new WebSessionArgumentResolver(adapterRegistry));
|
||||
result.add(new WebSessionMethodArgumentResolver(adapterRegistry));
|
||||
|
||||
// Custom...
|
||||
result.addAll(customResolvers.getCustomResolvers());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -36,11 +36,11 @@ import org.springframework.web.server.ServerWebExchange;
|
|||
* {@code HttpMessageReader}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
* @since 5.2
|
||||
*/
|
||||
public class HttpEntityArgumentResolver extends AbstractMessageReaderArgumentResolver {
|
||||
public class HttpEntityMethodArgumentResolver extends AbstractMessageReaderArgumentResolver {
|
||||
|
||||
public HttpEntityArgumentResolver(List<HttpMessageReader<?>> readers, ReactiveAdapterRegistry registry) {
|
||||
public HttpEntityMethodArgumentResolver(List<HttpMessageReader<?>> readers, ReactiveAdapterRegistry registry) {
|
||||
super(readers, registry);
|
||||
}
|
||||
|
|
@ -36,12 +36,12 @@ import org.springframework.web.server.ServerWebExchange;
|
|||
* parameter of type {@code Map} is also annotated.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
* @since 5.2
|
||||
*/
|
||||
public class ModelArgumentResolver extends HandlerMethodArgumentResolverSupport
|
||||
public class ModelMethodArgumentResolver extends HandlerMethodArgumentResolverSupport
|
||||
implements SyncHandlerMethodArgumentResolver {
|
||||
|
||||
public ModelArgumentResolver(ReactiveAdapterRegistry adapterRegistry) {
|
||||
public ModelMethodArgumentResolver(ReactiveAdapterRegistry adapterRegistry) {
|
||||
super(adapterRegistry);
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -31,12 +31,12 @@ import org.springframework.web.server.ServerWebExchange;
|
|||
* Resolves method argument value of type {@link java.security.Principal}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
* @see ServerWebExchangeArgumentResolver
|
||||
* @since 5.2
|
||||
* @see ServerWebExchangeMethodArgumentResolver
|
||||
*/
|
||||
public class PrincipalArgumentResolver extends HandlerMethodArgumentResolverSupport {
|
||||
public class PrincipalMethodArgumentResolver extends HandlerMethodArgumentResolverSupport {
|
||||
|
||||
public PrincipalArgumentResolver(ReactiveAdapterRegistry adapterRegistry) {
|
||||
public PrincipalMethodArgumentResolver(ReactiveAdapterRegistry adapterRegistry) {
|
||||
super(adapterRegistry);
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -41,11 +41,11 @@ import org.springframework.web.server.ServerWebInputException;
|
|||
* @author Sebastien Deleuze
|
||||
* @author Stephane Maldini
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
* @since 5.2
|
||||
*/
|
||||
public class RequestBodyArgumentResolver extends AbstractMessageReaderArgumentResolver {
|
||||
public class RequestBodyMethodArgumentResolver extends AbstractMessageReaderArgumentResolver {
|
||||
|
||||
public RequestBodyArgumentResolver(List<HttpMessageReader<?>> readers,
|
||||
public RequestBodyMethodArgumentResolver(List<HttpMessageReader<?>> readers,
|
||||
ReactiveAdapterRegistry registry) {
|
||||
|
||||
super(readers, registry);
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -50,18 +50,18 @@ import org.springframework.web.util.UriComponentsBuilder;
|
|||
* relative to the current request
|
||||
* </ul>
|
||||
*
|
||||
* <p>For the {@code WebSession} see {@link WebSessionArgumentResolver}
|
||||
* and for the {@code Principal} see {@link PrincipalArgumentResolver}.
|
||||
* <p>For the {@code WebSession} see {@link WebSessionMethodArgumentResolver}
|
||||
* and for the {@code Principal} see {@link PrincipalMethodArgumentResolver}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
* @see WebSessionArgumentResolver
|
||||
* @see PrincipalArgumentResolver
|
||||
* @since 5.2
|
||||
* @see WebSessionMethodArgumentResolver
|
||||
* @see PrincipalMethodArgumentResolver
|
||||
*/
|
||||
public class ServerWebExchangeArgumentResolver extends HandlerMethodArgumentResolverSupport
|
||||
public class ServerWebExchangeMethodArgumentResolver extends HandlerMethodArgumentResolverSupport
|
||||
implements SyncHandlerMethodArgumentResolver {
|
||||
|
||||
public ServerWebExchangeArgumentResolver(ReactiveAdapterRegistry adapterRegistry) {
|
||||
public ServerWebExchangeMethodArgumentResolver(ReactiveAdapterRegistry adapterRegistry) {
|
||||
super(adapterRegistry);
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -30,16 +30,16 @@ import org.springframework.web.server.WebSession;
|
|||
* Resolves method argument value of type {@link WebSession}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
* @see ServerWebExchangeArgumentResolver
|
||||
* @since 5.2
|
||||
* @see ServerWebExchangeMethodArgumentResolver
|
||||
*/
|
||||
public class WebSessionArgumentResolver extends HandlerMethodArgumentResolverSupport {
|
||||
public class WebSessionMethodArgumentResolver extends HandlerMethodArgumentResolverSupport {
|
||||
|
||||
// We need this resolver separate from ServerWebExchangeArgumentResolver which
|
||||
// implements SyncHandlerMethodArgumentResolver.
|
||||
|
||||
|
||||
public WebSessionArgumentResolver(ReactiveAdapterRegistry adapterRegistry) {
|
||||
public WebSessionMethodArgumentResolver(ReactiveAdapterRegistry adapterRegistry) {
|
||||
super(adapterRegistry);
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -17,8 +17,6 @@ package org.springframework.web.reactive.result.method.annotation;
|
|||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
@ -34,14 +32,13 @@ import org.springframework.web.client.RestTemplate;
|
|||
import org.springframework.web.reactive.config.EnableWebFlux;
|
||||
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Integration tests related to the use of context paths.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
@SuppressWarnings({"unused", "WeakerAccess"})
|
||||
public class ContextPathIntegrationTests {
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-201 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -44,11 +44,12 @@ import org.springframework.web.method.HandlerMethod;
|
|||
import org.springframework.web.reactive.BindingContext;
|
||||
import org.springframework.web.reactive.HandlerResult;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* {@code @ControllerAdvice} related tests for {@link RequestMappingHandlerAdapter}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class ControllerAdviceTests {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -95,7 +95,7 @@ public class ControllerMethodResolverTests {
|
|||
assertEquals(PathVariableMapMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(MatrixVariableMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(MatrixVariableMapMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(RequestBodyArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(RequestBodyMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(RequestPartMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(ModelAttributeMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(RequestHeaderMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
|
@ -106,13 +106,13 @@ public class ControllerMethodResolverTests {
|
|||
assertEquals(RequestAttributeMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
|
||||
assertEquals(ContinuationHandlerMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(HttpEntityArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(ModelArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(HttpEntityMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(ModelMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(ErrorsMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(ServerWebExchangeArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(PrincipalArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(ServerWebExchangeMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(PrincipalMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(SessionStatusMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(WebSessionArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(WebSessionMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
|
||||
assertEquals(CustomArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(CustomSyncArgumentResolver.class, next(resolvers, index).getClass());
|
||||
|
@ -145,11 +145,11 @@ public class ControllerMethodResolverTests {
|
|||
assertEquals(RequestAttributeMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
|
||||
assertEquals(ContinuationHandlerMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(ModelArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(ModelMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(ErrorsMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(ServerWebExchangeArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(PrincipalArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(WebSessionArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(ServerWebExchangeMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(PrincipalMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(WebSessionMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
|
||||
assertEquals(CustomArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(CustomSyncArgumentResolver.class, next(resolvers, index).getClass());
|
||||
|
@ -180,8 +180,8 @@ public class ControllerMethodResolverTests {
|
|||
assertEquals(ExpressionValueMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(RequestAttributeMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
|
||||
assertEquals(ModelArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(ServerWebExchangeArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(ModelMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(ServerWebExchangeMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
|
||||
assertEquals(CustomSyncArgumentResolver.class, next(resolvers, index).getClass());
|
||||
|
||||
|
@ -212,10 +212,10 @@ public class ControllerMethodResolverTests {
|
|||
assertEquals(RequestAttributeMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
|
||||
assertEquals(ContinuationHandlerMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(ModelArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(ServerWebExchangeArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(PrincipalArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(WebSessionArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(ModelMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(ServerWebExchangeMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(PrincipalMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(WebSessionMethodArgumentResolver.class, next(resolvers, index).getClass());
|
||||
|
||||
assertEquals(CustomArgumentResolver.class, next(resolvers, index).getClass());
|
||||
assertEquals(CustomSyncArgumentResolver.class, next(resolvers, index).getClass());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -35,10 +35,7 @@ import org.springframework.web.bind.annotation.CookieValue;
|
|||
import org.springframework.web.reactive.BindingContext;
|
||||
import org.springframework.web.server.ServerWebInputException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Test fixture with {@link CookieValueMethodArgumentResolver}.
|
||||
|
@ -91,7 +88,7 @@ public class CookieValueMethodArgumentResolverTests {
|
|||
catch (IllegalStateException ex) {
|
||||
assertTrue("Unexpected error message:\n" + ex.getMessage(),
|
||||
ex.getMessage().startsWith(
|
||||
"CookieValueMethodArgumentResolver doesn't support reactive type wrapper"));
|
||||
"CookieValueMethodArgumentResolver does not support reactive type wrapper"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -31,10 +31,7 @@ import org.springframework.mock.web.test.server.MockServerWebExchange;
|
|||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.reactive.BindingContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ExpressionValueMethodArgumentResolver}.
|
||||
|
@ -68,12 +65,12 @@ public class ExpressionValueMethodArgumentResolverTests {
|
|||
|
||||
|
||||
@Test
|
||||
public void supportsParameter() throws Exception {
|
||||
public void supportsParameter() {
|
||||
assertTrue(this.resolver.supportsParameter(this.paramSystemProperty));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotSupport() throws Exception {
|
||||
public void doesNotSupport() {
|
||||
assertFalse(this.resolver.supportsParameter(this.paramNotSupported));
|
||||
try {
|
||||
this.resolver.supportsParameter(this.paramAlsoNotSupported);
|
||||
|
@ -82,12 +79,12 @@ public class ExpressionValueMethodArgumentResolverTests {
|
|||
catch (IllegalStateException ex) {
|
||||
assertTrue("Unexpected error message:\n" + ex.getMessage(),
|
||||
ex.getMessage().startsWith(
|
||||
"ExpressionValueMethodArgumentResolver doesn't support reactive type wrapper"));
|
||||
"ExpressionValueMethodArgumentResolver does not support reactive type wrapper"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveSystemProperty() throws Exception {
|
||||
public void resolveSystemProperty() {
|
||||
System.setProperty("systemProperty", "22");
|
||||
try {
|
||||
Mono<Object> mono = this.resolver.resolveArgument(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -36,11 +36,8 @@ import org.springframework.web.client.RestTemplate;
|
|||
import org.springframework.web.reactive.config.CorsRegistry;
|
||||
import org.springframework.web.reactive.config.WebFluxConfigurationSupport;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -48,29 +48,29 @@ import org.springframework.web.server.ServerWebExchange;
|
|||
import org.springframework.web.server.ServerWebInputException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.core.ResolvableType.forClassWithGenerics;
|
||||
import static org.springframework.http.MediaType.TEXT_PLAIN;
|
||||
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.post;
|
||||
import static org.springframework.core.ResolvableType.*;
|
||||
import static org.springframework.http.MediaType.*;
|
||||
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link HttpEntityArgumentResolver}.When adding a test also
|
||||
* Unit tests for {@link HttpEntityMethodArgumentResolver}.When adding a test also
|
||||
* consider whether the logic under test is in a parent class, then see:
|
||||
* {@link MessageReaderArgumentResolverTests}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
public class HttpEntityArgumentResolverTests {
|
||||
public class HttpEntityMethodArgumentResolverTests {
|
||||
|
||||
private final HttpEntityArgumentResolver resolver = createResolver();
|
||||
private final HttpEntityMethodArgumentResolver resolver = createResolver();
|
||||
|
||||
private final ResolvableMethod testMethod = ResolvableMethod.on(getClass()).named("handle").build();
|
||||
|
||||
|
||||
private HttpEntityArgumentResolver createResolver() {
|
||||
private HttpEntityMethodArgumentResolver createResolver() {
|
||||
List<HttpMessageReader<?>> readers = new ArrayList<>();
|
||||
readers.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
|
||||
return new HttpEntityArgumentResolver(readers, ReactiveAdapterRegistry.getSharedInstance());
|
||||
return new HttpEntityMethodArgumentResolver(readers, ReactiveAdapterRegistry.getSharedInstance());
|
||||
}
|
||||
|
||||
|
||||
|
@ -94,7 +94,7 @@ public class HttpEntityArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void doesNotSupport() throws Exception {
|
||||
public void doesNotSupport() {
|
||||
assertFalse(this.resolver.supportsParameter(this.testMethod.arg(Mono.class, String.class)));
|
||||
assertFalse(this.resolver.supportsParameter(this.testMethod.arg(String.class)));
|
||||
try {
|
||||
|
@ -104,12 +104,12 @@ public class HttpEntityArgumentResolverTests {
|
|||
catch (IllegalStateException ex) {
|
||||
assertTrue("Unexpected error message:\n" + ex.getMessage(),
|
||||
ex.getMessage().startsWith(
|
||||
"HttpEntityArgumentResolver doesn't support reactive type wrapper"));
|
||||
"HttpEntityMethodArgumentResolver does not support reactive type wrapper"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyBodyWithString() throws Exception {
|
||||
public void emptyBodyWithString() {
|
||||
ResolvableType type = httpEntityType(String.class);
|
||||
HttpEntity<Object> entity = resolveValueWithEmptyBody(type);
|
||||
|
||||
|
@ -117,7 +117,7 @@ public class HttpEntityArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void emptyBodyWithMono() throws Exception {
|
||||
public void emptyBodyWithMono() {
|
||||
ResolvableType type = httpEntityType(Mono.class, String.class);
|
||||
HttpEntity<Mono<String>> entity = resolveValueWithEmptyBody(type);
|
||||
|
||||
|
@ -125,7 +125,7 @@ public class HttpEntityArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void emptyBodyWithFlux() throws Exception {
|
||||
public void emptyBodyWithFlux() {
|
||||
ResolvableType type = httpEntityType(Flux.class, String.class);
|
||||
HttpEntity<Flux<String>> entity = resolveValueWithEmptyBody(type);
|
||||
|
||||
|
@ -133,7 +133,7 @@ public class HttpEntityArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void emptyBodyWithSingle() throws Exception {
|
||||
public void emptyBodyWithSingle() {
|
||||
ResolvableType type = httpEntityType(Single.class, String.class);
|
||||
HttpEntity<Single<String>> entity = resolveValueWithEmptyBody(type);
|
||||
|
||||
|
@ -144,7 +144,7 @@ public class HttpEntityArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void emptyBodyWithRxJava2Single() throws Exception {
|
||||
public void emptyBodyWithRxJava2Single() {
|
||||
ResolvableType type = httpEntityType(io.reactivex.Single.class, String.class);
|
||||
HttpEntity<io.reactivex.Single<String>> entity = resolveValueWithEmptyBody(type);
|
||||
|
||||
|
@ -155,7 +155,7 @@ public class HttpEntityArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void emptyBodyWithRxJava2Maybe() throws Exception {
|
||||
public void emptyBodyWithRxJava2Maybe() {
|
||||
ResolvableType type = httpEntityType(Maybe.class, String.class);
|
||||
HttpEntity<Maybe<String>> entity = resolveValueWithEmptyBody(type);
|
||||
|
||||
|
@ -166,7 +166,7 @@ public class HttpEntityArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void emptyBodyWithObservable() throws Exception {
|
||||
public void emptyBodyWithObservable() {
|
||||
ResolvableType type = httpEntityType(Observable.class, String.class);
|
||||
HttpEntity<Observable<String>> entity = resolveValueWithEmptyBody(type);
|
||||
|
||||
|
@ -177,7 +177,7 @@ public class HttpEntityArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void emptyBodyWithRxJava2Observable() throws Exception {
|
||||
public void emptyBodyWithRxJava2Observable() {
|
||||
ResolvableType type = httpEntityType(io.reactivex.Observable.class, String.class);
|
||||
HttpEntity<io.reactivex.Observable<String>> entity = resolveValueWithEmptyBody(type);
|
||||
|
||||
|
@ -188,7 +188,7 @@ public class HttpEntityArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void emptyBodyWithFlowable() throws Exception {
|
||||
public void emptyBodyWithFlowable() {
|
||||
ResolvableType type = httpEntityType(Flowable.class, String.class);
|
||||
HttpEntity<Flowable<String>> entity = resolveValueWithEmptyBody(type);
|
||||
|
||||
|
@ -199,7 +199,7 @@ public class HttpEntityArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void emptyBodyWithCompletableFuture() throws Exception {
|
||||
public void emptyBodyWithCompletableFuture() {
|
||||
ResolvableType type = httpEntityType(CompletableFuture.class, String.class);
|
||||
HttpEntity<CompletableFuture<String>> entity = resolveValueWithEmptyBody(type);
|
||||
|
||||
|
@ -210,7 +210,7 @@ public class HttpEntityArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void httpEntityWithStringBody() throws Exception {
|
||||
public void httpEntityWithStringBody() {
|
||||
ServerWebExchange exchange = postExchange("line1");
|
||||
ResolvableType type = httpEntityType(String.class);
|
||||
HttpEntity<String> httpEntity = resolveValue(exchange, type);
|
||||
|
@ -220,7 +220,7 @@ public class HttpEntityArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void httpEntityWithMonoBody() throws Exception {
|
||||
public void httpEntityWithMonoBody() {
|
||||
ServerWebExchange exchange = postExchange("line1");
|
||||
ResolvableType type = httpEntityType(Mono.class, String.class);
|
||||
HttpEntity<Mono<String>> httpEntity = resolveValue(exchange, type);
|
||||
|
@ -230,7 +230,7 @@ public class HttpEntityArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void httpEntityWithSingleBody() throws Exception {
|
||||
public void httpEntityWithSingleBody() {
|
||||
ServerWebExchange exchange = postExchange("line1");
|
||||
ResolvableType type = httpEntityType(Single.class, String.class);
|
||||
HttpEntity<Single<String>> httpEntity = resolveValue(exchange, type);
|
||||
|
@ -240,7 +240,7 @@ public class HttpEntityArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void httpEntityWithRxJava2SingleBody() throws Exception {
|
||||
public void httpEntityWithRxJava2SingleBody() {
|
||||
ServerWebExchange exchange = postExchange("line1");
|
||||
ResolvableType type = httpEntityType(io.reactivex.Single.class, String.class);
|
||||
HttpEntity<io.reactivex.Single<String>> httpEntity = resolveValue(exchange, type);
|
||||
|
@ -250,7 +250,7 @@ public class HttpEntityArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void httpEntityWithRxJava2MaybeBody() throws Exception {
|
||||
public void httpEntityWithRxJava2MaybeBody() {
|
||||
ServerWebExchange exchange = postExchange("line1");
|
||||
ResolvableType type = httpEntityType(Maybe.class, String.class);
|
||||
HttpEntity<Maybe<String>> httpEntity = resolveValue(exchange, type);
|
||||
|
@ -270,7 +270,7 @@ public class HttpEntityArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void httpEntityWithFluxBody() throws Exception {
|
||||
public void httpEntityWithFluxBody() {
|
||||
ServerWebExchange exchange = postExchange("line1\nline2\nline3\n");
|
||||
ResolvableType type = httpEntityType(Flux.class, String.class);
|
||||
HttpEntity<Flux<String>> httpEntity = resolveValue(exchange, type);
|
||||
|
@ -285,7 +285,7 @@ public class HttpEntityArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void requestEntity() throws Exception {
|
||||
public void requestEntity() {
|
||||
ServerWebExchange exchange = postExchange("line1");
|
||||
ResolvableType type = forClassWithGenerics(RequestEntity.class, String.class);
|
||||
RequestEntity<String> requestEntity = resolveValue(exchange, type);
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -37,13 +37,11 @@ import org.springframework.web.reactive.BindingContext;
|
|||
import org.springframework.web.reactive.result.method.SyncHandlerMethodArgumentResolver;
|
||||
import org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link InitBinderBindingContext}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class InitBinderBindingContextTests {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -35,14 +35,12 @@ import org.springframework.web.method.ResolvableMethod;
|
|||
import org.springframework.web.reactive.BindingContext;
|
||||
import org.springframework.web.reactive.HandlerMapping;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.web.method.MvcAnnotationPredicates.matrixAttribute;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.web.method.MvcAnnotationPredicates.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link MatrixVariableMapMethodArgumentResolver}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class MatrixVariablesMapMethodArgumentResolverTests {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -37,13 +37,12 @@ import org.springframework.web.reactive.HandlerMapping;
|
|||
import org.springframework.web.server.ServerErrorException;
|
||||
import org.springframework.web.server.ServerWebInputException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.web.method.MvcAnnotationPredicates.matrixAttribute;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.web.method.MvcAnnotationPredicates.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link MatrixVariableMethodArgumentResolver}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class MatrixVariablesMethodArgumentResolverTests {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -59,12 +59,9 @@ import org.springframework.web.server.ServerWebExchange;
|
|||
import org.springframework.web.server.ServerWebInputException;
|
||||
import org.springframework.web.server.UnsupportedMediaTypeStatusException;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.core.ResolvableType.forClassWithGenerics;
|
||||
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.post;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.core.ResolvableType.*;
|
||||
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AbstractMessageReaderArgumentResolver}.
|
||||
|
|
|
@ -53,12 +53,11 @@ import org.springframework.util.ObjectUtils;
|
|||
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
|
||||
import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.springframework.core.io.buffer.support.DataBufferTestUtils.dumpString;
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON;
|
||||
import static org.springframework.web.method.ResolvableMethod.on;
|
||||
import static org.springframework.web.reactive.HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.core.io.buffer.support.DataBufferTestUtils.*;
|
||||
import static org.springframework.http.MediaType.*;
|
||||
import static org.springframework.web.method.ResolvableMethod.*;
|
||||
import static org.springframework.web.reactive.HandlerMapping.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AbstractMessageWriterResultHandler}.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -43,11 +43,7 @@ import org.springframework.web.method.ResolvableMethod;
|
|||
import org.springframework.web.reactive.BindingContext;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ModelAttributeMethodArgumentResolver}.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -53,10 +53,8 @@ import org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod
|
|||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.WebSession;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ModelInitializer}.
|
||||
|
@ -71,12 +69,11 @@ public class ModelInitializerTests {
|
|||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
public void setup() {
|
||||
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
|
||||
|
||||
ArgumentResolverConfigurer resolverConfigurer = new ArgumentResolverConfigurer();
|
||||
resolverConfigurer.addCustomResolver(new ModelArgumentResolver(adapterRegistry));
|
||||
resolverConfigurer.addCustomResolver(new ModelMethodArgumentResolver(adapterRegistry));
|
||||
|
||||
ControllerMethodResolver methodResolver = new ControllerMethodResolver(
|
||||
resolverConfigurer, adapterRegistry, new StaticApplicationContext(), Collections.emptyList());
|
||||
|
@ -85,10 +82,8 @@ public class ModelInitializerTests {
|
|||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void initBinderMethod() throws Exception {
|
||||
|
||||
public void initBinderMethod() {
|
||||
Validator validator = mock(Validator.class);
|
||||
|
||||
TestController controller = new TestController();
|
||||
|
@ -105,7 +100,7 @@ public class ModelInitializerTests {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void modelAttributeMethods() throws Exception {
|
||||
public void modelAttributeMethods() {
|
||||
TestController controller = new TestController();
|
||||
InitBinderBindingContext context = getBindingContext(controller);
|
||||
|
||||
|
@ -133,7 +128,7 @@ public class ModelInitializerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void saveModelAttributeToSession() throws Exception {
|
||||
public void saveModelAttributeToSession() {
|
||||
TestController controller = new TestController();
|
||||
InitBinderBindingContext context = getBindingContext(controller);
|
||||
|
||||
|
@ -151,7 +146,7 @@ public class ModelInitializerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void retrieveModelAttributeFromSession() throws Exception {
|
||||
public void retrieveModelAttributeFromSession() {
|
||||
WebSession session = this.exchange.getSession().block(Duration.ZERO);
|
||||
assertNotNull(session);
|
||||
|
||||
|
@ -171,7 +166,7 @@ public class ModelInitializerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void requiredSessionAttributeMissing() throws Exception {
|
||||
public void requiredSessionAttributeMissing() {
|
||||
TestController controller = new TestController();
|
||||
InitBinderBindingContext context = getBindingContext(controller);
|
||||
|
||||
|
@ -187,7 +182,7 @@ public class ModelInitializerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void clearModelAttributeFromSession() throws Exception {
|
||||
public void clearModelAttributeFromSession() {
|
||||
WebSession session = this.exchange.getSession().block(Duration.ZERO);
|
||||
assertNotNull(session);
|
||||
|
||||
|
@ -209,7 +204,6 @@ public class ModelInitializerTests {
|
|||
|
||||
|
||||
private InitBinderBindingContext getBindingContext(Object controller) {
|
||||
|
||||
List<SyncInvocableHandlerMethod> binderMethods =
|
||||
MethodIntrospector.selectMethods(controller.getClass(), BINDER_METHODS)
|
||||
.stream()
|
||||
|
@ -295,6 +289,7 @@ public class ModelInitializerTests {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private static final ReflectionUtils.MethodFilter BINDER_METHODS = method ->
|
||||
AnnotationUtils.findAnnotation(method, InitBinder.class) != null;
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.reactive.result.method.annotation;
|
||||
|
||||
import java.time.Duration;
|
||||
|
@ -34,13 +35,14 @@ import static org.junit.Assert.*;
|
|||
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ModelArgumentResolver}.
|
||||
* Unit tests for {@link ModelMethodArgumentResolver}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class ModelArgumentResolverTests {
|
||||
public class ModelMethodArgumentResolverTests {
|
||||
|
||||
private final ModelArgumentResolver resolver =
|
||||
new ModelArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
||||
private final ModelMethodArgumentResolver resolver =
|
||||
new ModelMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
||||
|
||||
private final ServerWebExchange exchange = MockServerWebExchange.from(get("/"));
|
||||
|
||||
|
@ -49,7 +51,6 @@ public class ModelArgumentResolverTests {
|
|||
|
||||
@Test
|
||||
public void supportsParameter() {
|
||||
|
||||
assertTrue(this.resolver.supportsParameter(this.resolvable.arg(Model.class)));
|
||||
assertTrue(this.resolver.supportsParameter(this.resolvable.arg(ModelMap.class)));
|
||||
assertTrue(this.resolver.supportsParameter(
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -34,10 +34,7 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||
import org.springframework.web.reactive.BindingContext;
|
||||
import org.springframework.web.reactive.HandlerMapping;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PathVariableMapMethodArgumentResolver}.
|
||||
|
@ -80,7 +77,7 @@ public class PathVariableMapMethodArgumentResolverTests {
|
|||
catch (IllegalStateException ex) {
|
||||
assertTrue("Unexpected error message:\n" + ex.getMessage(),
|
||||
ex.getMessage().startsWith(
|
||||
"PathVariableMapMethodArgumentResolver doesn't support reactive type wrapper"));
|
||||
"PathVariableMapMethodArgumentResolver does not support reactive type wrapper"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -39,10 +39,7 @@ import org.springframework.web.reactive.BindingContext;
|
|||
import org.springframework.web.reactive.HandlerMapping;
|
||||
import org.springframework.web.server.ServerErrorException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PathVariableMethodArgumentResolver}.
|
||||
|
@ -87,12 +84,12 @@ public class PathVariableMethodArgumentResolverTests {
|
|||
catch (IllegalStateException ex) {
|
||||
assertTrue("Unexpected error message:\n" + ex.getMessage(),
|
||||
ex.getMessage().startsWith(
|
||||
"PathVariableMethodArgumentResolver doesn't support reactive type wrapper"));
|
||||
"PathVariableMethodArgumentResolver does not support reactive type wrapper"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgument() throws Exception {
|
||||
public void resolveArgument() {
|
||||
Map<String, String> uriTemplateVars = new HashMap<>();
|
||||
uriTemplateVars.put("name", "value");
|
||||
this.exchange.getAttributes().put(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);
|
||||
|
@ -104,7 +101,7 @@ public class PathVariableMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentNotRequired() throws Exception {
|
||||
public void resolveArgumentNotRequired() {
|
||||
Map<String, String> uriTemplateVars = new HashMap<>();
|
||||
uriTemplateVars.put("name", "value");
|
||||
this.exchange.getAttributes().put(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);
|
||||
|
@ -116,7 +113,7 @@ public class PathVariableMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWrappedAsOptional() throws Exception {
|
||||
public void resolveArgumentWrappedAsOptional() {
|
||||
Map<String, String> uriTemplateVars = new HashMap<>();
|
||||
uriTemplateVars.put("name", "value");
|
||||
this.exchange.getAttributes().put(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);
|
||||
|
@ -131,7 +128,7 @@ public class PathVariableMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void handleMissingValue() throws Exception {
|
||||
public void handleMissingValue() {
|
||||
BindingContext bindingContext = new BindingContext();
|
||||
Mono<Object> mono = this.resolver.resolveArgument(this.paramNamedString, bindingContext, this.exchange);
|
||||
StepVerifier.create(mono)
|
||||
|
@ -141,7 +138,7 @@ public class PathVariableMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void nullIfNotRequired() throws Exception {
|
||||
public void nullIfNotRequired() {
|
||||
BindingContext bindingContext = new BindingContext();
|
||||
Mono<Object> mono = this.resolver.resolveArgument(this.paramNotRequired, bindingContext, this.exchange);
|
||||
StepVerifier.create(mono)
|
||||
|
@ -151,7 +148,7 @@ public class PathVariableMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void wrapEmptyWithOptional() throws Exception {
|
||||
public void wrapEmptyWithOptional() {
|
||||
BindingContext bindingContext = new BindingContext();
|
||||
Mono<Object> mono = this.resolver.resolveArgument(this.paramOptional, bindingContext, this.exchange);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -13,6 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.reactive.result.method.annotation;
|
||||
|
||||
import java.security.Principal;
|
||||
|
@ -29,23 +30,23 @@ import org.springframework.web.method.ResolvableMethod;
|
|||
import org.springframework.web.reactive.BindingContext;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PrincipalArgumentResolver}.
|
||||
* Unit tests for {@link PrincipalMethodArgumentResolver}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class PrincipalArgumentResolverTests {
|
||||
public class PrincipalMethodArgumentResolverTests {
|
||||
|
||||
private final PrincipalArgumentResolver resolver =
|
||||
new PrincipalArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
||||
private final PrincipalMethodArgumentResolver resolver =
|
||||
new PrincipalMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
||||
|
||||
private ResolvableMethod testMethod = ResolvableMethod.on(getClass()).named("handle").build();
|
||||
|
||||
|
||||
@Test
|
||||
public void supportsParameter() throws Exception {
|
||||
public void supportsParameter() {
|
||||
assertTrue(this.resolver.supportsParameter(this.testMethod.arg(Principal.class)));
|
||||
assertTrue(this.resolver.supportsParameter(this.testMethod.arg(Mono.class, Principal.class)));
|
||||
assertTrue(this.resolver.supportsParameter(this.testMethod.arg(Single.class, Principal.class)));
|
||||
|
@ -53,8 +54,7 @@ public class PrincipalArgumentResolverTests {
|
|||
|
||||
|
||||
@Test
|
||||
public void resolverArgument() throws Exception {
|
||||
|
||||
public void resolverArgument() {
|
||||
BindingContext context = new BindingContext();
|
||||
Principal user = () -> "Joe";
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"))
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -37,13 +37,8 @@ import org.springframework.web.method.ResolvableMethod;
|
|||
import org.springframework.web.reactive.BindingContext;
|
||||
import org.springframework.web.server.ServerWebInputException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.web.method.MvcAnnotationPredicates.requestAttribute;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.web.method.MvcAnnotationPredicates.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link RequestAttributeMethodArgumentResolver}.
|
||||
|
@ -71,8 +66,7 @@ public class RequestAttributeMethodArgumentResolverTests {
|
|||
|
||||
|
||||
@Test
|
||||
public void supportsParameter() throws Exception {
|
||||
|
||||
public void supportsParameter() {
|
||||
assertTrue(this.resolver.supportsParameter(
|
||||
this.testMethod.annot(requestAttribute().noName()).arg(Foo.class)));
|
||||
|
||||
|
@ -85,7 +79,7 @@ public class RequestAttributeMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void resolve() throws Exception {
|
||||
public void resolve() {
|
||||
MethodParameter param = this.testMethod.annot(requestAttribute().noName()).arg(Foo.class);
|
||||
Mono<Object> mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange);
|
||||
StepVerifier.create(mono)
|
||||
|
@ -100,7 +94,7 @@ public class RequestAttributeMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void resolveWithName() throws Exception {
|
||||
public void resolveWithName() {
|
||||
MethodParameter param = this.testMethod.annot(requestAttribute().name("specialFoo")).arg();
|
||||
Foo foo = new Foo();
|
||||
this.exchange.getAttributes().put("specialFoo", foo);
|
||||
|
@ -109,7 +103,7 @@ public class RequestAttributeMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void resolveNotRequired() throws Exception {
|
||||
public void resolveNotRequired() {
|
||||
MethodParameter param = this.testMethod.annot(requestAttribute().name("foo").notRequired()).arg();
|
||||
Mono<Object> mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange);
|
||||
assertNull(mono.block());
|
||||
|
@ -121,7 +115,7 @@ public class RequestAttributeMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void resolveOptional() throws Exception {
|
||||
public void resolveOptional() {
|
||||
MethodParameter param = this.testMethod.annot(requestAttribute().name("foo")).arg(Optional.class, Foo.class);
|
||||
Mono<Object> mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange);
|
||||
|
||||
|
@ -144,8 +138,8 @@ public class RequestAttributeMethodArgumentResolverTests {
|
|||
assertSame(foo, optional.get());
|
||||
}
|
||||
|
||||
@Test // SPR-16158
|
||||
public void resolveMonoParameter() throws Exception {
|
||||
@Test // SPR-16158
|
||||
public void resolveMonoParameter() {
|
||||
MethodParameter param = this.testMethod.annot(requestAttribute().noName()).arg(Mono.class, Foo.class);
|
||||
|
||||
// Mono attribute
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -45,23 +45,19 @@ import org.springframework.web.reactive.BindingContext;
|
|||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.ServerWebInputException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.web.method.MvcAnnotationPredicates.requestBody;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.web.method.MvcAnnotationPredicates.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link RequestBodyArgumentResolver}. When adding a test also
|
||||
* Unit tests for {@link RequestBodyMethodArgumentResolver}. When adding a test also
|
||||
* consider whether the logic under test is in a parent class, then see:
|
||||
* {@link MessageReaderArgumentResolverTests}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class RequestBodyArgumentResolverTests {
|
||||
public class RequestBodyMethodArgumentResolverTests {
|
||||
|
||||
private RequestBodyArgumentResolver resolver;
|
||||
private RequestBodyMethodArgumentResolver resolver;
|
||||
|
||||
private ResolvableMethod testMethod = ResolvableMethod.on(getClass()).named("handle").build();
|
||||
|
||||
|
@ -70,12 +66,12 @@ public class RequestBodyArgumentResolverTests {
|
|||
public void setup() {
|
||||
List<HttpMessageReader<?>> readers = new ArrayList<>();
|
||||
readers.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
|
||||
this.resolver = new RequestBodyArgumentResolver(readers, ReactiveAdapterRegistry.getSharedInstance());
|
||||
this.resolver = new RequestBodyMethodArgumentResolver(readers, ReactiveAdapterRegistry.getSharedInstance());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void supports() throws Exception {
|
||||
public void supports() {
|
||||
MethodParameter param;
|
||||
|
||||
param = this.testMethod.annot(requestBody()).arg(Mono.class, String.class);
|
||||
|
@ -86,7 +82,7 @@ public class RequestBodyArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void stringBody() throws Exception {
|
||||
public void stringBody() {
|
||||
String body = "line1";
|
||||
MethodParameter param = this.testMethod.annot(requestBody()).arg(String.class);
|
||||
String value = resolveValue(param, body);
|
||||
|
@ -95,13 +91,13 @@ public class RequestBodyArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test(expected = ServerWebInputException.class)
|
||||
public void emptyBodyWithString() throws Exception {
|
||||
public void emptyBodyWithString() {
|
||||
MethodParameter param = this.testMethod.annot(requestBody()).arg(String.class);
|
||||
resolveValueWithEmptyBody(param);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyBodyWithStringNotRequired() throws Exception {
|
||||
public void emptyBodyWithStringNotRequired() {
|
||||
MethodParameter param = this.testMethod.annot(requestBody().notRequired()).arg(String.class);
|
||||
String body = resolveValueWithEmptyBody(param);
|
||||
|
||||
|
@ -109,7 +105,7 @@ public class RequestBodyArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test // SPR-15758
|
||||
public void emptyBodyWithoutContentType() throws Exception {
|
||||
public void emptyBodyWithoutContentType() {
|
||||
MethodParameter param = this.testMethod.annot(requestBody().notRequired()).arg(Map.class);
|
||||
String body = resolveValueWithEmptyBody(param);
|
||||
|
||||
|
@ -118,8 +114,7 @@ public class RequestBodyArgumentResolverTests {
|
|||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void emptyBodyWithMono() throws Exception {
|
||||
|
||||
public void emptyBodyWithMono() {
|
||||
MethodParameter param = this.testMethod.annot(requestBody()).arg(Mono.class, String.class);
|
||||
StepVerifier.create((Mono<Void>) resolveValueWithEmptyBody(param))
|
||||
.expectNextCount(0)
|
||||
|
@ -135,8 +130,7 @@ public class RequestBodyArgumentResolverTests {
|
|||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void emptyBodyWithFlux() throws Exception {
|
||||
|
||||
public void emptyBodyWithFlux() {
|
||||
MethodParameter param = this.testMethod.annot(requestBody()).arg(Flux.class, String.class);
|
||||
StepVerifier.create((Flux<Void>) resolveValueWithEmptyBody(param))
|
||||
.expectNextCount(0)
|
||||
|
@ -151,8 +145,7 @@ public class RequestBodyArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void emptyBodyWithSingle() throws Exception {
|
||||
|
||||
public void emptyBodyWithSingle() {
|
||||
MethodParameter param = this.testMethod.annot(requestBody()).arg(Single.class, String.class);
|
||||
Single<String> single = resolveValueWithEmptyBody(param);
|
||||
StepVerifier.create(RxReactiveStreams.toPublisher(single))
|
||||
|
@ -169,8 +162,7 @@ public class RequestBodyArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void emptyBodyWithMaybe() throws Exception {
|
||||
|
||||
public void emptyBodyWithMaybe() {
|
||||
MethodParameter param = this.testMethod.annot(requestBody()).arg(Maybe.class, String.class);
|
||||
Maybe<String> maybe = resolveValueWithEmptyBody(param);
|
||||
StepVerifier.create(maybe.toFlowable())
|
||||
|
@ -187,8 +179,7 @@ public class RequestBodyArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void emptyBodyWithObservable() throws Exception {
|
||||
|
||||
public void emptyBodyWithObservable() {
|
||||
MethodParameter param = this.testMethod.annot(requestBody()).arg(Observable.class, String.class);
|
||||
Observable<String> observable = resolveValueWithEmptyBody(param);
|
||||
StepVerifier.create(RxReactiveStreams.toPublisher(observable))
|
||||
|
@ -205,8 +196,7 @@ public class RequestBodyArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void emptyBodyWithCompletableFuture() throws Exception {
|
||||
|
||||
public void emptyBodyWithCompletableFuture() {
|
||||
MethodParameter param = this.testMethod.annot(requestBody()).arg(CompletableFuture.class, String.class);
|
||||
CompletableFuture<String> future = resolveValueWithEmptyBody(param);
|
||||
future.whenComplete((text, ex) -> {
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -35,10 +35,7 @@ import org.springframework.util.MultiValueMap;
|
|||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link RequestHeaderMapMethodArgumentResolver}.
|
||||
|
@ -83,12 +80,12 @@ public class RequestHeaderMapMethodArgumentResolverTests {
|
|||
catch (IllegalStateException ex) {
|
||||
assertTrue("Unexpected error message:\n" + ex.getMessage(),
|
||||
ex.getMessage().startsWith(
|
||||
"RequestHeaderMapMethodArgumentResolver doesn't support reactive type wrapper"));
|
||||
"RequestHeaderMapMethodArgumentResolver does not support reactive type wrapper"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveMapArgument() throws Exception {
|
||||
public void resolveMapArgument() {
|
||||
String name = "foo";
|
||||
String value = "bar";
|
||||
Map<String, String> expected = Collections.singletonMap(name, value);
|
||||
|
@ -103,7 +100,7 @@ public class RequestHeaderMapMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void resolveMultiValueMapArgument() throws Exception {
|
||||
public void resolveMultiValueMapArgument() {
|
||||
String name = "foo";
|
||||
String value1 = "bar";
|
||||
String value2 = "baz";
|
||||
|
@ -122,7 +119,7 @@ public class RequestHeaderMapMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void resolveHttpHeadersArgument() throws Exception {
|
||||
public void resolveHttpHeadersArgument() {
|
||||
String name = "foo";
|
||||
String value1 = "bar";
|
||||
String value2 = "baz";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -41,11 +41,7 @@ import org.springframework.web.reactive.BindingContext;
|
|||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.ServerWebInputException;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link RequestHeaderMethodArgumentResolver}.
|
||||
|
@ -106,12 +102,12 @@ public class RequestHeaderMethodArgumentResolverTests {
|
|||
catch (IllegalStateException ex) {
|
||||
assertTrue("Unexpected error message:\n" + ex.getMessage(),
|
||||
ex.getMessage().startsWith(
|
||||
"RequestHeaderMethodArgumentResolver doesn't support reactive type wrapper"));
|
||||
"RequestHeaderMethodArgumentResolver does not support reactive type wrapper"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveStringArgument() throws Exception {
|
||||
public void resolveStringArgument() {
|
||||
String expected = "foo";
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("name", expected));
|
||||
|
||||
|
@ -124,7 +120,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void resolveStringArrayArgument() throws Exception {
|
||||
public void resolveStringArrayArgument() {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("name", "foo", "bar").build();
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
|
||||
|
@ -137,7 +133,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void resolveDefaultValue() throws Exception {
|
||||
public void resolveDefaultValue() {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
Mono<Object> mono = this.resolver.resolveArgument(
|
||||
this.paramNamedDefaultValueStringHeader, this.bindingContext, exchange);
|
||||
|
@ -148,7 +144,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void resolveDefaultValueFromSystemProperty() throws Exception {
|
||||
public void resolveDefaultValueFromSystemProperty() {
|
||||
System.setProperty("systemProperty", "bar");
|
||||
try {
|
||||
Mono<Object> mono = this.resolver.resolveArgument(
|
||||
|
@ -165,7 +161,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void resolveNameFromSystemPropertyThroughExpression() throws Exception {
|
||||
public void resolveNameFromSystemPropertyThroughExpression() {
|
||||
String expected = "foo";
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("bar", expected).build();
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
|
@ -185,7 +181,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void resolveNameFromSystemPropertyThroughPlaceholder() throws Exception {
|
||||
public void resolveNameFromSystemPropertyThroughPlaceholder() {
|
||||
String expected = "foo";
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("bar", expected).build();
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
|
@ -205,7 +201,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void notFound() throws Exception {
|
||||
public void notFound() {
|
||||
Mono<Object> mono = resolver.resolveArgument(
|
||||
this.paramNamedValueStringArray, this.bindingContext,
|
||||
MockServerWebExchange.from(MockServerHttpRequest.get("/")));
|
||||
|
@ -218,7 +214,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
|||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void dateConversion() throws Exception {
|
||||
public void dateConversion() {
|
||||
String rfc1123val = "Thu, 21 Apr 2016 17:11:08 +0100";
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("name", rfc1123val).build();
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
|
@ -231,7 +227,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void instantConversion() throws Exception {
|
||||
public void instantConversion() {
|
||||
String rfc1123val = "Thu, 21 Apr 2016 17:11:08 +0100";
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("name", rfc1123val).build();
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -46,9 +46,7 @@ import org.springframework.web.reactive.result.method.RequestMappingInfo;
|
|||
import org.springframework.web.util.pattern.PathPattern;
|
||||
import org.springframework.web.util.pattern.PathPatternParser;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
|
@ -68,6 +66,7 @@ public class RequestMappingHandlerMappingTests {
|
|||
this.handlerMapping.setApplicationContext(wac);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void resolveEmbeddedValuesInPatterns() {
|
||||
this.handlerMapping.setEmbeddedValueResolver(value -> "/${pattern}/bar".equals(value) ? "/foo/bar" : value);
|
||||
|
@ -79,7 +78,7 @@ public class RequestMappingHandlerMappingTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void pathPrefix() throws NoSuchMethodException {
|
||||
public void pathPrefix() throws Exception {
|
||||
this.handlerMapping.setEmbeddedValueResolver(value -> "/${prefix}".equals(value) ? "/api" : value);
|
||||
this.handlerMapping.setPathPrefixes(Collections.singletonMap(
|
||||
"/${prefix}", HandlerTypePredicate.forAnnotation(RestController.class)));
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -33,14 +33,12 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||
import org.springframework.web.method.ResolvableMethod;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.springframework.web.method.MvcAnnotationPredicates.requestParam;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.web.method.MvcAnnotationPredicates.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link RequestParamMapMethodArgumentResolver}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class RequestParamMapMethodArgumentResolverTests {
|
||||
|
@ -73,12 +71,12 @@ public class RequestParamMapMethodArgumentResolverTests {
|
|||
catch (IllegalStateException ex) {
|
||||
assertTrue("Unexpected error message:\n" + ex.getMessage(),
|
||||
ex.getMessage().startsWith(
|
||||
"RequestParamMapMethodArgumentResolver doesn't support reactive type wrapper"));
|
||||
"RequestParamMapMethodArgumentResolver does not support reactive type wrapper"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveMapArgumentWithQueryString() throws Exception {
|
||||
public void resolveMapArgumentWithQueryString() {
|
||||
MethodParameter param = this.testMethod.annot(requestParam().name("")).arg(Map.class);
|
||||
Object result= resolve(param, MockServerWebExchange.from(MockServerHttpRequest.get("/path?foo=bar")));
|
||||
assertTrue(result instanceof Map);
|
||||
|
@ -86,7 +84,7 @@ public class RequestParamMapMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void resolveMultiValueMapArgument() throws Exception {
|
||||
public void resolveMultiValueMapArgument() {
|
||||
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultiValueMap.class);
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?foo=bar&foo=baz"));
|
||||
Object result= resolve(param, exchange);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -37,14 +37,9 @@ import org.springframework.web.reactive.BindingContext;
|
|||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.ServerWebInputException;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.springframework.core.ResolvableType.forClassWithGenerics;
|
||||
import static org.springframework.web.method.MvcAnnotationPredicates.requestParam;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.core.ResolvableType.*;
|
||||
import static org.springframework.web.method.MvcAnnotationPredicates.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link RequestParamMethodArgumentResolver}.
|
||||
|
@ -118,7 +113,7 @@ public class RequestParamMethodArgumentResolverTests {
|
|||
catch (IllegalStateException ex) {
|
||||
assertTrue("Unexpected error message:\n" + ex.getMessage(),
|
||||
ex.getMessage().startsWith(
|
||||
"RequestParamMethodArgumentResolver doesn't support reactive type wrapper"));
|
||||
"RequestParamMethodArgumentResolver does not support reactive type wrapper"));
|
||||
}
|
||||
try {
|
||||
param = this.testMethod.annotNotPresent(RequestParam.class).arg(Mono.class, String.class);
|
||||
|
@ -128,7 +123,7 @@ public class RequestParamMethodArgumentResolverTests {
|
|||
catch (IllegalStateException ex) {
|
||||
assertTrue("Unexpected error message:\n" + ex.getMessage(),
|
||||
ex.getMessage().startsWith(
|
||||
"RequestParamMethodArgumentResolver doesn't support reactive type wrapper"));
|
||||
"RequestParamMethodArgumentResolver does not support reactive type wrapper"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -41,17 +41,15 @@ import org.springframework.web.reactive.HandlerResult;
|
|||
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
|
||||
import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.web.method.ResolvableMethod.on;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.web.method.ResolvableMethod.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ResponseBodyResultHandler}.When adding a test also
|
||||
* consider whether the logic under test is in a parent class, then see:
|
||||
* <ul>
|
||||
* <li>{@code MessageWriterResultHandlerTests},
|
||||
* <li>{@code ContentNegotiatingResultHandlerSupportTests}
|
||||
* <li>{@code MessageWriterResultHandlerTests},
|
||||
* <li>{@code ContentNegotiatingResultHandlerSupportTests}
|
||||
* </ul>
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
|
@ -76,7 +74,7 @@ public class ResponseBodyResultHandlerTests {
|
|||
|
||||
|
||||
@Test
|
||||
public void supports() throws NoSuchMethodException {
|
||||
public void supports() {
|
||||
Object controller = new TestController();
|
||||
Method method;
|
||||
|
||||
|
@ -89,7 +87,7 @@ public class ResponseBodyResultHandlerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void supportsRestController() throws NoSuchMethodException {
|
||||
public void supportsRestController() {
|
||||
Object controller = new TestRestController();
|
||||
Method method;
|
||||
|
||||
|
@ -117,7 +115,7 @@ public class ResponseBodyResultHandlerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void defaultOrder() throws Exception {
|
||||
public void defaultOrder() {
|
||||
assertEquals(100, this.resultHandler.getOrder());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -37,20 +37,17 @@ import org.springframework.web.server.WebSession;
|
|||
import org.springframework.web.util.UriBuilder;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ServerWebExchangeArgumentResolver}.
|
||||
* Unit tests for {@link ServerWebExchangeMethodArgumentResolver}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class ServerWebExchangeArgumentResolverTests {
|
||||
public class ServerWebExchangeMethodArgumentResolverTests {
|
||||
|
||||
private final ServerWebExchangeArgumentResolver resolver =
|
||||
new ServerWebExchangeArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
||||
private final ServerWebExchangeMethodArgumentResolver resolver =
|
||||
new ServerWebExchangeMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
||||
|
||||
private final MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.get("https://example.org:9999/path?q=foo"));
|
||||
|
@ -79,7 +76,7 @@ public class ServerWebExchangeArgumentResolverTests {
|
|||
catch (IllegalStateException ex) {
|
||||
assertTrue("Unexpected error message:\n" + ex.getMessage(),
|
||||
ex.getMessage().startsWith(
|
||||
"ServerWebExchangeArgumentResolver doesn't support reactive type wrapper"));
|
||||
"ServerWebExchangeMethodArgumentResolver does not support reactive type wrapper"));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -32,13 +32,14 @@ import static org.junit.Assert.*;
|
|||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link WebSessionArgumentResolver}.
|
||||
* Unit tests for {@link WebSessionMethodArgumentResolver}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class WebSessionArgumentResolverTests {
|
||||
public class WebSessionMethodArgumentResolverTests {
|
||||
|
||||
private final WebSessionArgumentResolver resolver =
|
||||
new WebSessionArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
||||
private final WebSessionMethodArgumentResolver resolver =
|
||||
new WebSessionMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
||||
|
||||
private ResolvableMethod testMethod = ResolvableMethod.on(getClass()).named("handle").build();
|
||||
|
Loading…
Reference in New Issue