Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -39,6 +39,7 @@ class CacheResultInterceptor extends AbstractKeyCacheInterceptor<CacheResultOper
|
||||
super(errorHandler);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Object invoke(CacheOperationInvocationContext<CacheResultOperation> context,
|
||||
CacheOperationInvoker invoker) {
|
||||
@@ -82,7 +83,6 @@ class CacheResultInterceptor extends AbstractKeyCacheInterceptor<CacheResultOper
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void cacheException(Cache exceptionCache, ExceptionTypeFilter filter, Object cacheKey, Throwable ex) {
|
||||
if (exceptionCache == null) {
|
||||
return;
|
||||
@@ -92,7 +92,6 @@ class CacheResultInterceptor extends AbstractKeyCacheInterceptor<CacheResultOper
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Cache resolveExceptionCache(CacheOperationInvocationContext<CacheResultOperation> context) {
|
||||
CacheResolver exceptionCacheResolver = context.getOperation().getExceptionCacheResolver();
|
||||
if (exceptionCacheResolver != null) {
|
||||
@@ -101,9 +100,10 @@ class CacheResultInterceptor extends AbstractKeyCacheInterceptor<CacheResultOper
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Rewrite the call stack of the specified {@code exception} so that it matches
|
||||
* the current call stack up-to (included) the specified method invocation.
|
||||
* the current call stack up to (included) the specified method invocation.
|
||||
* <p>Clone the specified exception. If the exception is not {@code serializable},
|
||||
* the original exception is returned. If no common ancestor can be found, returns
|
||||
* the original exception.
|
||||
@@ -111,8 +111,8 @@ class CacheResultInterceptor extends AbstractKeyCacheInterceptor<CacheResultOper
|
||||
* @param exception the exception to merge with the current call stack
|
||||
* @param className the class name of the common ancestor
|
||||
* @param methodName the method name of the common ancestor
|
||||
* @return a clone exception with a rewritten call stack composed of the current
|
||||
* call stack up to (included) the common ancestor specified by the {@code className} and
|
||||
* @return a clone exception with a rewritten call stack composed of the current call
|
||||
* stack up to (included) the common ancestor specified by the {@code className} and
|
||||
* {@code methodName} arguments, followed by stack trace elements of the specified
|
||||
* {@code exception} after the common ancestor.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -49,9 +49,6 @@ import static org.mockito.BDDMockito.*;
|
||||
*/
|
||||
public class JCacheErrorHandlerTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private Cache cache;
|
||||
|
||||
private Cache errorCache;
|
||||
@@ -60,20 +57,23 @@ public class JCacheErrorHandlerTests {
|
||||
|
||||
private SimpleService simpleService;
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
AnnotationConfigApplicationContext context =
|
||||
new AnnotationConfigApplicationContext(Config.class);
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||
this.cache = context.getBean("mockCache", Cache.class);
|
||||
this.errorCache = context.getBean("mockErrorCache", Cache.class);
|
||||
this.errorHandler = context.getBean(CacheErrorHandler.class);
|
||||
this.simpleService = context.getBean(SimpleService.class);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getFail() {
|
||||
UnsupportedOperationException exception =
|
||||
new UnsupportedOperationException("Test exception on get");
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on get");
|
||||
Object key = SimpleKeyGenerator.generateKey(0L);
|
||||
willThrow(exception).given(this.cache).get(key);
|
||||
|
||||
@@ -83,8 +83,7 @@ public class JCacheErrorHandlerTests {
|
||||
|
||||
@Test
|
||||
public void getPutNewElementFail() {
|
||||
UnsupportedOperationException exception =
|
||||
new UnsupportedOperationException("Test exception on put");
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put");
|
||||
Object key = SimpleKeyGenerator.generateKey(0L);
|
||||
given(this.cache.get(key)).willReturn(null);
|
||||
willThrow(exception).given(this.cache).put(key, 0L);
|
||||
@@ -95,12 +94,10 @@ public class JCacheErrorHandlerTests {
|
||||
|
||||
@Test
|
||||
public void getFailPutExceptionFail() {
|
||||
UnsupportedOperationException exceptionOnPut =
|
||||
new UnsupportedOperationException("Test exception on put");
|
||||
UnsupportedOperationException exceptionOnPut = new UnsupportedOperationException("Test exception on put");
|
||||
Object key = SimpleKeyGenerator.generateKey(0L);
|
||||
given(this.cache.get(key)).willReturn(null);
|
||||
willThrow(exceptionOnPut).given(this.errorCache).put(key,
|
||||
SimpleService.TEST_EXCEPTION);
|
||||
willThrow(exceptionOnPut).given(this.errorCache).put(key, SimpleService.TEST_EXCEPTION);
|
||||
|
||||
try {
|
||||
this.simpleService.getFail(0L);
|
||||
@@ -108,14 +105,13 @@ public class JCacheErrorHandlerTests {
|
||||
catch (IllegalStateException ex) {
|
||||
assertEquals("Test exception", ex.getMessage());
|
||||
}
|
||||
verify(this.errorHandler).handleCachePutError(exceptionOnPut,
|
||||
this.errorCache, key, SimpleService.TEST_EXCEPTION);
|
||||
verify(this.errorHandler).handleCachePutError(
|
||||
exceptionOnPut, this.errorCache, key, SimpleService.TEST_EXCEPTION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putFail() {
|
||||
UnsupportedOperationException exception =
|
||||
new UnsupportedOperationException("Test exception on put");
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put");
|
||||
Object key = SimpleKeyGenerator.generateKey(0L);
|
||||
willThrow(exception).given(this.cache).put(key, 234L);
|
||||
|
||||
@@ -125,8 +121,7 @@ public class JCacheErrorHandlerTests {
|
||||
|
||||
@Test
|
||||
public void evictFail() {
|
||||
UnsupportedOperationException exception =
|
||||
new UnsupportedOperationException("Test exception on evict");
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict");
|
||||
Object key = SimpleKeyGenerator.generateKey(0L);
|
||||
willThrow(exception).given(this.cache).evict(key);
|
||||
|
||||
@@ -136,8 +131,7 @@ public class JCacheErrorHandlerTests {
|
||||
|
||||
@Test
|
||||
public void clearFail() {
|
||||
UnsupportedOperationException exception =
|
||||
new UnsupportedOperationException("Test exception on evict");
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict");
|
||||
willThrow(exception).given(this.cache).clear();
|
||||
|
||||
this.simpleService.clear();
|
||||
@@ -181,14 +175,13 @@ public class JCacheErrorHandlerTests {
|
||||
given(cache.getName()).willReturn("error");
|
||||
return cache;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@CacheDefaults(cacheName = "test")
|
||||
public static class SimpleService {
|
||||
|
||||
private static final IllegalStateException TEST_EXCEPTION =
|
||||
new IllegalStateException("Test exception");
|
||||
private static final IllegalStateException TEST_EXCEPTION = new IllegalStateException("Test exception");
|
||||
|
||||
private AtomicLong counter = new AtomicLong();
|
||||
|
||||
@@ -214,4 +207,5 @@ public class JCacheErrorHandlerTests {
|
||||
public void clear() {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -55,6 +55,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
* @see MethodValidationInterceptor
|
||||
* @see javax.validation.executable.ExecutableValidator
|
||||
* @see org.hibernate.validator.method.MethodValidator
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,19 +31,18 @@ import org.springframework.transaction.TransactionUsageException;
|
||||
import org.springframework.transaction.support.SmartTransactionObject;
|
||||
|
||||
/**
|
||||
* Convenient base class for JDBC-aware transaction objects.
|
||||
* Can contain a {@link ConnectionHolder}, and implements the
|
||||
* {@link org.springframework.transaction.SavepointManager}
|
||||
* interface based on that ConnectionHolder.
|
||||
* Convenient base class for JDBC-aware transaction objects. Can contain a
|
||||
* {@link ConnectionHolder} with a JDBC {@code Connection}, and implements the
|
||||
* {@link SavepointManager} interface based on that {@code ConnectionHolder}.
|
||||
*
|
||||
* <p>Allows for programmatic management of JDBC 3.0
|
||||
* {@link java.sql.Savepoint Savepoints}. Spring's
|
||||
* {@link org.springframework.transaction.support.DefaultTransactionStatus}
|
||||
* will automatically delegate to this, as it autodetects transaction
|
||||
* objects that implement the SavepointManager interface.
|
||||
* <p>Allows for programmatic management of JDBC {@link java.sql.Savepoint Savepoints}.
|
||||
* Spring's {@link org.springframework.transaction.support.DefaultTransactionStatus}
|
||||
* automatically delegates to this, as it autodetects transaction objects which
|
||||
* implement the {@link SavepointManager} interface.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 1.1
|
||||
* @see DataSourceTransactionManager
|
||||
*/
|
||||
public abstract class JdbcTransactionObjectSupport implements SavepointManager, SmartTransactionObject {
|
||||
|
||||
@@ -151,7 +150,7 @@ public abstract class JdbcTransactionObjectSupport implements SavepointManager,
|
||||
}
|
||||
if (!hasConnectionHolder()) {
|
||||
throw new TransactionUsageException(
|
||||
"Cannot create nested transaction if not exposing a JDBC transaction");
|
||||
"Cannot create nested transaction when not exposing a JDBC transaction");
|
||||
}
|
||||
return getConnectionHolder();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,9 +23,9 @@ import org.springframework.transaction.TransactionTimedOutException;
|
||||
/**
|
||||
* Convenient base class for resource holders.
|
||||
*
|
||||
* <p>Features rollback-only support for nested transactions.
|
||||
* Can expire after a certain number of seconds or milliseconds,
|
||||
* to determine transactional timeouts.
|
||||
* <p>Features rollback-only support for participating transactions.
|
||||
* Can expire after a certain number of seconds or milliseconds
|
||||
* in order to determine a transactional timeout.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 02.02.2004
|
||||
|
||||
@@ -141,8 +141,7 @@ class Netty4ClientHttpRequest extends AbstractAsyncClientHttpRequest implements
|
||||
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
|
||||
nettyRequest.headers().add(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (!nettyRequest.headers().contains(HttpHeaders.CONTENT_LENGTH)
|
||||
&& this.body.buffer().readableBytes() > 0) {
|
||||
if (!nettyRequest.headers().contains(HttpHeaders.CONTENT_LENGTH) && this.body.buffer().readableBytes() > 0) {
|
||||
nettyRequest.headers().set(HttpHeaders.CONTENT_LENGTH, this.body.buffer().readableBytes());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -54,8 +54,7 @@ import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.1
|
||||
*/
|
||||
public class ModelAttributeMethodProcessor
|
||||
implements HandlerMethodArgumentResolver, HandlerMethodReturnValueHandler {
|
||||
public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResolver, HandlerMethodReturnValueHandler {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -251,7 +251,7 @@ public abstract class AbstractMessageConverterMethodArgumentResolver implements
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the request part if applicable.
|
||||
* Validate the binding target if applicable.
|
||||
* <p>The default implementation checks for {@code @javax.validation.Valid},
|
||||
* Spring's {@link org.springframework.validation.annotation.Validated},
|
||||
* and custom annotations whose name starts with "Valid".
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -110,8 +110,8 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
|
||||
* @param mavContainer the ModelAndViewContainer for this request
|
||||
* @param providedArgs "given" arguments matched by type (not resolved)
|
||||
*/
|
||||
public void invokeAndHandle(ServletWebRequest webRequest,
|
||||
ModelAndViewContainer mavContainer, Object... providedArgs) throws Exception {
|
||||
public void invokeAndHandle(ServletWebRequest webRequest, ModelAndViewContainer mavContainer,
|
||||
Object... providedArgs) throws Exception {
|
||||
|
||||
Object returnValue = invokeForRequest(webRequest, mavContainer, providedArgs);
|
||||
setResponseStatus(webRequest);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -144,7 +144,6 @@ import org.springframework.web.servlet.view.velocity.VelocityConfigurer;
|
||||
import org.springframework.web.servlet.view.velocity.VelocityViewResolver;
|
||||
import org.springframework.web.util.UrlPathHelper;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -161,7 +160,9 @@ import static org.junit.Assert.*;
|
||||
*/
|
||||
public class MvcNamespaceTests {
|
||||
|
||||
public static final String VIEWCONTROLLER_BEAN_NAME = "org.springframework.web.servlet.config.viewControllerHandlerMapping";
|
||||
public static final String VIEWCONTROLLER_BEAN_NAME =
|
||||
"org.springframework.web.servlet.config.viewControllerHandlerMapping";
|
||||
|
||||
|
||||
private GenericWebApplicationContext appContext;
|
||||
|
||||
@@ -199,7 +200,7 @@ public class MvcNamespaceTests {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.json");
|
||||
NativeWebRequest webRequest = new ServletWebRequest(request);
|
||||
ContentNegotiationManager manager = mapping.getContentNegotiationManager();
|
||||
assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(webRequest));
|
||||
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(webRequest));
|
||||
|
||||
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
|
||||
assertNotNull(adapter);
|
||||
@@ -707,7 +708,8 @@ public class MvcNamespaceTests {
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.xml");
|
||||
NativeWebRequest webRequest = new ServletWebRequest(request);
|
||||
assertEquals(Arrays.asList(MediaType.valueOf("application/rss+xml")), manager.resolveMediaTypes(webRequest));
|
||||
assertEquals(Collections.singletonList(MediaType.valueOf("application/rss+xml")),
|
||||
manager.resolveMediaTypes(webRequest));
|
||||
|
||||
ViewResolverComposite compositeResolver = this.appContext.getBean(ViewResolverComposite.class);
|
||||
assertNotNull(compositeResolver);
|
||||
@@ -927,14 +929,14 @@ public class MvcNamespaceTests {
|
||||
assertArrayEquals(new String[]{"header1", "header2", "header3"}, config.getAllowedHeaders().toArray());
|
||||
assertArrayEquals(new String[]{"header1", "header2"}, config.getExposedHeaders().toArray());
|
||||
assertFalse(config.getAllowCredentials());
|
||||
assertEquals(new Long(123), config.getMaxAge());
|
||||
assertEquals(Long.valueOf(123), config.getMaxAge());
|
||||
config = configs.get("/resources/**");
|
||||
assertArrayEquals(new String[]{"http://domain1.com"}, config.getAllowedOrigins().toArray());
|
||||
assertArrayEquals(new String[]{"GET", "HEAD", "POST"}, config.getAllowedMethods().toArray());
|
||||
assertArrayEquals(new String[]{"*"}, config.getAllowedHeaders().toArray());
|
||||
assertNull(config.getExposedHeaders());
|
||||
assertTrue(config.getAllowCredentials());
|
||||
assertEquals(new Long(1800), config.getMaxAge());
|
||||
assertEquals(Long.valueOf(1800), config.getMaxAge());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -950,21 +952,21 @@ public class MvcNamespaceTests {
|
||||
|
||||
|
||||
@DateTimeFormat(iso = ISO.DATE)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface IsoDate {
|
||||
}
|
||||
|
||||
|
||||
@NumberFormat(style = NumberFormat.Style.PERCENT)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface PercentNumber {
|
||||
}
|
||||
|
||||
|
||||
@Validated(MyGroup.class)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface MyValid {
|
||||
}
|
||||
@@ -983,6 +985,7 @@ public class MvcNamespaceTests {
|
||||
public void testBind(@RequestParam @IsoDate Date date,
|
||||
@RequestParam(required = false) @PercentNumber Double percent,
|
||||
@MyValid TestBean bean, BindingResult result) {
|
||||
|
||||
this.date = date;
|
||||
this.percent = percent;
|
||||
this.recordedValidationError = (result.getErrorCount() == 1);
|
||||
|
||||
Reference in New Issue
Block a user