Skip to content

Commit 451db9a

Browse files
hpoettkerfmbenhassine
authored andcommitted
Fix tests catching nested exceptions
These tests started failing after an upstream change in Spring Framework [1]. [1]: spring-projects/spring-framework#25162
1 parent 12bd08d commit 451db9a

File tree

8 files changed

+44
-29
lines changed

8 files changed

+44
-29
lines changed

Diff for: spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTests.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.junit.After;
2525
import org.junit.Assert;
2626
import org.junit.Before;
27-
import org.junit.Ignore;
2827
import org.junit.Test;
2928

3029
import org.springframework.batch.core.JobExecution;
@@ -36,6 +35,7 @@
3635
import org.springframework.batch.repeat.RepeatStatus;
3736
import org.springframework.beans.factory.BeanCreationException;
3837
import org.springframework.beans.factory.annotation.Value;
38+
import org.springframework.beans.factory.support.ScopeNotActiveException;
3939
import org.springframework.context.ConfigurableApplicationContext;
4040
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
4141
import org.springframework.context.annotation.Bean;
@@ -110,7 +110,6 @@ public void testJobScopeWithProxyTargetClassInjected() throws Exception {
110110
assertEquals("JOB", value.call());
111111
}
112112

113-
@Ignore // FIXME git bissect and check when this started to fail
114113
@Test
115114
public void testIntentionallyBlowUpOnMissingContextWithProxyTargetClass() throws Exception {
116115
init(JobScopeConfigurationRequiringProxyTargetClass.class);
@@ -119,10 +118,11 @@ public void testIntentionallyBlowUpOnMissingContextWithProxyTargetClass() throws
119118
SimpleHolder value = context.getBean(SimpleHolder.class);
120119
assertEquals("JOB", value.call());
121120
});
122-
assertTrue(expectedException.getMessage().contains("job scope"));
121+
assertTrue(expectedException instanceof ScopeNotActiveException);
122+
String message = expectedException.getCause().getMessage();
123+
assertTrue(message.contains("job scope"));
123124
}
124125

125-
@Ignore // FIXME git bissect and check when this started to fail
126126
@Test
127127
public void testIntentionallyBlowupWithForcedInterface() throws Exception {
128128
init(JobScopeConfigurationForcingInterfaceProxy.class);
@@ -131,7 +131,9 @@ public void testIntentionallyBlowupWithForcedInterface() throws Exception {
131131
SimpleHolder value = context.getBean(SimpleHolder.class);
132132
assertEquals("JOB", value.call());
133133
});
134-
assertTrue(expectedException.getMessage().contains("job scope"));
134+
assertTrue(expectedException instanceof ScopeNotActiveException);
135+
String message = expectedException.getCause().getMessage();
136+
assertTrue(message.contains("job scope"));
135137
}
136138

137139
@Test
@@ -142,7 +144,6 @@ public void testJobScopeWithDefaults() throws Exception {
142144
assertEquals("JOB", value.call());
143145
}
144146

145-
@Ignore // FIXME git bissect and check when this started to fail
146147
@Test
147148
public void testIntentionallyBlowUpOnMissingContextWithInterface() throws Exception {
148149
init(JobScopeConfigurationWithDefaults.class);
@@ -152,7 +153,9 @@ public void testIntentionallyBlowUpOnMissingContextWithInterface() throws Except
152153
Callable<String> value = context.getBean(Callable.class);
153154
assertEquals("JOB", value.call());
154155
});
155-
assertTrue(expectedException.getMessage().contains("job scope"));
156+
assertTrue(expectedException instanceof ScopeNotActiveException);
157+
String message = expectedException.getCause().getMessage();
158+
assertTrue(message.contains("job scope"));
156159
}
157160

