Unwrap proxied DataSources in SqlScriptsTestExecutionListener

Prior to this commit, if the DataSource in the
DataSourceFromTransactionManager was wrapped in a proxy implementing
InfrastructureProxy, SqlScriptsTestExecutionListener would throw an
exception stating that the DataSource in the ApplicationContext and the
DataSource in the DataSourceFromTransactionManager were not the same.

This commit unwraps both data sources and compares the underlying
target instances to check for equality.

In addition, this commit makes the unwrapResourceIfNecessary() method in
TransactionSynchronizationUtils public.

Closes gh-26422
This commit is contained in:
Sam Brannen
2021-01-22 18:22:00 +01:00
parent bad8954e65
commit 4a7a2258f9
3 changed files with 144 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,7 +45,7 @@ public abstract class TransactionSynchronizationUtils {
/**
* Check whether the given resource transaction managers refers to the given
* Check whether the given resource transaction manager refers to the given
* (underlying) resource factory.
* @see ResourceTransactionManager#getResourceFactory()
* @see org.springframework.core.InfrastructureProxy#getWrappedObject()
@@ -59,7 +59,7 @@ public abstract class TransactionSynchronizationUtils {
* the given handle as-is.
* @see org.springframework.core.InfrastructureProxy#getWrappedObject()
*/
static Object unwrapResourceIfNecessary(Object resource) {
public static Object unwrapResourceIfNecessary(Object resource) {
Assert.notNull(resource, "Resource must not be null");
Object resourceRef = resource;
// unwrap infrastructure proxy