提交 28039057 编写于 作者: J Juergen Hoeller

Consistent naming of HandlerMethodArgumentResolver implementations

Includes combined imports of assertion methods and related polishing.

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