diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/serviceloader/ServiceLoaderTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/serviceloader/ServiceLoaderTests.java index f54517c5d91..bdf544c6c55 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/serviceloader/ServiceLoaderTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/serviceloader/ServiceLoaderTests.java @@ -21,6 +21,7 @@ import java.util.ServiceLoader; import javax.xml.parsers.DocumentBuilderFactory; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.support.DefaultListableBeanFactory; @@ -33,12 +34,15 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue; * @author Juergen Hoeller * @author Chris Beams */ -public class ServiceLoaderTests { +class ServiceLoaderTests { + + @BeforeAll + static void assumeDocumentBuilderFactoryCanBeLoaded() { + assumeTrue(ServiceLoader.load(DocumentBuilderFactory.class).iterator().hasNext()); + } @Test - public void testServiceLoaderFactoryBean() { - assumeTrue(ServiceLoader.load(DocumentBuilderFactory.class).iterator().hasNext()); - + void testServiceLoaderFactoryBean() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); RootBeanDefinition bd = new RootBeanDefinition(ServiceLoaderFactoryBean.class); bd.getPropertyValues().add("serviceType", DocumentBuilderFactory.class.getName()); @@ -49,9 +53,7 @@ public class ServiceLoaderTests { } @Test - public void testServiceFactoryBean() { - assumeTrue(ServiceLoader.load(DocumentBuilderFactory.class).iterator().hasNext()); - + void testServiceFactoryBean() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); RootBeanDefinition bd = new RootBeanDefinition(ServiceFactoryBean.class); bd.getPropertyValues().add("serviceType", DocumentBuilderFactory.class.getName()); @@ -61,9 +63,7 @@ public class ServiceLoaderTests { } @Test - public void testServiceListFactoryBean() { - assumeTrue(ServiceLoader.load(DocumentBuilderFactory.class).iterator().hasNext()); - + void testServiceListFactoryBean() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); RootBeanDefinition bd = new RootBeanDefinition(ServiceListFactoryBean.class); bd.getPropertyValues().add("serviceType", DocumentBuilderFactory.class.getName()); diff --git a/spring-context/src/test/java/org/springframework/context/support/PropertyResourceConfigurerIntegrationTests.java b/spring-context/src/test/java/org/springframework/context/support/PropertyResourceConfigurerIntegrationTests.java index f876a6a7f6f..0cc659c5114 100644 --- a/spring-context/src/test/java/org/springframework/context/support/PropertyResourceConfigurerIntegrationTests.java +++ b/spring-context/src/test/java/org/springframework/context/support/PropertyResourceConfigurerIntegrationTests.java @@ -18,7 +18,6 @@ package org.springframework.context.support; import java.io.FileNotFoundException; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.beans.MutablePropertyValues; @@ -31,6 +30,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.tests.sample.beans.TestBean; import org.springframework.util.StringUtils; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** @@ -40,6 +40,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * as opposed to using only a BeanFactory during testing. * * @author Chris Beams + * @author Sam Brannen * @see org.springframework.beans.factory.config.PropertyResourceConfigurerTests */ public class PropertyResourceConfigurerIntegrationTests { @@ -54,8 +55,8 @@ public class PropertyResourceConfigurerIntegrationTests { pvs.add("location", "${user.dir}/test"); ac.registerSingleton("configurer", PropertyPlaceholderConfigurer.class, pvs); String userDir = getUserDir(); - assertThatExceptionOfType(BeanInitializationException.class).isThrownBy( - ac::refresh) + assertThatExceptionOfType(BeanInitializationException.class) + .isThrownBy(ac::refresh) .withCauseInstanceOf(FileNotFoundException.class) .withMessageContaining(userDir); } @@ -70,8 +71,8 @@ public class PropertyResourceConfigurerIntegrationTests { pvs.add("location", "${user.dir}/test/${user.dir}"); ac.registerSingleton("configurer", PropertyPlaceholderConfigurer.class, pvs); String userDir = getUserDir(); - assertThatExceptionOfType(BeanInitializationException.class).isThrownBy( - ac::refresh) + assertThatExceptionOfType(BeanInitializationException.class) + .isThrownBy(ac::refresh) .withCauseInstanceOf(FileNotFoundException.class) .matches(ex -> ex.getMessage().contains(userDir + "/test/" + userDir) || ex.getMessage().contains(userDir + "/test//" + userDir)); @@ -95,8 +96,8 @@ public class PropertyResourceConfigurerIntegrationTests { pvs = new MutablePropertyValues(); pvs.add("location", "${myprop}/test/${myprop}"); ac.registerSingleton("configurer", PropertyPlaceholderConfigurer.class, pvs); - assertThatExceptionOfType(BeanInitializationException.class).isThrownBy( - ac::refresh) + assertThatExceptionOfType(BeanInitializationException.class) + .isThrownBy(ac::refresh) .withMessageContaining("myprop"); } @@ -109,8 +110,7 @@ public class PropertyResourceConfigurerIntegrationTests { pvs = new MutablePropertyValues(); pvs.add("properties", "var=${m}var\nm=${var2}\nvar2=${var}"); ac.registerSingleton("configurer1", PropertyPlaceholderConfigurer.class, pvs); - assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy( - ac::refresh); + assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(ac::refresh); } @Test @@ -122,8 +122,7 @@ public class PropertyResourceConfigurerIntegrationTests { pvs = new MutablePropertyValues(); pvs.add("properties", "var=${m}var\nm=${var2}\nvar2=${m}"); ac.registerSingleton("configurer1", PropertyPlaceholderConfigurer.class, pvs); - assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy( - ac::refresh); + assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(ac::refresh); } @Test @@ -135,31 +134,35 @@ public class PropertyResourceConfigurerIntegrationTests { pvs = new MutablePropertyValues(); pvs.add("properties", "var=${m}var\nm=${var2}\nvar2=${m2}"); ac.registerSingleton("configurer1", PropertyPlaceholderConfigurer.class, pvs); - assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy( - ac::refresh); + assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(ac::refresh); } - @Disabled // this test was breaking after the 3.0 repackaging @Test - public void testPropertyPlaceholderConfigurerWithAutowireByType() { -// StaticApplicationContext ac = new StaticApplicationContext(); -// MutablePropertyValues pvs = new MutablePropertyValues(); -// pvs.addPropertyValue("touchy", "${test}"); -// ac.registerSingleton("tb", TestBean.class, pvs); -// pvs = new MutablePropertyValues(); -// pvs.addPropertyValue("target", new RuntimeBeanReference("tb")); -// // uncomment when fixing this test -// // ac.registerSingleton("tbProxy", org.springframework.aop.framework.ProxyFactoryBean.class, pvs); -// pvs = new MutablePropertyValues(); -// Properties props = new Properties(); -// props.put("test", "mytest"); -// pvs.addPropertyValue("properties", new Properties(props)); -// RootBeanDefinition ppcDef = new RootBeanDefinition(PropertyPlaceholderConfigurer.class, pvs); -// ppcDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE); -// ac.registerBeanDefinition("configurer", ppcDef); -// ac.refresh(); -// TestBean tb = (TestBean) ac.getBean("tb"); -// assertEquals("mytest", tb.getTouchy()); + public void testPropertyPlaceholderConfigurerWithValueFromSystemProperty() { + final String propertyName = getClass().getName() + ".test"; + + try { + System.setProperty(propertyName, "mytest"); + + StaticApplicationContext context = new StaticApplicationContext(); + + MutablePropertyValues pvs = new MutablePropertyValues(); + pvs.addPropertyValue("touchy", "${" + propertyName + "}"); + context.registerSingleton("tb", TestBean.class, pvs); + + pvs = new MutablePropertyValues(); + pvs.addPropertyValue("target", new RuntimeBeanReference("tb")); + context.registerSingleton("tbProxy", org.springframework.aop.framework.ProxyFactoryBean.class, pvs); + + context.registerSingleton("configurer", PropertyPlaceholderConfigurer.class); + context.refresh(); + + TestBean testBean = context.getBean("tb", TestBean.class); + assertThat(testBean.getTouchy()).isEqualTo("mytest"); + } + finally { + System.clearProperty(propertyName); + } } } diff --git a/spring-context/src/test/java/org/springframework/scheduling/concurrent/ScheduledExecutorFactoryBeanTests.java b/spring-context/src/test/java/org/springframework/scheduling/concurrent/ScheduledExecutorFactoryBeanTests.java index c305586f2f5..cb3099cccec 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/concurrent/ScheduledExecutorFactoryBeanTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/concurrent/ScheduledExecutorFactoryBeanTests.java @@ -20,7 +20,6 @@ import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ThreadFactory; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.core.task.NoOpRunnable; @@ -142,8 +141,8 @@ public class ScheduledExecutorFactoryBeanTests { verify(runnable, atLeast(2)).run(); } - @Disabled @Test + @EnabledForTestGroups(PERFORMANCE) public void testWithInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectly() throws Exception { Runnable runnable = mock(Runnable.class); @@ -162,8 +161,8 @@ public class ScheduledExecutorFactoryBeanTests { verify(runnable, never()).run(); } - @Disabled @Test + @EnabledForTestGroups(PERFORMANCE) public void testWithInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException() throws Exception { Runnable runnable = mock(Runnable.class); willThrow(new IllegalStateException()).given(runnable).run(); diff --git a/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java b/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java index f1949548d3c..b80e5803f1e 100644 --- a/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java @@ -27,13 +27,14 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.HashSet; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.springframework.tests.EnabledForTestGroups; import org.springframework.util.FileCopyUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.springframework.tests.TestGroup.CI; /** * Unit tests for various {@link Resource} implementations. @@ -218,10 +219,10 @@ class ResourceTests { assertThat(relative).isEqualTo(new UrlResource("file:dir/subdir")); } - @Disabled - @Test // this test is quite slow. TODO: re-enable with JUnit categories + @Test + @EnabledForTestGroups(CI) void testNonFileResourceExists() throws Exception { - Resource resource = new UrlResource("https://www.springframework.org"); + Resource resource = new UrlResource("https://spring.io/"); assertThat(resource.exists()).isTrue(); } diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/persistenceunit/PersistenceXmlParsingTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/persistenceunit/PersistenceXmlParsingTests.java index ba3b722259d..781027af228 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/persistenceunit/PersistenceXmlParsingTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/persistenceunit/PersistenceXmlParsingTests.java @@ -254,7 +254,7 @@ public class PersistenceXmlParsingTests { assertThat(info[0].excludeUnlistedClasses()).as("Exclude unlisted should default false in 1.0.").isFalse(); } - @Disabled // not doing schema parsing anymore for JPA 2.0 compatibility + @Disabled("not doing schema parsing anymore for JPA 2.0 compatibility") @Test public void testInvalidPersistence() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( @@ -264,7 +264,7 @@ public class PersistenceXmlParsingTests { reader.readPersistenceUnitInfos(resource)); } - @Disabled // not doing schema parsing anymore for JPA 2.0 compatibility + @Disabled("not doing schema parsing anymore for JPA 2.0 compatibility") @Test public void testNoSchemaPersistence() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java index c8371b37845..cee641e864c 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java @@ -31,7 +31,6 @@ import javax.persistence.PersistenceContextType; import javax.persistence.PersistenceProperty; import javax.persistence.PersistenceUnit; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.FactoryBean; @@ -337,7 +336,6 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT } @Test - @Disabled public void testPersistenceUnitsFromJndi() { EntityManager mockEm = mock(EntityManager.class); given(mockEmf.createEntityManager()).willReturn(mockEm); diff --git a/spring-web/src/test/java/org/springframework/web/util/UrlPathHelperTests.java b/spring-web/src/test/java/org/springframework/web/util/UrlPathHelperTests.java index e4809de72b2..11cac7f0cf0 100644 --- a/spring-web/src/test/java/org/springframework/web/util/UrlPathHelperTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/UrlPathHelperTests.java @@ -300,8 +300,9 @@ public class UrlPathHelperTests { assertThat(helper.getLookupPathForRequest(request)).isEqualTo("/"); } + @Disabled // test the root mapping for /foo/* w/o a trailing slash - //foo - @Test @Disabled + @Test public void tomcatCasualServletRootWithMissingSlash() throws Exception { request.setContextPath("/test"); request.setPathInfo(null); @@ -348,8 +349,8 @@ public class UrlPathHelperTests { tomcatCasualServletRoot(); } - // test the root mapping for /foo/* w/o a trailing slash - //foo @Disabled + // test the root mapping for /foo/* w/o a trailing slash - //foo @Test public void wasCasualServletRootWithMissingSlash() throws Exception { request.setContextPath("/test");