158161
public void init(Class<?>... config) throws Exception {

Diff for: spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/StepScopeConfigurationTests.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.junit.After;
2020
import org.junit.Assert;
2121
import org.junit.Before;
22-
import org.junit.Ignore;
2322
import org.junit.Test;
2423
import org.springframework.batch.core.StepContribution;
2524
import org.springframework.batch.core.StepExecution;
@@ -29,6 +28,7 @@
2928
import org.springframework.batch.repeat.RepeatStatus;
3029
import org.springframework.beans.factory.BeanCreationException;
3130
import org.springframework.beans.factory.annotation.Value;
31+
import org.springframework.beans.factory.support.ScopeNotActiveException;
3232
import org.springframework.context.ConfigurableApplicationContext;
3333
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
3434
import org.springframework.context.annotation.Bean;
@@ -108,7 +108,6 @@ public void testStepScopeWithProxyTargetClassInjected() throws Exception {
108108
assertEquals("STEP", value.call());
109109
}
110110

111-
@Ignore // FIXME git bissect and check when this started to fail
112111
@Test
113112
public void testIntentionallyBlowUpOnMissingContextWithProxyTargetClass() throws Exception {
114113
init(StepScopeConfigurationRequiringProxyTargetClass.class);
@@ -118,10 +117,11 @@ public void testIntentionallyBlowUpOnMissingContextWithProxyTargetClass() throws
118117
SimpleHolder value = context.getBean(SimpleHolder.class);
119118
assertEquals("STEP", value.call());
120119
});
121-
assertTrue(expectedException.getMessage().contains("step scope"));
120+
assertTrue(expectedException instanceof ScopeNotActiveException);
121+
String message = expectedException.getCause().getMessage();
122+
assertTrue(message.contains("step scope"));
122123
}
123124

124-
@Ignore // FIXME git bissect and check when this started to fail
125125
@Test
126126
public void testIntentionallyBlowupWithForcedInterface() throws Exception {
127127
init(StepScopeConfigurationForcingInterfaceProxy.class);
@@ -130,7 +130,9 @@ public void testIntentionallyBlowupWithForcedInterface() throws Exception {
130130
SimpleHolder value = context.getBean(SimpleHolder.class);
131131
assertEquals("STEP", value.call());
132132
});
133-
assertTrue(expectedException.getMessage().contains("step scope"));
133+
assertTrue(expectedException instanceof ScopeNotActiveException);
134+
String message = expectedException.getCause().getMessage();
135+
assertTrue(message.contains("step scope"));
134136
}
135137

136138
@Test
@@ -141,7 +143,6 @@ public void testStepScopeWithDefaults() throws Exception {
141143
assertEquals("STEP", value.call());
142144
}
143145

144-
@Ignore // FIXME git bissect and check when this started to fail
145146
@Test
146147
public void testIntentionallyBlowUpOnMissingContextWithInterface() throws Exception {
147148
init(StepScopeConfigurationWithDefaults.class);
@@ -152,7 +153,9 @@ public void testIntentionallyBlowUpOnMissingContextWithInterface() throws Except
152153
Callable<String> value = context.getBean(Callable.class);
153154
assertEquals("STEP", value.call());
154155
});
155-
assertTrue(expectedException.getMessage().contains("step scope"));
156+
assertTrue(expectedException instanceof ScopeNotActiveException);
157+
String message = expectedException.getCause().getMessage();
158+
assertTrue(message.contains("step scope"));
156159
}
157160

158161
public void init(Class<?>... config) throws Exception {

Diff for: spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ChunkElementParserTests.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.Collection;
2121
import java.util.Map;
2222

23-
import org.junit.Ignore;
2423
import org.junit.Test;
2524

2625
import org.springframework.batch.core.Step;
@@ -175,15 +174,14 @@ public void testProcessorTransactionalNotAllowedOnSimpleProcessor() throws Excep
175174
}
176175

