From 451db9a968f440665c592ff8df1b1dc1b4cd6a1f Mon Sep 17 00:00:00 2001 From: Henning Poettker Date: Wed, 22 Jun 2022 12:06:20 +0200 Subject: [PATCH] Fix tests catching nested exceptions These tests started failing after an upstream change in Spring Framework [1]. [1]: https://github.com/spring-projects/spring-framework/issues/25162 --- .../annotation/JobScopeConfigurationTests.java | 17 ++++++++++------- .../annotation/StepScopeConfigurationTests.java | 17 ++++++++++------- .../xml/ChunkElementParserTests.java | 4 +--- .../xml/JobParserExceptionTests.java | 4 +--- .../FaultTolerantStepFactoryBeanRetryTests.java | 6 ++---- .../ChunkMessageItemWriterIntegrationTests.java | 4 ++-- .../JobLaunchingGatewayIntegrationTests.java | 4 ++-- ...LaunchingMessageHandlerIntegrationTests.java | 17 ++++++++++++++++- 8 files changed, 44 insertions(+), 29 deletions(-) diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTests.java index e63c250e0..8f635ed76 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTests.java @@ -24,7 +24,6 @@ import java.util.concurrent.Callable; import org.junit.After; import org.junit.Assert; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.springframework.batch.core.JobExecution; @@ -36,6 +35,7 @@ import org.springframework.batch.core.step.tasklet.Tasklet; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.support.ScopeNotActiveException; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -110,7 +110,6 @@ public class JobScopeConfigurationTests { assertEquals("JOB", value.call()); } - @Ignore // FIXME git bissect and check when this started to fail @Test public void testIntentionallyBlowUpOnMissingContextWithProxyTargetClass() throws Exception { init(JobScopeConfigurationRequiringProxyTargetClass.class); @@ -119,10 +118,11 @@ public class JobScopeConfigurationTests { SimpleHolder value = context.getBean(SimpleHolder.class); assertEquals("JOB", value.call()); }); - assertTrue(expectedException.getMessage().contains("job scope")); + assertTrue(expectedException instanceof ScopeNotActiveException); + String message = expectedException.getCause().getMessage(); + assertTrue(message.contains("job scope")); } - @Ignore // FIXME git bissect and check when this started to fail @Test public void testIntentionallyBlowupWithForcedInterface() throws Exception { init(JobScopeConfigurationForcingInterfaceProxy.class); @@ -131,7 +131,9 @@ public class JobScopeConfigurationTests { SimpleHolder value = context.getBean(SimpleHolder.class); assertEquals("JOB", value.call()); }); - assertTrue(expectedException.getMessage().contains("job scope")); + assertTrue(expectedException instanceof ScopeNotActiveException); + String message = expectedException.getCause().getMessage(); + assertTrue(message.contains("job scope")); } @Test @@ -142,7 +144,6 @@ public class JobScopeConfigurationTests { assertEquals("JOB", value.call()); } - @Ignore // FIXME git bissect and check when this started to fail @Test public void testIntentionallyBlowUpOnMissingContextWithInterface() throws Exception { init(JobScopeConfigurationWithDefaults.class); @@ -152,7 +153,9 @@ public class JobScopeConfigurationTests { Callable value = context.getBean(Callable.class); assertEquals("JOB", value.call()); }); - assertTrue(expectedException.getMessage().contains("job scope")); + assertTrue(expectedException instanceof ScopeNotActiveException); + String message = expectedException.getCause().getMessage(); + assertTrue(message.contains("job scope")); } public void init(Class... config) throws Exception { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/StepScopeConfigurationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/StepScopeConfigurationTests.java index bb5480147..4eb5cfd2f 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/StepScopeConfigurationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/StepScopeConfigurationTests.java @@ -19,7 +19,6 @@ package org.springframework.batch.core.configuration.annotation; import org.junit.After; import org.junit.Assert; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.StepExecution; @@ -29,6 +28,7 @@ import org.springframework.batch.core.step.tasklet.Tasklet; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.support.ScopeNotActiveException; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -108,7 +108,6 @@ public class StepScopeConfigurationTests { assertEquals("STEP", value.call()); } - @Ignore // FIXME git bissect and check when this started to fail @Test public void testIntentionallyBlowUpOnMissingContextWithProxyTargetClass() throws Exception { init(StepScopeConfigurationRequiringProxyTargetClass.class); @@ -118,10 +117,11 @@ public class StepScopeConfigurationTests { SimpleHolder value = context.getBean(SimpleHolder.class); assertEquals("STEP", value.call()); }); - assertTrue(expectedException.getMessage().contains("step scope")); + assertTrue(expectedException instanceof ScopeNotActiveException); + String message = expectedException.getCause().getMessage(); + assertTrue(message.contains("step scope")); } - @Ignore // FIXME git bissect and check when this started to fail @Test public void testIntentionallyBlowupWithForcedInterface() throws Exception { init(StepScopeConfigurationForcingInterfaceProxy.class); @@ -130,7 +130,9 @@ public class StepScopeConfigurationTests { SimpleHolder value = context.getBean(SimpleHolder.class); assertEquals("STEP", value.call()); }); - assertTrue(expectedException.getMessage().contains("step scope")); + assertTrue(expectedException instanceof ScopeNotActiveException); + String message = expectedException.getCause().getMessage(); + assertTrue(message.contains("step scope")); } @Test @@ -141,7 +143,6 @@ public class StepScopeConfigurationTests { assertEquals("STEP", value.call()); } - @Ignore // FIXME git bissect and check when this started to fail @Test public void testIntentionallyBlowUpOnMissingContextWithInterface() throws Exception { init(StepScopeConfigurationWithDefaults.class); @@ -152,7 +153,9 @@ public class StepScopeConfigurationTests { Callable value = context.getBean(Callable.class); assertEquals("STEP", value.call()); }); - assertTrue(expectedException.getMessage().contains("step scope")); + assertTrue(expectedException instanceof ScopeNotActiveException); + String message = expectedException.getCause().getMessage(); + assertTrue(message.contains("step scope")); } public void init(Class... config) throws Exception { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ChunkElementParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ChunkElementParserTests.java index ed38007ef..0314a9504 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ChunkElementParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ChunkElementParserTests.java @@ -20,7 +20,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Map; -import org.junit.Ignore; import org.junit.Test; import org.springframework.batch.core.Step; @@ -175,7 +174,6 @@ public class ChunkElementParserTests { } @Test - @Ignore // FIXME git bissect and check when this started to fail public void testProcessorNonTransactionalNotAllowedWithTransactionalReader() throws Exception { try { new ClassPathXmlApplicationContext( @@ -183,7 +181,7 @@ public class ChunkElementParserTests { fail("Expected BeanCreationException"); } catch (BeanCreationException e) { - String msg = e.getMessage(); + String msg = e.getRootCause().getMessage(); assertTrue("Wrong message: " + msg, msg.contains("The field 'processor-transactional' cannot be false if 'reader-transactional")); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserExceptionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserExceptionTests.java index 2e480d821..14b0cde80 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserExceptionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserExceptionTests.java @@ -18,7 +18,6 @@ package org.springframework.batch.core.configuration.xml; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import org.junit.Ignore; import org.junit.Test; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanDefinitionStoreException; @@ -52,7 +51,6 @@ public class JobParserExceptionTests { } @Test - @Ignore // FIXME git bissect and check when this started to fail public void testNextOutOfScope() { try { new ClassPathXmlApplicationContext( @@ -60,7 +58,7 @@ public class JobParserExceptionTests { fail("Error expected"); } catch (BeanCreationException e) { - String message = e.getMessage(); + String message = e.getRootCause().getMessage(); assertTrue("Wrong message: " + message, message .matches(".*Missing state for \\[StateTransition: \\[state=.*s2, pattern=\\*, next=.*s3\\]\\]")); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRetryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRetryTests.java index d59742dd8..4759ae010 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRetryTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRetryTests.java @@ -26,7 +26,6 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.springframework.batch.core.BatchStatus; @@ -589,7 +588,6 @@ public class FaultTolerantStepFactoryBeanRetryTests { @SuppressWarnings("unchecked") @Test - @Ignore // FIXME git bissect and check when this started to fail public void testNonSkippableException() throws Exception { // Very specific skippable exception @@ -624,8 +622,8 @@ public class FaultTolerantStepFactoryBeanRetryTests { StepExecution stepExecution = new StepExecution(step.getName(), jobExecution); repository.add(stepExecution); step.execute(stepExecution); - String message = stepExecution.getFailureExceptions().get(0).getMessage(); - assertTrue("Wrong message: " + message, message.contains("Write error - planned but not skippable.")); + String message = stepExecution.getFailureExceptions().get(0).getCause().getMessage(); + assertEquals("Wrong message: " + message, "Write error - planned but not skippable.", message); List expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("")); assertEquals(expectedOutput, written); diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkMessageItemWriterIntegrationTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkMessageItemWriterIntegrationTests.java index 526cda85e..76e2b30fa 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkMessageItemWriterIntegrationTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkMessageItemWriterIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 the original author or authors. + * Copyright 2021-2022 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. @@ -79,7 +79,7 @@ public class ChunkMessageItemWriterIntegrationTests { @Before public void setUp() throws Exception { - EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder().generateUniqueName(true) .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") .addScript("/org/springframework/batch/core/schema-hsqldb.sql").build(); DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(embeddedDatabase); diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingGatewayIntegrationTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingGatewayIntegrationTests.java index 8104d87a2..41c150c5c 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingGatewayIntegrationTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingGatewayIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2022 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. @@ -91,7 +91,7 @@ public class JobLaunchingGatewayIntegrationTests { fail(); } catch (MessagingException e) { - String message = e.getMessage(); + String message = e.getCause().getMessage(); assertTrue("Wrong message: " + message, message.contains("replyChannel")); } Message executionMessage = (Message) responseChannel.receive(1000); diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingMessageHandlerIntegrationTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingMessageHandlerIntegrationTests.java index 10ea0ef64..a4e81842f 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingMessageHandlerIntegrationTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingMessageHandlerIntegrationTests.java @@ -1,3 +1,18 @@ +/* + * Copyright 2008-2022 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.batch.integration.launch; import static org.junit.Assert.assertNotNull; @@ -57,7 +72,7 @@ public class JobLaunchingMessageHandlerIntegrationTests { requestChannel.send(trigger); } catch (MessagingException e) { - String message = e.getMessage(); + String message = e.getCause().getMessage(); assertTrue("Wrong message: " + message, message.contains("replyChannel")); } Message executionMessage = (Message) responseChannel.receive(1000);