Skip to content

Commit

Permalink
Fix tests catching nested exceptions
Browse files Browse the repository at this point in the history
These tests started failing after an upstream
change in Spring Framework [1].

[1]: spring-projects/spring-framework#25162
  • Loading branch information
hpoettker authored and fmbenhassine committed Jul 15, 2022
1 parent 12bd08d commit 451db9a
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 29 deletions.
Expand Up @@ -24,7 +24,6 @@
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;
Expand All @@ -36,6 +35,7 @@
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;
Expand Down Expand Up @@ -110,7 +110,6 @@ public void testJobScopeWithProxyTargetClassInjected() throws Exception {
assertEquals("JOB", value.call());
}

@Ignore // FIXME git bissect and check when this started to fail
@Test
public void testIntentionallyBlowUpOnMissingContextWithProxyTargetClass() throws Exception {
init(JobScopeConfigurationRequiringProxyTargetClass.class);
Expand All @@ -119,10 +118,11 @@ public void testIntentionallyBlowUpOnMissingContextWithProxyTargetClass() throws
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);
Expand All @@ -131,7 +131,9 @@ public void testIntentionallyBlowupWithForcedInterface() throws Exception {
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
Expand All @@ -142,7 +144,6 @@ public void testJobScopeWithDefaults() throws Exception {
assertEquals("JOB", value.call());
}

@Ignore // FIXME git bissect and check when this started to fail
@Test
public void testIntentionallyBlowUpOnMissingContextWithInterface() throws Exception {
init(JobScopeConfigurationWithDefaults.class);
Expand All @@ -152,7 +153,9 @@ public void testIntentionallyBlowUpOnMissingContextWithInterface() throws Except
Callable<String> 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 {
Expand Down
Expand Up @@ -19,7 +19,6 @@
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;
Expand All @@ -29,6 +28,7 @@
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;
Expand Down Expand Up @@ -108,7 +108,6 @@ public void testStepScopeWithProxyTargetClassInjected() throws Exception {
assertEquals("STEP", value.call());
}

@Ignore // FIXME git bissect and check when this started to fail
@Test
public void testIntentionallyBlowUpOnMissingContextWithProxyTargetClass() throws Exception {
init(StepScopeConfigurationRequiringProxyTargetClass.class);
Expand All @@ -118,10 +117,11 @@ public void testIntentionallyBlowUpOnMissingContextWithProxyTargetClass() throws
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);
Expand All @@ -130,7 +130,9 @@ public void testIntentionallyBlowupWithForcedInterface() throws Exception {
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
Expand All @@ -141,7 +143,6 @@ public void testStepScopeWithDefaults() throws Exception {
assertEquals("STEP", value.call());
}

@Ignore // FIXME git bissect and check when this started to fail
@Test
public void testIntentionallyBlowUpOnMissingContextWithInterface() throws Exception {
init(StepScopeConfigurationWithDefaults.class);
Expand All @@ -152,7 +153,9 @@ public void testIntentionallyBlowUpOnMissingContextWithInterface() throws Except
Callable<String> 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 {
Expand Down
Expand Up @@ -20,7 +20,6 @@
import java.util.Collection;
import java.util.Map;

import org.junit.Ignore;
import org.junit.Test;

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

@Test
@Ignore // FIXME git bissect and check when this started to fail
public void testProcessorNonTransactionalNotAllowedWithTransactionalReader() throws Exception {
try {
new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/ChunkElementIllegalTransactionalAttributeParserTests-context.xml");
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"));
}
Expand Down
Expand Up @@ -18,7 +18,6 @@
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;
Expand Down Expand Up @@ -52,15 +51,14 @@ public void testUnreachableStepInFlow() {
}

@Test
@Ignore // FIXME git bissect and check when this started to fail
public void testNextOutOfScope() {
try {
new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/JobParserNextOutOfScopeTests-context.xml");
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\\]\\]"));
}
Expand Down
Expand Up @@ -26,7 +26,6 @@
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;
Expand Down Expand Up @@ -589,7 +588,6 @@ public void write(List<? extends String> item) throws Exception {

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

// Very specific skippable exception
Expand Down Expand Up @@ -624,8 +622,8 @@ public void write(List<? extends String> item) throws Exception {
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<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray(""));
assertEquals(expectedOutput, written);
Expand Down
@@ -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.
Expand Down Expand Up @@ -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);
Expand Down
@@ -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.
Expand Down Expand Up @@ -91,7 +91,7 @@ public void testNoReply() {
fail();
}
catch (MessagingException e) {
String message = e.getMessage();
String message = e.getCause().getMessage();
assertTrue("Wrong message: " + message, message.contains("replyChannel"));
}
Message<JobExecution> executionMessage = (Message<JobExecution>) responseChannel.receive(1000);
Expand Down
@@ -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;
Expand Down Expand Up @@ -57,7 +72,7 @@ public void testNoReply() {
requestChannel.send(trigger);
}
catch (MessagingException e) {
String message = e.getMessage();
String message = e.getCause().getMessage();
assertTrue("Wrong message: " + message, message.contains("replyChannel"));
}
Message<JobExecution> executionMessage = (Message<JobExecution>) responseChannel.receive(1000);
Expand Down

0 comments on commit 451db9a

Please sign in to comment.