177176
@Test
178-
@Ignore // FIXME git bissect and check when this started to fail
179177
public void testProcessorNonTransactionalNotAllowedWithTransactionalReader() throws Exception {
180178
try {
181179
new ClassPathXmlApplicationContext(
182180
"org/springframework/batch/core/configuration/xml/ChunkElementIllegalTransactionalAttributeParserTests-context.xml");
183181
fail("Expected BeanCreationException");
184182
}
185183
catch (BeanCreationException e) {
186-
String msg = e.getMessage();
184+
String msg = e.getRootCause().getMessage();
187185
assertTrue("Wrong message: " + msg,
188186
msg.contains("The field 'processor-transactional' cannot be false if 'reader-transactional"));
189187
}

Diff for: spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserExceptionTests.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import static org.junit.Assert.assertTrue;
1919
import static org.junit.Assert.fail;
2020

21-
import org.junit.Ignore;
2221
import org.junit.Test;
2322
import org.springframework.beans.factory.BeanCreationException;
2423
import org.springframework.beans.factory.BeanDefinitionStoreException;
@@ -52,15 +51,14 @@ public void testUnreachableStepInFlow() {
5251
}
5352

5453
@Test
55-
@Ignore // FIXME git bissect and check when this started to fail
5654
public void testNextOutOfScope() {
5755
try {
5856
new ClassPathXmlApplicationContext(
5957
"org/springframework/batch/core/configuration/xml/JobParserNextOutOfScopeTests-context.xml");
6058
fail("Error expected");
6159
}
6260
catch (BeanCreationException e) {
63-
String message = e.getMessage();
61+
String message = e.getRootCause().getMessage();
6462
assertTrue("Wrong message: " + message, message
6563
.matches(".*Missing state for \\[StateTransition: \\[state=.*s2, pattern=\\*, next=.*s3\\]\\]"));
6664
}

Diff for: spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRetryTests.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.apache.commons.logging.Log;
2727
import org.apache.commons.logging.LogFactory;
2828
import org.junit.Before;
29-
import org.junit.Ignore;
3029
import org.junit.Test;
3130

3231
import org.springframework.batch.core.BatchStatus;
@@ -589,7 +588,6 @@ public void write(List<? extends String> item) throws Exception {
589588

590589
@SuppressWarnings("unchecked")
591590
@Test
592-
@Ignore // FIXME git bissect and check when this started to fail
593591
public void testNonSkippableException() throws Exception {
594592

595593
// Very specific skippable exception
@@ -624,8 +622,8 @@ public void write(List<? extends String> item) throws Exception {
624622
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
625623
repository.add(stepExecution);
626624
step.execute(stepExecution);
627-
String message = stepExecution.getFailureExceptions().get(0).getMessage();
628-
assertTrue("Wrong message: " + message, message.contains("Write error - planned but not skippable."));
625+
String message = stepExecution.getFailureExceptions().get(0).getCause().getMessage();
626+
assertEquals("Wrong message: " + message, "Write error - planned but not skippable.", message);
629627

630628
List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray(""));
631629
assertEquals(expectedOutput, written);

Diff for: spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkMessageItemWriterIntegrationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 the original author or authors.
2+
* Copyright 2021-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -79,7 +79,7 @@ public class ChunkMessageItemWriterIntegrationTests {
7979

8080
@Before
8181
public void setUp() throws Exception {
82-
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
82+
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder().generateUniqueName(true)
8383
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
8484
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
8585
DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(embeddedDatabase);

Diff for: spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingGatewayIntegrationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -91,7 +91,7 @@ public void testNoReply() {
9191
fail();
9292
}
9393
catch (MessagingException e) {
94-
String message = e.getMessage();
94+
String message = e.getCause().getMessage();
9595
assertTrue("Wrong message: " + message, message.contains("replyChannel"));
9696
}
9797
Message<JobExecution> executionMessage = (Message<JobExecution>) responseChannel.receive(1000);

Diff for: spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingMessageHandlerIntegrationTests.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2008-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.springframework.batch.integration.launch;
217

318
import static org.junit.Assert.assertNotNull;
@@ -57,7 +72,7 @@ public void testNoReply() {
5772
requestChannel.send(trigger);
5873
}
5974
catch (MessagingException e) {
60-
String message = e.getMessage();
75+
String message = e.getCause().getMessage();
6176
assertTrue("Wrong message: " + message, message.contains("replyChannel"));
6277
}
6378
Message<JobExecution> executionMessage = (Message<JobExecution>) responseChannel.receive(1000);

0 commit comments

Comments
 (0)