Polishing
This commit is contained in:
parent
6d9736acd0
commit
f22a1eece4
|
|
@ -53,8 +53,6 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
|||
*/
|
||||
class AspectJExpressionPointcutTests {
|
||||
|
||||
public static final String MATCH_ALL_METHODS = "execution(* *(..))";
|
||||
|
||||
private Method getAge;
|
||||
|
||||
private Method setAge;
|
||||
|
|
@ -175,25 +173,25 @@ class AspectJExpressionPointcutTests {
|
|||
@Test
|
||||
void testFriendlyErrorOnNoLocationClassMatching() {
|
||||
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
pc.matches(ITestBean.class))
|
||||
.withMessageContaining("expression");
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> pc.matches(ITestBean.class))
|
||||
.withMessageContaining("expression");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFriendlyErrorOnNoLocation2ArgMatching() {
|
||||
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
pc.matches(getAge, ITestBean.class))
|
||||
.withMessageContaining("expression");
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> pc.matches(getAge, ITestBean.class))
|
||||
.withMessageContaining("expression");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFriendlyErrorOnNoLocation3ArgMatching() {
|
||||
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
pc.matches(getAge, ITestBean.class, (Object[]) null))
|
||||
.withMessageContaining("expression");
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> pc.matches(getAge, ITestBean.class, (Object[]) null))
|
||||
.withMessageContaining("expression");
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -210,8 +208,10 @@ class AspectJExpressionPointcutTests {
|
|||
// not currently testable in a reliable fashion
|
||||
//assertDoesNotMatchStringClass(classFilter);
|
||||
|
||||
assertThat(methodMatcher.matches(setSomeNumber, TestBean.class, 12D)).as("Should match with setSomeNumber with Double input").isTrue();
|
||||
assertThat(methodMatcher.matches(setSomeNumber, TestBean.class, 11)).as("Should not match setSomeNumber with Integer input").isFalse();
|
||||
assertThat(methodMatcher.matches(setSomeNumber, TestBean.class, 12D))
|
||||
.as("Should match with setSomeNumber with Double input").isTrue();
|
||||
assertThat(methodMatcher.matches(setSomeNumber, TestBean.class, 11))
|
||||
.as("Should not match setSomeNumber with Integer input").isFalse();
|
||||
assertThat(methodMatcher.matches(getAge, TestBean.class)).as("Should not match getAge").isFalse();
|
||||
assertThat(methodMatcher.isRuntime()).as("Should be a runtime match").isTrue();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -137,17 +137,6 @@ import org.springframework.util.ReflectionUtils;
|
|||
public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
||||
implements ConfigurableApplicationContext {
|
||||
|
||||
/**
|
||||
* The name of the {@link LifecycleProcessor} bean in the context.
|
||||
* If none is supplied, a {@link DefaultLifecycleProcessor} is used.
|
||||
* @since 3.0
|
||||
* @see org.springframework.context.LifecycleProcessor
|
||||
* @see org.springframework.context.support.DefaultLifecycleProcessor
|
||||
* @see #start()
|
||||
* @see #stop()
|
||||
*/
|
||||
public static final String LIFECYCLE_PROCESSOR_BEAN_NAME = "lifecycleProcessor";
|
||||
|
||||
/**
|
||||
* The name of the {@link MessageSource} bean in the context.
|
||||
* If none is supplied, message resolution is delegated to the parent.
|
||||
|
|
@ -168,6 +157,17 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
|||
*/
|
||||
public static final String APPLICATION_EVENT_MULTICASTER_BEAN_NAME = "applicationEventMulticaster";
|
||||
|
||||
/**
|
||||
* The name of the {@link LifecycleProcessor} bean in the context.
|
||||
* If none is supplied, a {@link DefaultLifecycleProcessor} is used.
|
||||
* @since 3.0
|
||||
* @see org.springframework.context.LifecycleProcessor
|
||||
* @see org.springframework.context.support.DefaultLifecycleProcessor
|
||||
* @see #start()
|
||||
* @see #stop()
|
||||
*/
|
||||
public static final String LIFECYCLE_PROCESSOR_BEAN_NAME = "lifecycleProcessor";
|
||||
|
||||
|
||||
static {
|
||||
// Eagerly load the ContextClosedEvent class to avoid weird classloader issues
|
||||
|
|
@ -806,8 +806,9 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
|||
}
|
||||
|
||||
/**
|
||||
* Initialize the MessageSource.
|
||||
* Use parent's if none defined in this context.
|
||||
* Initialize the {@link MessageSource}.
|
||||
* <p>Uses parent's {@code MessageSource} if none defined in this context.
|
||||
* @see #MESSAGE_SOURCE_BEAN_NAME
|
||||
*/
|
||||
protected void initMessageSource() {
|
||||
ConfigurableListableBeanFactory beanFactory = getBeanFactory();
|
||||
|
|
@ -837,8 +838,9 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
|||
}
|
||||
|
||||
/**
|
||||
* Initialize the ApplicationEventMulticaster.
|
||||
* Uses SimpleApplicationEventMulticaster if none defined in the context.
|
||||
* Initialize the {@link ApplicationEventMulticaster}.
|
||||
* <p>Uses {@link SimpleApplicationEventMulticaster} if none defined in the context.
|
||||
* @see #APPLICATION_EVENT_MULTICASTER_BEAN_NAME
|
||||
* @see org.springframework.context.event.SimpleApplicationEventMulticaster
|
||||
*/
|
||||
protected void initApplicationEventMulticaster() {
|
||||
|
|
@ -861,15 +863,16 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
|||
}
|
||||
|
||||
/**
|
||||
* Initialize the LifecycleProcessor.
|
||||
* Uses DefaultLifecycleProcessor if none defined in the context.
|
||||
* Initialize the {@link LifecycleProcessor}.
|
||||
* <p>Uses {@link DefaultLifecycleProcessor} if none defined in the context.
|
||||
* @since 3.0
|
||||
* @see #LIFECYCLE_PROCESSOR_BEAN_NAME
|
||||
* @see org.springframework.context.support.DefaultLifecycleProcessor
|
||||
*/
|
||||
protected void initLifecycleProcessor() {
|
||||
ConfigurableListableBeanFactory beanFactory = getBeanFactory();
|
||||
if (beanFactory.containsLocalBean(LIFECYCLE_PROCESSOR_BEAN_NAME)) {
|
||||
this.lifecycleProcessor =
|
||||
beanFactory.getBean(LIFECYCLE_PROCESSOR_BEAN_NAME, LifecycleProcessor.class);
|
||||
this.lifecycleProcessor = beanFactory.getBean(LIFECYCLE_PROCESSOR_BEAN_NAME, LifecycleProcessor.class);
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Using LifecycleProcessor [" + this.lifecycleProcessor + "]");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -276,8 +276,9 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage
|
|||
* @see jakarta.persistence.spi.PersistenceUnitInfo#getNonJtaDataSource()
|
||||
* @see #setPersistenceUnitManager
|
||||
*/
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.internalPersistenceUnitManager.setDataSourceLookup(new SingleDataSourceLookup(dataSource));
|
||||
public void setDataSource(@Nullable DataSource dataSource) {
|
||||
this.internalPersistenceUnitManager.setDataSourceLookup(
|
||||
dataSource != null ? new SingleDataSourceLookup(dataSource) : null);
|
||||
this.internalPersistenceUnitManager.setDefaultDataSource(dataSource);
|
||||
}
|
||||
|
||||
|
|
@ -293,8 +294,9 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage
|
|||
* @see jakarta.persistence.spi.PersistenceUnitInfo#getJtaDataSource()
|
||||
* @see #setPersistenceUnitManager
|
||||
*/
|
||||
public void setJtaDataSource(DataSource jtaDataSource) {
|
||||
this.internalPersistenceUnitManager.setDataSourceLookup(new SingleDataSourceLookup(jtaDataSource));
|
||||
public void setJtaDataSource(@Nullable DataSource jtaDataSource) {
|
||||
this.internalPersistenceUnitManager.setDataSourceLookup(
|
||||
jtaDataSource != null ? new SingleDataSourceLookup(jtaDataSource) : null);
|
||||
this.internalPersistenceUnitManager.setDefaultJtaDataSource(jtaDataSource);
|
||||
}
|
||||
|
||||
|
|
@ -439,6 +441,7 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage
|
|||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public DataSource getDataSource() {
|
||||
if (this.persistenceUnitInfo != null) {
|
||||
return (this.persistenceUnitInfo.getJtaDataSource() != null ?
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
|
|
@ -28,28 +28,18 @@ import jakarta.persistence.spi.PersistenceProvider;
|
|||
* shared JPA EntityManagerFactory in a Spring application context; the
|
||||
* EntityManagerFactory can then be passed to JPA-based DAOs via
|
||||
* dependency injection. Note that switching to a JNDI lookup or to a
|
||||
* {@link LocalContainerEntityManagerFactoryBean}
|
||||
* definition is just a matter of configuration!
|
||||
* {@link LocalContainerEntityManagerFactoryBean} definition based on the
|
||||
* JPA container contract is just a matter of configuration!
|
||||
*
|
||||
* <p>Configuration settings are usually read from a {@code META-INF/persistence.xml}
|
||||
* config file, residing in the class path, according to the JPA standalone bootstrap
|
||||
* contract. Additionally, most JPA providers will require a special VM agent
|
||||
* (specified on JVM startup) that allows them to instrument application classes.
|
||||
* See the Java Persistence API specification and your provider documentation
|
||||
* for setup details.
|
||||
*
|
||||
* <p>This EntityManagerFactory bootstrap is appropriate for standalone applications
|
||||
* which solely use JPA for data access. If you want to set up your persistence
|
||||
* provider for an external DataSource and/or for global transactions which span
|
||||
* multiple resources, you will need to either deploy it into a full Jakarta EE
|
||||
* application server and access the deployed EntityManagerFactory via JNDI,
|
||||
* or use Spring's {@link LocalContainerEntityManagerFactoryBean} with appropriate
|
||||
* configuration for local setup according to JPA's container contract.
|
||||
* contract. See the Java Persistence API specification and your persistence provider
|
||||
* documentation for setup details. Additionally, JPA properties can also be added
|
||||
* on this FactoryBean via {@link #setJpaProperties}/{@link #setJpaPropertyMap}.
|
||||
*
|
||||
* <p><b>Note:</b> This FactoryBean has limited configuration power in terms of
|
||||
* what configuration it is able to pass to the JPA provider. If you need more
|
||||
* flexible configuration, for example passing a Spring-managed JDBC DataSource
|
||||
* to the JPA provider, consider using Spring's more powerful
|
||||
* the configuration that it is able to pass to the JPA provider. If you need
|
||||
* more flexible configuration options, consider using Spring's more powerful
|
||||
* {@link LocalContainerEntityManagerFactoryBean} instead.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
|
|
@ -775,7 +775,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
|
|||
|
||||
@Override
|
||||
public void setStatus(int status) {
|
||||
if (!this.isCommitted()) {
|
||||
if (!isCommitted()) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
|
|
@ -775,7 +775,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
|
|||
|
||||
@Override
|
||||
public void setStatus(int status) {
|
||||
if (!this.isCommitted()) {
|
||||
if (!isCommitted()) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
|
@ -785,6 +785,9 @@ public class MockHttpServletResponse implements HttpServletResponse {
|
|||
return this.status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the error message used when calling {@link HttpServletResponse#sendError(int, String)}.
|
||||
*/
|
||||
@Nullable
|
||||
public String getErrorMessage() {
|
||||
return this.errorMessage;
|
||||
|
|
|
|||
Loading…
Reference in New Issue