-1

I'm running a very simple and lightweight test suite with Maven, using MockMvc to test my controllers. I have basic authentication configured, and everything works perfectly.

However, as soon as I put the annotation @EnableBatchProcessing to one of my classes, the tests all fail with a 401 Unauthorized. Just one simple annotation and everything breaks.

Why would a batch processing annotation affect testing in such a way?

Kayaman
  • 72,141
  • 5
  • 83
  • 121
  • 1
    Turn up your debug logs. My suspicion is that Spring Security is getting activated. – chrylis -cautiouslyoptimistic- Dec 05 '14 at 11:55
  • @chrylis You're right, I was a bit hasty posting a question here. Turns out there was a problem with the batch transactionmanager messing up with the JPATransactionManager, so authentication failed when trying to read the database. – Kayaman Dec 05 '14 at 13:05
  • 1
    Possible duplicate of [Could not open JPA EntityManager for transaction; nested exception is java.lang.IllegalStateException](https://stackoverflow.com/questions/20907206/could-not-open-jpa-entitymanager-for-transaction-nested-exception-is-java-lang) – dlamblin Jul 10 '18 at 10:53

1 Answers1

2

Turns out the Spring Batch config was off. The problem was essentially the same as here.

I wanted to use an in-memory map for the batch details, but even though it worked, it wreaked havoc when running the tests.

When I worked the configuration down to the following, the tests worked perfectly.

@Configuration
@EnableBatchProcessing
public class ExcelBatchConfig extends DefaultBatchConfigurer {

    /**
     * If we don't provide a datasource, an in-memory map will be used.
     */
    @Override
    @Autowired
    public void setDataSource(DataSource dataSource) {
    }
}
Community
  • 1
  • 1
Kayaman
  • 72,141
  • 5
  • 83
  • 121