From 746ffab09dc9faf2253675870fde4a9ed95064ce Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Tue, 17 Oct 2023 11:02:24 +0200 Subject: [PATCH] Update samples - Restructure contexts - Remove unused resources - Remove irrelevant tests Issue #4329 --- spring-batch-samples/README.md | 106 +----- .../batch/samples/common/LogAdvice.java | 39 -- .../StepExecutionApplicationEventAdvice.java | 69 ---- .../config/DataSourceConfiguration.java | 71 ---- .../internal/FootballExceptionHandler.java | 40 -- .../retry/RetrySampleConfiguration.java | 39 +- .../src/main/resources/batch-hsql.properties | 23 -- .../src/main/resources/common-context.xml | 13 - .../main/resources/data-source-context.xml | 63 +-- .../src/main/resources/job-runner-context.xml | 11 - .../job/beanWrapperMapperSampleJob.xml | 4 +- .../common}/business-schema-hsqldb.sql | 0 .../job/compositeItemWriterSampleJob.xml | 5 +- .../samples/filter/job/customerFilterJob.xml | 6 +- .../samples/football/job/footballJob.xml | 22 +- .../samples/hibernate/CustomerCredit.hbm.xml | 17 - .../samples/jobstep/job/jobStepSample.xml | 5 +- .../batch/samples/mail/mailJob.xml | 1 - .../misc/jmx/adhoc-job-launcher-context.xml | 25 +- .../batch/samples/misc/jmx/adhocLoopJob.xml | 24 +- .../partition/jdbc/partitionJdbcJob.xml | 3 +- .../processindicator/job/parallelJob.xml | 22 +- .../job/staging-test-context.xml | 4 +- .../restart/fail/job/failRestartSample.xml | 5 +- .../job/skipSample-job-launcher-context.xml | 7 +- .../batch/samples/skip/job/skipSampleJob.xml | 5 +- .../batch/samples/trade/job/tradeJob.xml | 7 +- .../resources/simple-job-launcher-context.xml | 13 +- .../DelegatingJobFunctionalTests.java | 2 +- .../TaskletAdapterJobFunctionalTests.java | 2 +- .../samples/amqp/AmqpJobFunctionalTests.java | 2 +- ...WrapperMapperSampleJobFunctionalTests.java | 2 +- .../RemoteChunkingJobFunctionalTests.java | 15 +- .../common/ColumnRangePartitionerTests.java | 51 --- .../samples/common/CustomItemReaderTests.java | 122 ------ .../samples/common/CustomItemWriterTests.java | 63 --- ...ExceptionThrowingItemReaderProxyTests.java | 66 ---- .../common/OutputFileListenerTests.java | 61 --- .../common/StagingItemReaderTests.java | 144 ------- .../common/StagingItemWriterTests.java | 66 ---- ...positeItemWriterSampleFunctionalTests.java | 2 +- .../config/JobRunnerConfiguration.java | 40 -- .../AggregateItemFieldSetMapperTests.java | 63 --- .../multiline/AggregateItemReaderTests.java | 72 ---- .../domain/multiline/AggregateItemTests.java | 53 --- .../order/AddressFieldSetMapperTests.java | 70 ---- .../order/BillingFieldSetMapperTests.java | 52 --- .../order/CustomerFieldSetMapperTests.java | 71 ---- .../order/HeaderFieldSetMapperTests.java | 57 --- .../order/OrderItemFieldSetMapperTests.java | 77 ---- .../domain/order/OrderItemReaderTests.java | 123 ------ .../order/ShippingFieldSetMapperTests.java | 56 --- ...ositeCustomerUpdateLineTokenizerTests.java | 103 ----- .../trade/CustomerUpdateProcessorTests.java | 92 ----- .../samples/domain/trade/TradeTests.java | 37 -- .../CustomerCreditIncreaseProcessorTests.java | 49 --- .../CustomerCreditRowMapperTests.java | 57 --- ...ditUpdatePreparedStatementSetterTests.java | 57 --- .../CustomerCreditUpdateProcessorTests.java | 59 --- .../CustomerUpdateProcessorTests.java | 46 --- .../FlatFileCustomerCreditDaoTests.java | 78 ---- .../internal/GeneratingItemReaderTests.java | 51 --- .../trade/internal/JdbcTradeWriterTests.java | 81 ---- .../internal/TradeFieldSetMapperTests.java | 62 --- .../trade/internal/TradeProcessorTests.java | 49 --- .../trade/internal/TradeRowMapperTests.java | 64 ---- .../delimited/DelimitedFunctionalTests.java | 2 +- .../fixed/FixedLengthFunctionalTests.java | 2 +- .../multiline/MultiLineFunctionalTests.java | 2 +- .../MultilineAggregateJobFunctionalTests.java | 2 +- .../MultiRecordTypeFunctionalTests.java | 2 +- .../MultiResourceFunctionalTests.java | 2 +- .../PatternMatchingJobFunctionalTests.java | 2 +- .../validator/OrderValidatorTests.java | 359 ------------------ .../samples/file/xml/XmlFunctionalTests.java | 4 +- .../CustomerFilterJobFunctionalTests.java | 2 +- .../football/FootballJobFunctionalTests.java | 2 +- .../internal/JdbcGameDaoIntegrationTests.java | 120 ------ .../JdbcPlayerDaoIntegrationTests.java | 83 ---- .../JdbcPlayerSummaryDaoIntegrationTests.java | 85 ----- .../HeaderFooterSampleFunctionalTests.java | 2 +- .../jdbc/JdbcCursorFunctionalTests.java | 2 +- .../jdbc/JdbcPagingFunctionalTests.java | 2 +- .../jobstep/JobStepFunctionalTests.java | 2 +- .../batch/samples/jpa/JpaFunctionalTests.java | 10 +- .../jpa/RepositoryFunctionalTests.java | 11 +- .../loop/LoopFlowSampleFunctionalTests.java | 2 +- .../samples/mail/MailJobFunctionalTests.java | 4 +- .../misc/groovy/GroovyJobFunctionalTests.java | 2 +- ...obExecutionNotificationPublisherTests.java | 50 --- .../file/PartitionFileJobFunctionalTests.java | 2 +- .../jdbc/PartitionJdbcJobFunctionalTests.java | 2 +- .../RemotePartitioningJobFunctionalTests.java | 14 +- ...WithMessageAggregationFunctionalTests.java | 5 +- ...bWithRepositoryPollingFunctionalTests.java | 5 +- .../ProcessIndicatorJobFunctionalTests.java | 2 +- .../restart/fail/RestartFunctionalTests.java | 2 +- .../stop/GracefulShutdownFunctionalTests.java | 2 +- .../retry/RetrySampleConfigurationTests.java | 60 --- .../retry/RetrySampleFunctionalTests.java | 33 +- .../support/AbstractFieldSetMapperTests.java | 59 --- .../support/AbstractRowMapperTests.java | 69 ---- .../support/ItemTrackingItemWriterTests.java | 64 ---- .../support/RetrySampleItemWriterTests.java | 49 --- .../trade/TradeJobFunctionalTests.java | 4 +- 105 files changed, 209 insertions(+), 3785 deletions(-) delete mode 100644 spring-batch-samples/src/main/java/org/springframework/batch/samples/common/LogAdvice.java delete mode 100644 spring-batch-samples/src/main/java/org/springframework/batch/samples/common/StepExecutionApplicationEventAdvice.java delete mode 100644 spring-batch-samples/src/main/java/org/springframework/batch/samples/config/DataSourceConfiguration.java delete mode 100644 spring-batch-samples/src/main/java/org/springframework/batch/samples/football/internal/FootballExceptionHandler.java delete mode 100644 spring-batch-samples/src/main/resources/batch-hsql.properties delete mode 100644 spring-batch-samples/src/main/resources/common-context.xml delete mode 100644 spring-batch-samples/src/main/resources/job-runner-context.xml rename spring-batch-samples/src/main/resources/{ => org/springframework/batch/samples/common}/business-schema-hsqldb.sql (100%) delete mode 100644 spring-batch-samples/src/main/resources/org/springframework/batch/samples/hibernate/CustomerCredit.hbm.xml delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/common/ColumnRangePartitionerTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/common/CustomItemReaderTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/common/CustomItemWriterTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/common/ExceptionThrowingItemReaderProxyTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/common/OutputFileListenerTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/common/StagingItemReaderTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/common/StagingItemWriterTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/config/JobRunnerConfiguration.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/multiline/AggregateItemFieldSetMapperTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/multiline/AggregateItemReaderTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/multiline/AggregateItemTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/AddressFieldSetMapperTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/BillingFieldSetMapperTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/CustomerFieldSetMapperTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/HeaderFieldSetMapperTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/OrderItemFieldSetMapperTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/OrderItemReaderTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/ShippingFieldSetMapperTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/CompositeCustomerUpdateLineTokenizerTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/CustomerUpdateProcessorTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/TradeTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/CustomerCreditIncreaseProcessorTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/CustomerCreditRowMapperTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/CustomerCreditUpdatePreparedStatementSetterTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/CustomerCreditUpdateProcessorTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/CustomerUpdateProcessorTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/FlatFileCustomerCreditDaoTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/GeneratingItemReaderTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/JdbcTradeWriterTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/TradeFieldSetMapperTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/TradeProcessorTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/TradeRowMapperTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/file/patternmatching/internal/validator/OrderValidatorTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/football/internal/JdbcGameDaoIntegrationTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/football/internal/JdbcPlayerDaoIntegrationTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/football/internal/JdbcPlayerSummaryDaoIntegrationTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/misc/jmx/JobExecutionNotificationPublisherTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/retry/RetrySampleConfigurationTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/support/AbstractFieldSetMapperTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/support/AbstractRowMapperTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/support/ItemTrackingItemWriterTests.java delete mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/samples/support/RetrySampleItemWriterTests.java diff --git a/spring-batch-samples/README.md b/spring-batch-samples/README.md index 5859df8fa..1e0a4bf87 100644 --- a/spring-batch-samples/README.md +++ b/spring-batch-samples/README.md @@ -31,7 +31,6 @@ Here is a list of samples with checks to indicate which features each one demons | [Football Job](#football-job) | | | | | | | | | | | | | [Trade Job](#trade-job) | | | | | | X | | | | | | | [Header Footer Sample](#header-footer-sample) | | | | | | | | | | | | -| [Hibernate Sample](#hibernate-sample) | | X | | | | | | X | | | | | [Loop Flow Sample](#loop-flow-sample) | | | | | | | | | | | | | [Multiline Sample](#multiline-input-job) | | | | | | | X | | | | | | [Pattern matching Sample](#pattern-matching-sample) | | | | | | | X | | | | | @@ -53,7 +52,6 @@ The IO Sample Job has a number of special instances that show different IO featu |:--------------------------------------------------------------------|:---------------:|:------------------:|:---------:|:---------------:|:---------------:|:----------------:|:-------------------:|:----------:|:---------:|:--------------:|:----------:|:------------:| | [Delimited File Import Job](#delimited-file-import-job) | x | | | | | | | x | | | | | | [Fixed Length Import Job](#fixed-length-import-job) | | x | | | | | | | x | | | | -| [Hibernate Sample](#hibernate-sample) | | | | | x | | | | | | x | | | [Jdbc Readers and Writers Sample](#jdbc-readers-and-writers-sample) | | | | | x | | | | | | x | | | [JPA Readers and Writers sample](#jpa-readers-and-writers-sample) | | | | x | | | | | | | x | | | [Multiline Input Sample](#multiline-input-job) | x | | | | | | | x | | | x | | @@ -327,22 +325,6 @@ of the output file. [Header Footer Sample](src/main/java/org/springframework/batch/samples/headerfooter/README.md) -### Hibernate Sample - -The purpose of this sample is to show a typical usage of Hibernate -as an ORM tool in the input and output of a job. - -The job uses a `HibernateCursorItemReader` for the input, where -a simple HQL query is used to supply items. It also uses a -non-framework `ItemWriter` wrapping a DAO, which perhaps was -written as part of an online system. - -The output reliability and robustness are improved by the use of -`Session.flush()` inside `ItemWriter.write()`. This -"write-behind" behaviour is provided by Hibernate implicitly, but we -need to take control of it so that the skip and retry features -provided by Spring Batch can work effectively. - ### Stop Restart Sample This sample has a single step that is an infinite loop, reading and @@ -440,12 +422,14 @@ capabilities of Spring Batch. The retry is configured in the step through the `SkipLimitStepFactoryBean`: - - ... - - - +```xml + + ... + + + +``` Failed items will cause a rollback for all `Exception` types, up to a limit of 3 attempts. On the 4th attempt, the failed item would @@ -485,13 +469,15 @@ back on the validation exception, since we know that it didn't invalidate the transaction, only the item. This is done through the transaction attribute: - - - - - .... - +```xml + + + + + .... + +``` The format for the transaction attribute specification is given in the Spring Core documentation (e.g. see the Javadocs for @@ -563,62 +549,6 @@ during reading and processing can be found in `org.springframework.batch.samples.skip.SkippableExceptionDuringReadSample` and `org.springframework.batch.samples.skip.SkippableExceptionDuringProcessSample`. -### Tasklet Job - -The goal is to show the simplest use of the batch framework with a -single job with a single step, which cleans up a directory and runs -a system command. - -*Description:* The -`Job` itself is defined by the bean definition with -`id="taskletJob"`. In this example we have two steps. - -* The first step defines a tasklet that is responsible for -clearing out a directory though a custom `Tasklet`. Each -tasklet has an `execute()` method which is called by the -step. All processing of business data should be handled by this -method. -* The second step uses another tasklet to execute a system (OS) -command line. - -You can visualise the Spring configuration of a job through -Spring-IDE. See [Spring IDE](https://spring.io/tools). The -source view of the configuration is as follows: - - - - - - - - - - - - - - - - - - - - - - - - - - - - -For simplicity we are only displaying the job configuration itself -and leaving out the details of the supporting batch execution -environment configuration. - ### Batch metrics with Micrometer This sample shows how to use [Micrometer](https://micrometer.io) to collect batch metrics in Spring Batch. @@ -650,7 +580,7 @@ and import the ready-to-use dashboard in `spring-batch-samples/src/main/resource Finally, run the `org.springframework.batch.samples.metrics.BatchMetricsApplication` class without any argument to start the sample. -# MongoDB sample +### MongoDB sample This sample is a showcase of MongoDB support in Spring Batch. It copies data from an input collection to an output collection using `MongoItemReader` and `MongoItemWriter`. diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/samples/common/LogAdvice.java b/spring-batch-samples/src/main/java/org/springframework/batch/samples/common/LogAdvice.java deleted file mode 100644 index 46700bf07..000000000 --- a/spring-batch-samples/src/main/java/org/springframework/batch/samples/common/LogAdvice.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2006-2023 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.samples.common; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Wraps calls for 'Processing' methods which output a single Object to write the string - * representation of the object to the log. - * - * @author Lucas Ward - * @author Mahmoud Ben Hassine - */ -public class LogAdvice { - - private static final Log log = LogFactory.getLog(LogAdvice.class); - - public void doStronglyTypedLogging(Object item) { - if (log.isInfoEnabled()) { - log.info("Processed: " + item); - } - } - -} diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/samples/common/StepExecutionApplicationEventAdvice.java b/spring-batch-samples/src/main/java/org/springframework/batch/samples/common/StepExecutionApplicationEventAdvice.java deleted file mode 100644 index a23bc5155..000000000 --- a/spring-batch-samples/src/main/java/org/springframework/batch/samples/common/StepExecutionApplicationEventAdvice.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2006-2014 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.samples.common; - -import org.aspectj.lang.JoinPoint; -import org.springframework.batch.core.StepExecution; -import org.springframework.batch.samples.misc.jmx.SimpleMessageApplicationEvent; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.context.ApplicationEventPublisherAware; - -/** - * Wraps calls for methods taking {@link StepExecution} as an argument and publishes - * notifications in the form of {@link org.springframework.context.ApplicationEvent}. - * - * @author Dave Syer - */ -public class StepExecutionApplicationEventAdvice implements ApplicationEventPublisherAware { - - private ApplicationEventPublisher applicationEventPublisher; - - /* - * (non-Javadoc) - * - * @see org.springframework.context.ApplicationEventPublisherAware# - * setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) - */ - @Override - public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) { - this.applicationEventPublisher = applicationEventPublisher; - } - - public void before(JoinPoint jp, StepExecution stepExecution) { - String msg = "Before: " + jp.toShortString() + " with: " + stepExecution; - publish(jp.getTarget(), msg); - } - - public void after(JoinPoint jp, StepExecution stepExecution) { - String msg = "After: " + jp.toShortString() + " with: " + stepExecution; - publish(jp.getTarget(), msg); - } - - public void onError(JoinPoint jp, StepExecution stepExecution, Throwable t) { - String msg = "Error in: " + jp.toShortString() + " with: " + stepExecution + " (" + t.getClass() + ":" - + t.getMessage() + ")"; - publish(jp.getTarget(), msg); - } - - /* - * Publish a {@link SimpleMessageApplicationEvent} with the given parameters. - */ - private void publish(Object source, String message) { - applicationEventPublisher.publishEvent(new SimpleMessageApplicationEvent(source, message)); - } - -} diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/samples/config/DataSourceConfiguration.java b/spring-batch-samples/src/main/java/org/springframework/batch/samples/config/DataSourceConfiguration.java deleted file mode 100644 index 6c148080d..000000000 --- a/spring-batch-samples/src/main/java/org/springframework/batch/samples/config/DataSourceConfiguration.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2012-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.samples.config; - -import jakarta.annotation.PostConstruct; -import javax.sql.DataSource; - -import org.apache.commons.dbcp2.BasicDataSource; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; -import org.springframework.core.env.Environment; -import org.springframework.core.io.ResourceLoader; -import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils; -import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; -import org.springframework.jdbc.support.JdbcTransactionManager; - -/** - * @author Dave Syer - * @author Mahmoud Ben Hassine - * - */ -@Configuration -@PropertySource("classpath:/batch-hsql.properties") -public class DataSourceConfiguration { - - @Autowired - private Environment environment; - - @Autowired - private ResourceLoader resourceLoader; - - @PostConstruct - protected void initialize() { - ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); - populator.addScript(resourceLoader.getResource(environment.getProperty("batch.schema.script"))); - populator.setContinueOnError(true); - DatabasePopulatorUtils.execute(populator, dataSource()); - } - - @Bean(destroyMethod = "close") - public DataSource dataSource() { - BasicDataSource dataSource = new BasicDataSource(); - dataSource.setDriverClassName(environment.getProperty("batch.jdbc.driver")); - dataSource.setUrl(environment.getProperty("batch.jdbc.url")); - dataSource.setUsername(environment.getProperty("batch.jdbc.user")); - dataSource.setPassword(environment.getProperty("batch.jdbc.password")); - return dataSource; - } - - @Bean - public JdbcTransactionManager transactionManager(DataSource dataSource) { - return new JdbcTransactionManager(dataSource); - } - -} \ No newline at end of file diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/samples/football/internal/FootballExceptionHandler.java b/spring-batch-samples/src/main/java/org/springframework/batch/samples/football/internal/FootballExceptionHandler.java deleted file mode 100644 index 081b889fa..000000000 --- a/spring-batch-samples/src/main/java/org/springframework/batch/samples/football/internal/FootballExceptionHandler.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2006-2007 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.samples.football.internal; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.batch.repeat.RepeatContext; -import org.springframework.batch.repeat.exception.ExceptionHandler; - -public class FootballExceptionHandler implements ExceptionHandler { - - private static final Log logger = LogFactory.getLog(FootballExceptionHandler.class); - - @Override - public void handleException(RepeatContext context, Throwable throwable) throws Throwable { - - if (!(throwable instanceof NumberFormatException)) { - throw throwable; - } - else { - logger.error("Number Format Exception!", throwable); - } - - } - -} diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/samples/retry/RetrySampleConfiguration.java b/spring-batch-samples/src/main/java/org/springframework/batch/samples/retry/RetrySampleConfiguration.java index 8b1ad4968..b717fd9e2 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/samples/retry/RetrySampleConfiguration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/samples/retry/RetrySampleConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 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. @@ -15,21 +15,22 @@ */ package org.springframework.batch.samples.retry; +import javax.sql.DataSource; + import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.step.builder.StepBuilder; -import org.springframework.batch.item.ItemReader; -import org.springframework.batch.item.ItemWriter; import org.springframework.batch.samples.domain.trade.Trade; import org.springframework.batch.samples.domain.trade.internal.GeneratingTradeItemReader; import org.springframework.batch.samples.support.RetrySampleItemWriter; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; +import org.springframework.jdbc.support.JdbcTransactionManager; /** * @author Dave Syer @@ -40,17 +41,14 @@ import org.springframework.transaction.PlatformTransactionManager; @EnableBatchProcessing public class RetrySampleConfiguration { - @Autowired - private PlatformTransactionManager transactionManager; - @Bean - public Job retrySample(JobRepository jobRepository) { - return new JobBuilder("retrySample", jobRepository).start(step(jobRepository)).build(); + public Job retrySample(JobRepository jobRepository, Step step) { + return new JobBuilder("retrySample", jobRepository).start(step).build(); } @Bean - protected Step step(JobRepository jobRepository) { - return new StepBuilder("step", jobRepository).chunk(1, this.transactionManager) + protected Step step(JobRepository jobRepository, JdbcTransactionManager transactionManager) { + return new StepBuilder("step", jobRepository).chunk(1, transactionManager) .reader(reader()) .writer(writer()) .faultTolerant() @@ -60,15 +58,28 @@ public class RetrySampleConfiguration { } @Bean - protected ItemReader reader() { + protected GeneratingTradeItemReader reader() { GeneratingTradeItemReader reader = new GeneratingTradeItemReader(); reader.setLimit(10); return reader; } @Bean - protected ItemWriter writer() { + protected RetrySampleItemWriter writer() { return new RetrySampleItemWriter<>(); } + @Bean + public DataSource dataSource() { + return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL) + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .build(); + } + + @Bean + public JdbcTransactionManager transactionManager(DataSource dataSource) { + return new JdbcTransactionManager(dataSource); + } + } diff --git a/spring-batch-samples/src/main/resources/batch-hsql.properties b/spring-batch-samples/src/main/resources/batch-hsql.properties deleted file mode 100644 index 7b6e6846b..000000000 --- a/spring-batch-samples/src/main/resources/batch-hsql.properties +++ /dev/null @@ -1,23 +0,0 @@ -# Placeholders batch.* -# for HSQLDB: -batch.jdbc.driver=org.hsqldb.jdbcDriver -batch.jdbc.url=jdbc:hsqldb:mem:testdb;sql.enforce_strict_size=true;hsqldb.tx=mvcc -# use this one for a separate server process so you can inspect the results -# (or add it to system properties with -D to override at run time). -# batch.jdbc.url=jdbc:hsqldb:hsql://localhost:9005/samples -batch.jdbc.user=sa -batch.jdbc.password= -batch.jdbc.testWhileIdle=false -batch.jdbc.validationQuery= -batch.drop.script=classpath:/org/springframework/batch/core/schema-drop-hsqldb.sql -batch.schema.script=classpath:/org/springframework/batch/core/schema-hsqldb.sql -batch.business.schema.script=classpath:/business-schema-hsqldb.sql -batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer -batch.database.incrementer.parent=columnIncrementerParent -batch.lob.handler.class=org.springframework.jdbc.support.lob.DefaultLobHandler -batch.jdbc.pool.size=6 -batch.grid.size=6 -batch.verify.cursor.position=true -batch.isolationlevel=ISOLATION_SERIALIZABLE -batch.data.source.init=true -batch.table.prefix=BATCH_ diff --git a/spring-batch-samples/src/main/resources/common-context.xml b/spring-batch-samples/src/main/resources/common-context.xml deleted file mode 100644 index 7896ff2d5..000000000 --- a/spring-batch-samples/src/main/resources/common-context.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - diff --git a/spring-batch-samples/src/main/resources/data-source-context.xml b/spring-batch-samples/src/main/resources/data-source-context.xml index e2c546d91..39c1506bd 100644 --- a/spring-batch-samples/src/main/resources/data-source-context.xml +++ b/spring-batch-samples/src/main/resources/data-source-context.xml @@ -4,65 +4,26 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jdbc https://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> - - - - - - + + + + + - - - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - + diff --git a/spring-batch-samples/src/main/resources/job-runner-context.xml b/spring-batch-samples/src/main/resources/job-runner-context.xml deleted file mode 100644 index f93e9127d..000000000 --- a/spring-batch-samples/src/main/resources/job-runner-context.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - diff --git a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/beanwrapper/job/beanWrapperMapperSampleJob.xml b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/beanwrapper/job/beanWrapperMapperSampleJob.xml index 0f645886b..a42fb6663 100644 --- a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/beanwrapper/job/beanWrapperMapperSampleJob.xml +++ b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/beanwrapper/job/beanWrapperMapperSampleJob.xml @@ -64,7 +64,9 @@ - + + + diff --git a/spring-batch-samples/src/main/resources/business-schema-hsqldb.sql b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/common/business-schema-hsqldb.sql similarity index 100% rename from spring-batch-samples/src/main/resources/business-schema-hsqldb.sql rename to spring-batch-samples/src/main/resources/org/springframework/batch/samples/common/business-schema-hsqldb.sql diff --git a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/compositewriter/job/compositeItemWriterSampleJob.xml b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/compositewriter/job/compositeItemWriterSampleJob.xml index e82c4589b..78ead8d4e 100644 --- a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/compositewriter/job/compositeItemWriterSampleJob.xml +++ b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/compositewriter/job/compositeItemWriterSampleJob.xml @@ -65,10 +65,11 @@ - + + + - diff --git a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/filter/job/customerFilterJob.xml b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/filter/job/customerFilterJob.xml index d180077d2..fc1454148 100644 --- a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/filter/job/customerFilterJob.xml +++ b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/filter/job/customerFilterJob.xml @@ -66,8 +66,10 @@ class="org.springframework.batch.samples.domain.trade.internal.JdbcCustomerDao"> - - + + + + diff --git a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/football/job/footballJob.xml b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/football/job/footballJob.xml index 45a9565d2..9a2d7ccce 100644 --- a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/football/job/footballJob.xml +++ b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/football/job/footballJob.xml @@ -8,13 +8,13 @@ + commit-interval="2" /> + commit-interval="2" /> @@ -23,7 +23,7 @@ + commit-interval="2" /> @@ -44,7 +44,7 @@ - + @@ -60,7 +60,7 @@ - + @@ -90,18 +90,6 @@ GAMES.player_id group by GAMES.player_id, GAMES.year_no - - - - - games.file.name=games-small.csv - player.file.name=player-small1.csv - job.commit.interval=2 - - - - - \ No newline at end of file diff --git a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/hibernate/CustomerCredit.hbm.xml b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/hibernate/CustomerCredit.hbm.xml deleted file mode 100644 index c6f362f94..000000000 --- a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/hibernate/CustomerCredit.hbm.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/jobstep/job/jobStepSample.xml b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/jobstep/job/jobStepSample.xml index bbb6dd086..c60f2c0d2 100644 --- a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/jobstep/job/jobStepSample.xml +++ b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/jobstep/job/jobStepSample.xml @@ -56,10 +56,11 @@ - + + + - diff --git a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/mail/mailJob.xml b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/mail/mailJob.xml index fc28c457f..f9c4d53eb 100644 --- a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/mail/mailJob.xml +++ b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/mail/mailJob.xml @@ -24,7 +24,6 @@ - diff --git a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/misc/jmx/adhoc-job-launcher-context.xml b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/misc/jmx/adhoc-job-launcher-context.xml index da17b6e1b..efbc83b8d 100644 --- a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/misc/jmx/adhoc-job-launcher-context.xml +++ b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/misc/jmx/adhoc-job-launcher-context.xml @@ -1,9 +1,30 @@ - + + + + + + + + + + + + + + + @@ -31,7 +52,6 @@ - @@ -50,4 +70,5 @@ + \ No newline at end of file diff --git a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/misc/jmx/adhocLoopJob.xml b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/misc/jmx/adhocLoopJob.xml index ecdffdd29..df10b749d 100644 --- a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/misc/jmx/adhocLoopJob.xml +++ b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/misc/jmx/adhocLoopJob.xml @@ -1,14 +1,11 @@ + https://www.springframework.org/schema/batch/spring-batch.xsd"> @@ -27,17 +24,4 @@ - - - - - - - diff --git a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/partition/jdbc/partitionJdbcJob.xml b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/partition/jdbc/partitionJdbcJob.xml index 1556a2919..5c8e81a62 100644 --- a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/partition/jdbc/partitionJdbcJob.xml +++ b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/partition/jdbc/partitionJdbcJob.xml @@ -7,7 +7,7 @@ - + @@ -91,7 +91,6 @@ - diff --git a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/processindicator/job/parallelJob.xml b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/processindicator/job/parallelJob.xml index 04691f4fa..cc9795cdc 100644 --- a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/processindicator/job/parallelJob.xml +++ b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/processindicator/job/parallelJob.xml @@ -1,9 +1,7 @@ @@ -34,7 +32,9 @@ - + + + @@ -90,21 +90,15 @@ class="org.springframework.batch.samples.domain.trade.internal.JdbcTradeDao"> - + + + - - - - - - \ No newline at end of file diff --git a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/processindicator/job/staging-test-context.xml b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/processindicator/job/staging-test-context.xml index d69e162ae..7312c6cd0 100644 --- a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/processindicator/job/staging-test-context.xml +++ b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/processindicator/job/staging-test-context.xml @@ -6,7 +6,9 @@ - + + + diff --git a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/restart/fail/job/failRestartSample.xml b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/restart/fail/job/failRestartSample.xml index ddeb2eecd..9224e0b52 100644 --- a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/restart/fail/job/failRestartSample.xml +++ b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/restart/fail/job/failRestartSample.xml @@ -53,10 +53,11 @@ - + + + - diff --git a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/skip/job/skipSample-job-launcher-context.xml b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/skip/job/skipSample-job-launcher-context.xml index 04def7139..4b7850773 100644 --- a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/skip/job/skipSample-job-launcher-context.xml +++ b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/skip/job/skipSample-job-launcher-context.xml @@ -5,7 +5,6 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd"> - @@ -39,9 +38,9 @@ - - - + + + diff --git a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/skip/job/skipSampleJob.xml b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/skip/job/skipSampleJob.xml index e21f9e976..c9dd565d9 100644 --- a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/skip/job/skipSampleJob.xml +++ b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/skip/job/skipSampleJob.xml @@ -99,7 +99,9 @@ - + + + @@ -123,7 +125,6 @@ - diff --git a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/trade/job/tradeJob.xml b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/trade/job/tradeJob.xml index 7a0a2870e..46d27d8b3 100644 --- a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/trade/job/tradeJob.xml +++ b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/trade/job/tradeJob.xml @@ -6,8 +6,6 @@ xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd"> - - @@ -54,7 +52,6 @@ - @@ -68,7 +65,9 @@ - + + + diff --git a/spring-batch-samples/src/main/resources/simple-job-launcher-context.xml b/spring-batch-samples/src/main/resources/simple-job-launcher-context.xml index 86beb60e9..7e6600820 100644 --- a/spring-batch-samples/src/main/resources/simple-job-launcher-context.xml +++ b/spring-batch-samples/src/main/resources/simple-job-launcher-context.xml @@ -3,8 +3,9 @@ xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd"> + - + @@ -16,7 +17,6 @@ - - - + + - - - diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/adapter/readerwriter/DelegatingJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/adapter/readerwriter/DelegatingJobFunctionalTests.java index 670a6f5b5..592a3dcbe 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/adapter/readerwriter/DelegatingJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/adapter/readerwriter/DelegatingJobFunctionalTests.java @@ -26,7 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @SpringJUnitConfig(locations = { "/org/springframework/batch/samples/adapter/readerwriter/delegatingJob.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) + "/simple-job-launcher-context.xml" }) class DelegatingJobFunctionalTests { @Autowired diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/adapter/tasklet/TaskletAdapterJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/adapter/tasklet/TaskletAdapterJobFunctionalTests.java index 4a055ee29..c7916b064 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/adapter/tasklet/TaskletAdapterJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/adapter/tasklet/TaskletAdapterJobFunctionalTests.java @@ -28,7 +28,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.junit.jupiter.api.Assertions.assertEquals; @SpringJUnitConfig(locations = { "/org/springframework/batch/samples/adapter/tasklet/taskletJob.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) + "/simple-job-launcher-context.xml" }) class TaskletAdapterJobFunctionalTests { @Autowired diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/amqp/AmqpJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/amqp/AmqpJobFunctionalTests.java index 191c41a3f..c13603e20 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/amqp/AmqpJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/amqp/AmqpJobFunctionalTests.java @@ -60,7 +60,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext */ @SpringJUnitConfig(locations = { "/org/springframework/batch/samples/amqp/job/amqp-example-job.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) + "/simple-job-launcher-context.xml" }) @Testcontainers(disabledWithoutDocker = true) class AmqpJobFunctionalTests { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/beanwrapper/BeanWrapperMapperSampleJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/beanwrapper/BeanWrapperMapperSampleJobFunctionalTests.java index 8dd76d676..a2d0c4cdc 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/beanwrapper/BeanWrapperMapperSampleJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/beanwrapper/BeanWrapperMapperSampleJobFunctionalTests.java @@ -27,7 +27,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.junit.jupiter.api.Assertions.assertEquals; @SpringJUnitConfig(locations = { "/org/springframework/batch/samples/beanwrapper/job/beanWrapperMapperSampleJob.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) + "/simple-job-launcher-context.xml" }) class BeanWrapperMapperSampleJobFunctionalTests { @Autowired diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/chunking/RemoteChunkingJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/chunking/RemoteChunkingJobFunctionalTests.java index df19e90e3..07d5f93da 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/chunking/RemoteChunkingJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/chunking/RemoteChunkingJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 the original author or authors. + * Copyright 2018-2023 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. @@ -25,8 +25,8 @@ import org.junit.jupiter.api.Test; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; -import org.springframework.batch.samples.config.JobRunnerConfiguration; -import org.springframework.batch.test.JobLauncherTestUtils; +import org.springframework.batch.core.JobParameters; +import org.springframework.batch.core.launch.JobLauncher; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.PropertySource; @@ -43,12 +43,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; * @author Glenn Renfro */ -@SpringJUnitConfig(classes = { JobRunnerConfiguration.class, ManagerConfiguration.class }) +@SpringJUnitConfig(classes = { ManagerConfiguration.class }) @PropertySource("classpath:org/springframework/batch/samples/chunking/remote-chunking.properties") class RemoteChunkingJobFunctionalTests { @Autowired - private JobLauncherTestUtils jobLauncherTestUtils; + private JobLauncher jobLauncher; private EmbeddedActiveMQ brokerService; @@ -73,11 +73,8 @@ class RemoteChunkingJobFunctionalTests { @Test void testRemoteChunkingJob(@Autowired Job job) throws Exception { - // given - this.jobLauncherTestUtils.setJob(job); - // when - JobExecution jobExecution = this.jobLauncherTestUtils.launchJob(); + JobExecution jobExecution = this.jobLauncher.run(job, new JobParameters()); // then assertEquals(ExitStatus.COMPLETED.getExitCode(), jobExecution.getExitStatus().getExitCode()); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/common/ColumnRangePartitionerTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/common/ColumnRangePartitionerTests.java deleted file mode 100644 index ef99ec04a..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/common/ColumnRangePartitionerTests.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2009-2023 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.samples.common; - -import java.util.Map; - -import javax.sql.DataSource; - -import org.junit.jupiter.api.Test; - -import org.springframework.batch.item.ExecutionContext; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -@SpringJUnitConfig(locations = "classpath:data-source-context.xml") -class ColumnRangePartitionerTests { - - private DataSource dataSource; - - @Autowired - public void setDataSource(DataSource dataSource) { - this.dataSource = dataSource; - } - - private final ColumnRangePartitioner partitioner = new ColumnRangePartitioner(); - - @Test - void testPartition() { - partitioner.setDataSource(dataSource); - partitioner.setTable("CUSTOMER"); - partitioner.setColumn("ID"); - Map partition = partitioner.partition(2); - assertEquals(2, partition.size()); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/common/CustomItemReaderTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/common/CustomItemReaderTests.java deleted file mode 100644 index 014cea2c7..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/common/CustomItemReaderTests.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright 2006-2023 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.samples.common; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.batch.item.ExecutionContext; -import org.springframework.batch.item.ItemReader; -import org.springframework.batch.item.ItemStream; -import org.springframework.batch.item.ItemStreamException; -import org.springframework.lang.Nullable; - -import java.util.ArrayList; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -/** - * Unit test class that was used as part of the Reference Documentation. I'm only - * including it in the code to help keep the reference documentation up to date as the - * code base shifts. - * - * @author Lucas Ward - * @author Glenn Renfro - * @author Mahmoud Ben Hassine - * - */ -class CustomItemReaderTests { - - private ItemReader itemReader; - - @BeforeEach - void setUp() { - List items = new ArrayList<>(); - items.add("1"); - items.add("2"); - items.add("3"); - - itemReader = new CustomItemReader<>(items); - } - - @Test - void testRead() throws Exception { - assertEquals("1", itemReader.read()); - assertEquals("2", itemReader.read()); - assertEquals("3", itemReader.read()); - assertNull(itemReader.read()); - } - - @Test - void testRestart() throws Exception { - ExecutionContext executionContext = new ExecutionContext(); - ((ItemStream) itemReader).open(executionContext); - assertEquals("1", itemReader.read()); - ((ItemStream) itemReader).update(executionContext); - List items = new ArrayList<>(); - items.add("1"); - items.add("2"); - items.add("3"); - itemReader = new CustomItemReader<>(items); - - ((ItemStream) itemReader).open(executionContext); - assertEquals("2", itemReader.read()); - } - - static class CustomItemReader implements ItemReader, ItemStream { - - private static final String CURRENT_INDEX = "current.index"; - - private final List items; - - private int currentIndex = 0; - - public CustomItemReader(List items) { - this.items = items; - } - - @Nullable - @Override - public T read() throws Exception { - if (currentIndex < items.size()) { - return items.get(currentIndex++); - } - return null; - } - - @Override - public void open(ExecutionContext executionContext) throws ItemStreamException { - if (executionContext.containsKey(CURRENT_INDEX)) { - currentIndex = executionContext.getInt(CURRENT_INDEX); - } - else { - currentIndex = 0; - } - } - - @Override - public void close() throws ItemStreamException { - } - - @Override - public void update(ExecutionContext executionContext) throws ItemStreamException { - executionContext.putInt(CURRENT_INDEX, currentIndex); - } - - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/common/CustomItemWriterTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/common/CustomItemWriterTests.java deleted file mode 100644 index 39017fa12..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/common/CustomItemWriterTests.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2006-2023 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.samples.common; - -import org.junit.jupiter.api.Test; -import org.springframework.batch.item.Chunk; -import org.springframework.batch.item.ItemWriter; -import org.springframework.batch.support.transaction.TransactionAwareProxyFactory; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * Unit test class that was used as part of the Reference Documentation. I'm only - * including it in the code to help keep the reference documentation up to date as the - * code base shifts. - * - * @author Lucas Ward - * @author Mahmoud Ben Hassine - * @author Glenn Renfro - * - */ -class CustomItemWriterTests { - - @Test - void testFlush() throws Exception { - CustomItemWriter itemWriter = new CustomItemWriter<>(); - itemWriter.write(Chunk.of("1")); - assertEquals(1, itemWriter.getOutput().size()); - itemWriter.write(Chunk.of("2", "3")); - assertEquals(3, itemWriter.getOutput().size()); - } - - static class CustomItemWriter implements ItemWriter { - - private final List output = TransactionAwareProxyFactory.createTransactionalList(); - - @Override - public void write(Chunk chunk) throws Exception { - output.addAll(chunk.getItems()); - } - - public List getOutput() { - return output; - } - - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/common/ExceptionThrowingItemReaderProxyTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/common/ExceptionThrowingItemReaderProxyTests.java deleted file mode 100644 index 8efb41553..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/common/ExceptionThrowingItemReaderProxyTests.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.samples.common; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; -import org.springframework.batch.core.UnexpectedJobExecutionException; -import org.springframework.batch.item.support.ListItemReader; -import org.springframework.batch.repeat.context.RepeatContextSupport; -import org.springframework.batch.repeat.support.RepeatSynchronizationManager; -import org.springframework.batch.samples.support.ExceptionThrowingItemReaderProxy; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -class ExceptionThrowingItemReaderProxyTests { - - // expected call count before exception is thrown (exception should be thrown in next - // iteration) - private static final int ITER_COUNT = 5; - - @AfterEach - void tearDown() { - RepeatSynchronizationManager.clear(); - } - - @Test - void testProcess() throws Exception { - - // create module and set item processor and iteration count - ExceptionThrowingItemReaderProxy itemReader = new ExceptionThrowingItemReaderProxy<>(); - itemReader.setDelegate(new ListItemReader<>(List.of("a", "b", "c", "d", "e", "f"))); - itemReader.setThrowExceptionOnRecordNumber(ITER_COUNT + 1); - - RepeatSynchronizationManager.register(new RepeatContextSupport(null)); - - // call process method multiple times and verify whether exception is thrown when - // expected - for (int i = 0; i <= ITER_COUNT; i++) { - try { - itemReader.read(); - assertTrue(i < ITER_COUNT); - } - catch (UnexpectedJobExecutionException bce) { - assertEquals(ITER_COUNT, i); - } - } - - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/common/OutputFileListenerTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/common/OutputFileListenerTests.java deleted file mode 100644 index d66adbca3..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/common/OutputFileListenerTests.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2009-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.samples.common; - -import org.junit.jupiter.api.Test; - -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.StepExecution; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class OutputFileListenerTests { - - private final OutputFileListener listener = new OutputFileListener(); - - private final StepExecution stepExecution = new StepExecution("foo", new JobExecution(0L), 1L); - - @Test - void testCreateOutputNameFromInput() { - listener.createOutputNameFromInput(stepExecution); - assertEquals("{outputFile=file:./target/output/foo.csv}", stepExecution.getExecutionContext().toString()); - } - - @Test - void testSetPath() { - listener.setPath("spam/"); - listener.createOutputNameFromInput(stepExecution); - assertEquals("{outputFile=spam/foo.csv}", stepExecution.getExecutionContext().toString()); - } - - @Test - void testSetOutputKeyName() { - listener.setPath(""); - listener.setOutputKeyName("spam"); - listener.createOutputNameFromInput(stepExecution); - assertEquals("{spam=foo.csv}", stepExecution.getExecutionContext().toString()); - } - - @Test - void testSetInputKeyName() { - listener.setPath(""); - listener.setInputKeyName("spam"); - stepExecution.getExecutionContext().putString("spam", "bar"); - listener.createOutputNameFromInput(stepExecution); - assertEquals("bar.csv", stepExecution.getExecutionContext().getString("outputFile")); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/common/StagingItemReaderTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/common/StagingItemReaderTests.java deleted file mode 100644 index 11b253b24..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/common/StagingItemReaderTests.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright 2008-2023 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.samples.common; - -import javax.sql.DataSource; - -import org.junit.jupiter.api.Test; - -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.JobInstance; -import org.springframework.batch.core.JobParameters; -import org.springframework.batch.core.StepExecution; -import org.springframework.batch.item.Chunk; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -import org.springframework.test.context.transaction.AfterTransaction; -import org.springframework.test.context.transaction.BeforeTransaction; -import org.springframework.test.jdbc.JdbcTestUtils; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.TransactionDefinition; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.transaction.support.TransactionCallback; -import org.springframework.transaction.support.TransactionTemplate; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; - -@SpringJUnitConfig( - locations = "classpath:org/springframework/batch/samples/processindicator/job/staging-test-context.xml") -class StagingItemReaderTests { - - private JdbcTemplate jdbcTemplate; - - @Autowired - private PlatformTransactionManager transactionManager; - - @Autowired - private StagingItemWriter writer; - - @Autowired - private StagingItemReader reader; - - private final Long jobId = 113L; - - @Autowired - public void setDataSource(DataSource dataSource) { - this.jdbcTemplate = new JdbcTemplate(dataSource); - } - - @BeforeTransaction - void onSetUpBeforeTransaction() { - StepExecution stepExecution = new StepExecution("stepName", - new JobExecution(new JobInstance(jobId, "testJob"), new JobParameters())); - writer.beforeStep(stepExecution); - writer.write(Chunk.of("FOO", "BAR", "SPAM", "BUCKET")); - reader.beforeStep(stepExecution); - } - - @AfterTransaction - void onTearDownAfterTransaction() throws Exception { - reader.destroy(); - JdbcTestUtils.deleteFromTables(jdbcTemplate, "BATCH_STAGING"); - } - - @Transactional - @Test - void testReaderWithProcessorUpdatesProcessIndicator() throws Exception { - long id = jdbcTemplate.queryForObject("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?", Long.class, jobId); - String before = jdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?", String.class, id); - assertEquals(StagingItemWriter.NEW, before); - - ProcessIndicatorItemWrapper wrapper = reader.read(); - String item = wrapper.getItem(); - assertEquals("FOO", item); - - StagingItemProcessor updater = new StagingItemProcessor<>(); - updater.setJdbcTemplate(jdbcTemplate); - updater.process(wrapper); - - String after = jdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?", String.class, id); - assertEquals(StagingItemWriter.DONE, after); - } - - @Transactional - @Test - void testUpdateProcessIndicatorAfterCommit() { - TransactionTemplate txTemplate = new TransactionTemplate(transactionManager); - txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); - txTemplate.execute((TransactionCallback) transactionStatus -> { - try { - testReaderWithProcessorUpdatesProcessIndicator(); - } - catch (Exception e) { - fail("Unexpected Exception: " + e); - } - return null; - }); - long id = jdbcTemplate.queryForObject("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?", Long.class, jobId); - String before = jdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?", String.class, id); - assertEquals(StagingItemWriter.DONE, before); - } - - @Transactional - @Test - void testReaderRollsBackProcessIndicator() { - TransactionTemplate txTemplate = new TransactionTemplate(transactionManager); - txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); - - final Long idToUse = txTemplate.execute(transactionStatus -> { - - long id = jdbcTemplate.queryForObject("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?", Long.class, - jobId); - String before = jdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?", String.class, - id); - assertEquals(StagingItemWriter.NEW, before); - - ProcessIndicatorItemWrapper wrapper = reader.read(); - assertEquals("FOO", wrapper.getItem()); - - transactionStatus.setRollbackOnly(); - - return id; - }); - - String after = jdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?", String.class, - idToUse); - assertEquals(StagingItemWriter.NEW, after); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/common/StagingItemWriterTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/common/StagingItemWriterTests.java deleted file mode 100644 index 447a64e42..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/common/StagingItemWriterTests.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2006-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.samples.common; - -import javax.sql.DataSource; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.JobInstance; -import org.springframework.batch.core.JobParameters; -import org.springframework.batch.core.StepExecution; -import org.springframework.batch.item.Chunk; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -import org.springframework.test.jdbc.JdbcTestUtils; -import org.springframework.transaction.annotation.Transactional; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -@SpringJUnitConfig( - locations = "classpath:org/springframework/batch/samples/processindicator/job/staging-test-context.xml") -class StagingItemWriterTests { - - private JdbcTemplate jdbcTemplate; - - @Autowired - private StagingItemWriter writer; - - @Autowired - public void setDataSource(DataSource dataSource) { - this.jdbcTemplate = new JdbcTemplate(dataSource); - } - - @BeforeEach - void onSetUpBeforeTransaction() { - StepExecution stepExecution = new StepExecution("stepName", - new JobExecution(new JobInstance(12L, "testJob"), new JobParameters())); - writer.beforeStep(stepExecution); - } - - @Transactional - @Test - void testProcessInsertsNewItem() { - int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STAGING"); - writer.write(Chunk.of("FOO")); - int after = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STAGING"); - assertEquals(before + 1, after); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/compositewriter/CompositeItemWriterSampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/compositewriter/CompositeItemWriterSampleFunctionalTests.java index c8c1d5e67..5b909167d 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/compositewriter/CompositeItemWriterSampleFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/compositewriter/CompositeItemWriterSampleFunctionalTests.java @@ -40,7 +40,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @SpringJUnitConfig( locations = { "/org/springframework/batch/samples/compositewriter/job/compositeItemWriterSampleJob.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) + "/simple-job-launcher-context.xml" }) class CompositeItemWriterSampleFunctionalTests { private static final String GET_TRADES = "SELECT isin, quantity, price, customer FROM TRADE order by isin"; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/config/JobRunnerConfiguration.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/config/JobRunnerConfiguration.java deleted file mode 100644 index 57bc9460f..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/config/JobRunnerConfiguration.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2012-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.samples.config; - -import org.springframework.batch.core.launch.JobLauncher; -import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.test.JobLauncherTestUtils; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author Dave Syer - * @author Mahmoud Ben Hassine - * - */ -@Configuration -public class JobRunnerConfiguration { - - @Bean - public JobLauncherTestUtils utils(JobRepository jobRepository, JobLauncher jobLauncher) { - JobLauncherTestUtils jobLauncherTestUtils = new JobLauncherTestUtils(); - jobLauncherTestUtils.setJobRepository(jobRepository); - jobLauncherTestUtils.setJobLauncher(jobLauncher); - return jobLauncherTestUtils; - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/multiline/AggregateItemFieldSetMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/multiline/AggregateItemFieldSetMapperTests.java deleted file mode 100644 index e0fdec80e..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/multiline/AggregateItemFieldSetMapperTests.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2008-2023 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.samples.domain.multiline; - -import org.junit.jupiter.api.Test; -import org.springframework.batch.item.file.transform.DefaultFieldSet; -import org.springframework.batch.samples.file.multilineaggregate.AggregateItemFieldSetMapper; - -import static org.junit.jupiter.api.Assertions.*; - -class AggregateItemFieldSetMapperTests { - - private final AggregateItemFieldSetMapper mapper = new AggregateItemFieldSetMapper<>(); - - @Test - void testDefaultBeginRecord() throws Exception { - assertTrue(mapper.mapFieldSet(new DefaultFieldSet(new String[] { "BEGIN" })).isHeader()); - assertFalse(mapper.mapFieldSet(new DefaultFieldSet(new String[] { "BEGIN" })).isFooter()); - } - - @Test - void testSetBeginRecord() throws Exception { - mapper.setBegin("FOO"); - assertTrue(mapper.mapFieldSet(new DefaultFieldSet(new String[] { "FOO" })).isHeader()); - } - - @Test - void testDefaultEndRecord() throws Exception { - assertFalse(mapper.mapFieldSet(new DefaultFieldSet(new String[] { "END" })).isHeader()); - assertTrue(mapper.mapFieldSet(new DefaultFieldSet(new String[] { "END" })).isFooter()); - } - - @Test - void testSetEndRecord() throws Exception { - mapper.setEnd("FOO"); - assertTrue(mapper.mapFieldSet(new DefaultFieldSet(new String[] { "FOO" })).isFooter()); - } - - @Test - void testMandatoryProperties() { - assertThrows(IllegalStateException.class, mapper::afterPropertiesSet); - } - - @Test - void testDelegate() throws Exception { - mapper.setDelegate(fs -> "foo"); - assertEquals("foo", mapper.mapFieldSet(new DefaultFieldSet(new String[] { "FOO" })).getItem()); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/multiline/AggregateItemReaderTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/multiline/AggregateItemReaderTests.java deleted file mode 100644 index 34e9a8b9d..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/multiline/AggregateItemReaderTests.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2008-2023 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.samples.domain.multiline; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.batch.item.ItemReader; -import org.springframework.batch.samples.file.multilineaggregate.AggregateItem; -import org.springframework.batch.samples.file.multilineaggregate.AggregateItemReader; -import org.springframework.lang.Nullable; - -import java.util.Collection; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -class AggregateItemReaderTests { - - private ItemReader> input; - - private AggregateItemReader provider; - - @BeforeEach - void setUp() { - input = new ItemReader<>() { - private int count = 0; - - @Nullable - @Override - public AggregateItem read() { - return switch (count++) { - case 0 -> AggregateItem.getHeader(); - case 1, 2, 3 -> new AggregateItem<>("line"); - case 4 -> AggregateItem.getFooter(); - default -> null; - }; - } - - }; - - provider = new AggregateItemReader<>(); - provider.setItemReader(input); - } - - @Test - void testNext() throws Exception { - Object result = provider.read(); - - Collection lines = (Collection) result; - assertEquals(3, lines.size()); - - for (Object line : lines) { - assertEquals("line", line); - } - - assertNull(provider.read()); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/multiline/AggregateItemTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/multiline/AggregateItemTests.java deleted file mode 100644 index aef0e4567..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/multiline/AggregateItemTests.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2006-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.samples.domain.multiline; - -import org.junit.jupiter.api.Test; - -import org.springframework.batch.samples.file.multilineaggregate.AggregateItem; - -import static org.junit.jupiter.api.Assertions.*; - -/** - * @author Dave Syer - * @author Glenn Renfro - * - */ -class AggregateItemTests { - - @Test - void testGetFooter() { - assertTrue(AggregateItem.getFooter().isFooter()); - assertFalse(AggregateItem.getFooter().isHeader()); - } - - @Test - void testGetHeader() { - assertTrue(AggregateItem.getHeader().isHeader()); - assertFalse(AggregateItem.getHeader().isFooter()); - } - - @Test - void testBeginRecordHasNoItem() { - assertThrows(IllegalStateException.class, () -> AggregateItem.getHeader().getItem()); - } - - @Test - void testEndRecordHasNoItem() { - assertThrows(IllegalStateException.class, () -> AggregateItem.getFooter().getItem()); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/AddressFieldSetMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/AddressFieldSetMapperTests.java deleted file mode 100644 index a4b1269ce..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/AddressFieldSetMapperTests.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.samples.domain.order; - -import org.springframework.batch.item.file.mapping.FieldSetMapper; -import org.springframework.batch.item.file.transform.DefaultFieldSet; -import org.springframework.batch.item.file.transform.FieldSet; -import org.springframework.batch.samples.file.patternmatching.Address; -import org.springframework.batch.samples.file.patternmatching.internal.mapper.AddressFieldSetMapper; -import org.springframework.batch.samples.support.AbstractFieldSetMapperTests; - -class AddressFieldSetMapperTests extends AbstractFieldSetMapperTests { - - private static final String ADDRESSEE = "Jan Hrach"; - - private static final String ADDRESS_LINE_1 = "Plynarenska 7c"; - - private static final String ADDRESS_LINE_2 = ""; - - private static final String CITY = "Bratislava"; - - private static final String STATE = ""; - - private static final String COUNTRY = "Slovakia"; - - private static final String ZIP_CODE = "80000"; - - @Override - protected Object expectedDomainObject() { - Address address = new Address(); - address.setAddressee(ADDRESSEE); - address.setAddrLine1(ADDRESS_LINE_1); - address.setAddrLine2(ADDRESS_LINE_2); - address.setCity(CITY); - address.setState(STATE); - address.setCountry(COUNTRY); - address.setZipCode(ZIP_CODE); - return address; - } - - @Override - protected FieldSet fieldSet() { - String[] tokens = new String[] { ADDRESSEE, ADDRESS_LINE_1, ADDRESS_LINE_2, CITY, STATE, COUNTRY, ZIP_CODE }; - String[] columnNames = new String[] { AddressFieldSetMapper.ADDRESSEE_COLUMN, - AddressFieldSetMapper.ADDRESS_LINE1_COLUMN, AddressFieldSetMapper.ADDRESS_LINE2_COLUMN, - AddressFieldSetMapper.CITY_COLUMN, AddressFieldSetMapper.STATE_COLUMN, - AddressFieldSetMapper.COUNTRY_COLUMN, AddressFieldSetMapper.ZIP_CODE_COLUMN }; - - return new DefaultFieldSet(tokens, columnNames); - } - - @Override - protected FieldSetMapper
fieldSetMapper() { - return new AddressFieldSetMapper(); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/BillingFieldSetMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/BillingFieldSetMapperTests.java deleted file mode 100644 index 4810cd4c5..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/BillingFieldSetMapperTests.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.samples.domain.order; - -import org.springframework.batch.item.file.mapping.FieldSetMapper; -import org.springframework.batch.item.file.transform.DefaultFieldSet; -import org.springframework.batch.item.file.transform.FieldSet; -import org.springframework.batch.samples.file.patternmatching.BillingInfo; -import org.springframework.batch.samples.file.patternmatching.internal.mapper.BillingFieldSetMapper; -import org.springframework.batch.samples.support.AbstractFieldSetMapperTests; - -class BillingFieldSetMapperTests extends AbstractFieldSetMapperTests { - - private static final String PAYMENT_ID = "777"; - - private static final String PAYMENT_DESC = "My last penny"; - - @Override - protected Object expectedDomainObject() { - BillingInfo bInfo = new BillingInfo(); - bInfo.setPaymentDesc(PAYMENT_DESC); - bInfo.setPaymentId(PAYMENT_ID); - return bInfo; - } - - @Override - protected FieldSet fieldSet() { - String[] tokens = new String[] { PAYMENT_ID, PAYMENT_DESC }; - String[] columnNames = new String[] { BillingFieldSetMapper.PAYMENT_TYPE_ID_COLUMN, - BillingFieldSetMapper.PAYMENT_DESC_COLUMN }; - return new DefaultFieldSet(tokens, columnNames); - } - - @Override - protected FieldSetMapper fieldSetMapper() { - return new BillingFieldSetMapper(); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/CustomerFieldSetMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/CustomerFieldSetMapperTests.java deleted file mode 100644 index 5a5e3032b..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/CustomerFieldSetMapperTests.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.samples.domain.order; - -import org.springframework.batch.item.file.mapping.FieldSetMapper; -import org.springframework.batch.item.file.transform.DefaultFieldSet; -import org.springframework.batch.item.file.transform.FieldSet; -import org.springframework.batch.samples.file.patternmatching.Customer; -import org.springframework.batch.samples.file.patternmatching.internal.mapper.CustomerFieldSetMapper; -import org.springframework.batch.samples.support.AbstractFieldSetMapperTests; - -class CustomerFieldSetMapperTests extends AbstractFieldSetMapperTests { - - private static final boolean BUSINESS_CUSTOMER = false; - - private static final String FIRST_NAME = "Jan"; - - private static final String LAST_NAME = "Hrach"; - - private static final String MIDDLE_NAME = ""; - - private static final boolean REGISTERED = true; - - private static final long REG_ID = 1; - - private static final boolean VIP = true; - - @Override - protected Object expectedDomainObject() { - Customer cs = new Customer(); - cs.setBusinessCustomer(BUSINESS_CUSTOMER); - cs.setFirstName(FIRST_NAME); - cs.setLastName(LAST_NAME); - cs.setMiddleName(MIDDLE_NAME); - cs.setRegistered(REGISTERED); - cs.setRegistrationId(REG_ID); - cs.setVip(VIP); - return cs; - } - - @Override - protected FieldSet fieldSet() { - String[] tokens = new String[] { Customer.LINE_ID_NON_BUSINESS_CUST, FIRST_NAME, LAST_NAME, MIDDLE_NAME, - CustomerFieldSetMapper.TRUE_SYMBOL, String.valueOf(REG_ID), CustomerFieldSetMapper.TRUE_SYMBOL }; - String[] columnNames = new String[] { CustomerFieldSetMapper.LINE_ID_COLUMN, - CustomerFieldSetMapper.FIRST_NAME_COLUMN, CustomerFieldSetMapper.LAST_NAME_COLUMN, - CustomerFieldSetMapper.MIDDLE_NAME_COLUMN, CustomerFieldSetMapper.REGISTERED_COLUMN, - CustomerFieldSetMapper.REG_ID_COLUMN, CustomerFieldSetMapper.VIP_COLUMN }; - - return new DefaultFieldSet(tokens, columnNames); - } - - @Override - protected FieldSetMapper fieldSetMapper() { - return new CustomerFieldSetMapper(); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/HeaderFieldSetMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/HeaderFieldSetMapperTests.java deleted file mode 100644 index 5789842f3..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/HeaderFieldSetMapperTests.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.samples.domain.order; - -import java.util.Calendar; - -import org.springframework.batch.item.file.mapping.FieldSetMapper; -import org.springframework.batch.item.file.transform.DefaultFieldSet; -import org.springframework.batch.item.file.transform.FieldSet; -import org.springframework.batch.samples.file.patternmatching.Order; -import org.springframework.batch.samples.file.patternmatching.internal.mapper.HeaderFieldSetMapper; -import org.springframework.batch.samples.support.AbstractFieldSetMapperTests; - -class HeaderFieldSetMapperTests extends AbstractFieldSetMapperTests { - - private static final long ORDER_ID = 1; - - private static final String DATE = "2007-01-01"; - - @Override - protected Object expectedDomainObject() { - Order order = new Order(); - Calendar calendar = Calendar.getInstance(); - calendar.set(2007, 0, 1, 0, 0, 0); - calendar.set(Calendar.MILLISECOND, 0); - order.setOrderDate(calendar.getTime()); - order.setOrderId(ORDER_ID); - return order; - } - - @Override - protected FieldSet fieldSet() { - String[] tokens = new String[] { String.valueOf(ORDER_ID), DATE }; - String[] columnNames = new String[] { HeaderFieldSetMapper.ORDER_ID_COLUMN, - HeaderFieldSetMapper.ORDER_DATE_COLUMN }; - return new DefaultFieldSet(tokens, columnNames); - } - - @Override - protected FieldSetMapper fieldSetMapper() { - return new HeaderFieldSetMapper(); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/OrderItemFieldSetMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/OrderItemFieldSetMapperTests.java deleted file mode 100644 index 01001757a..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/OrderItemFieldSetMapperTests.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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.samples.domain.order; - -import java.math.BigDecimal; - -import org.springframework.batch.item.file.mapping.FieldSetMapper; -import org.springframework.batch.item.file.transform.DefaultFieldSet; -import org.springframework.batch.item.file.transform.FieldSet; -import org.springframework.batch.samples.file.patternmatching.LineItem; -import org.springframework.batch.samples.file.patternmatching.internal.mapper.OrderItemFieldSetMapper; -import org.springframework.batch.samples.support.AbstractFieldSetMapperTests; - -class OrderItemFieldSetMapperTests extends AbstractFieldSetMapperTests { - - private static final BigDecimal DISCOUNT_AMOUNT = new BigDecimal("1"); - - private static final BigDecimal DISCOUNT_PERC = new BigDecimal("2"); - - private static final BigDecimal HANDLING_PRICE = new BigDecimal("3"); - - private static final long ITEM_ID = 4; - - private static final BigDecimal PRICE = new BigDecimal("5"); - - private static final int QUANTITY = 6; - - private static final BigDecimal SHIPPING_PRICE = new BigDecimal("7"); - - private static final BigDecimal TOTAL_PRICE = new BigDecimal("8"); - - @Override - protected Object expectedDomainObject() { - LineItem item = new LineItem(); - item.setDiscountAmount(DISCOUNT_AMOUNT); - item.setDiscountPerc(DISCOUNT_PERC); - item.setHandlingPrice(HANDLING_PRICE); - item.setItemId(ITEM_ID); - item.setPrice(PRICE); - item.setQuantity(QUANTITY); - item.setShippingPrice(SHIPPING_PRICE); - item.setTotalPrice(TOTAL_PRICE); - return item; - } - - @Override - protected FieldSet fieldSet() { - String[] tokens = new String[] { String.valueOf(DISCOUNT_AMOUNT), String.valueOf(DISCOUNT_PERC), - String.valueOf(HANDLING_PRICE), String.valueOf(ITEM_ID), String.valueOf(PRICE), - String.valueOf(QUANTITY), String.valueOf(SHIPPING_PRICE), String.valueOf(TOTAL_PRICE) }; - String[] columnNames = new String[] { OrderItemFieldSetMapper.DISCOUNT_AMOUNT_COLUMN, - OrderItemFieldSetMapper.DISCOUNT_PERC_COLUMN, OrderItemFieldSetMapper.HANDLING_PRICE_COLUMN, - OrderItemFieldSetMapper.ITEM_ID_COLUMN, OrderItemFieldSetMapper.PRICE_COLUMN, - OrderItemFieldSetMapper.QUANTITY_COLUMN, OrderItemFieldSetMapper.SHIPPING_PRICE_COLUMN, - OrderItemFieldSetMapper.TOTAL_PRICE_COLUMN }; - return new DefaultFieldSet(tokens, columnNames); - } - - @Override - protected FieldSetMapper fieldSetMapper() { - return new OrderItemFieldSetMapper(); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/OrderItemReaderTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/OrderItemReaderTests.java deleted file mode 100644 index 07942d78e..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/OrderItemReaderTests.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * 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.samples.domain.order; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.batch.item.ItemReader; -import org.springframework.batch.item.file.mapping.FieldSetMapper; -import org.springframework.batch.item.file.transform.DefaultFieldSet; -import org.springframework.batch.item.file.transform.FieldSet; -import org.springframework.batch.samples.file.patternmatching.Address; -import org.springframework.batch.samples.file.patternmatching.BillingInfo; -import org.springframework.batch.samples.file.patternmatching.Customer; -import org.springframework.batch.samples.file.patternmatching.LineItem; -import org.springframework.batch.samples.file.patternmatching.Order; -import org.springframework.batch.samples.file.patternmatching.ShippingInfo; -import org.springframework.batch.samples.file.patternmatching.internal.OrderItemReader; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -class OrderItemReaderTests { - - private OrderItemReader provider; - - private ItemReader
input; - - @BeforeEach - @SuppressWarnings("unchecked") - void setUp() { - input = mock(); - - provider = new OrderItemReader(); - provider.setFieldSetReader(input); - } - - /* - * OrderItemProvider is responsible for retrieving validated value object from input - * source. OrderItemProvider.next(): - reads lines from the input source - returned as - * fieldsets - pass fieldsets to the mapper - mapper will create value object - pass - * value object to validator - returns validated object - * - * In testNext method we are going to test these responsibilities. So we need create - * mock objects for input source, mapper and validator. - */ - @Test - @SuppressWarnings("unchecked") - void testNext() throws Exception { - FieldSet headerFS = new DefaultFieldSet(new String[] { Order.LINE_ID_HEADER }); - FieldSet customerFS = new DefaultFieldSet(new String[] { Customer.LINE_ID_NON_BUSINESS_CUST }); - FieldSet billingFS = new DefaultFieldSet(new String[] { Address.LINE_ID_BILLING_ADDR }); - FieldSet shippingFS = new DefaultFieldSet(new String[] { Address.LINE_ID_SHIPPING_ADDR }); - FieldSet billingInfoFS = new DefaultFieldSet(new String[] { BillingInfo.LINE_ID_BILLING_INFO }); - FieldSet shippingInfoFS = new DefaultFieldSet(new String[] { ShippingInfo.LINE_ID_SHIPPING_INFO }); - FieldSet itemFS = new DefaultFieldSet(new String[] { LineItem.LINE_ID_ITEM }); - FieldSet footerFS = new DefaultFieldSet(new String[] { Order.LINE_ID_FOOTER, "100", "3", "3" }, - new String[] { "ID", "TOTAL_PRICE", "TOTAL_LINE_ITEMS", "TOTAL_ITEMS" }); - - when(input.read()).thenReturn(headerFS, customerFS, billingFS, shippingFS, billingInfoFS, shippingInfoFS, - itemFS, itemFS, itemFS, footerFS, null); - - Order order = new Order(); - Customer customer = new Customer(); - Address billing = new Address(); - Address shipping = new Address(); - BillingInfo billingInfo = new BillingInfo(); - ShippingInfo shippingInfo = new ShippingInfo(); - LineItem item = new LineItem(); - - @SuppressWarnings("rawtypes") - FieldSetMapper mapper = mock(); - when(mapper.mapFieldSet(headerFS)).thenReturn(order); - when(mapper.mapFieldSet(customerFS)).thenReturn(customer); - when(mapper.mapFieldSet(billingFS)).thenReturn(billing); - when(mapper.mapFieldSet(shippingFS)).thenReturn(shipping); - when(mapper.mapFieldSet(billingInfoFS)).thenReturn(billingInfo); - when(mapper.mapFieldSet(shippingInfoFS)).thenReturn(shippingInfo); - when(mapper.mapFieldSet(itemFS)).thenReturn(item); - - provider.setAddressMapper(mapper); - provider.setBillingMapper(mapper); - provider.setCustomerMapper(mapper); - provider.setHeaderMapper(mapper); - provider.setItemMapper(mapper); - provider.setShippingMapper(mapper); - - Object result = provider.read(); - - assertNotNull(result); - - Order o = (Order) result; - assertEquals(o, order); - assertEquals(o.getCustomer(), customer); - assertFalse(o.getCustomer().isBusinessCustomer()); - assertEquals(o.getBillingAddress(), billing); - assertEquals(o.getShippingAddress(), shipping); - assertEquals(o.getBilling(), billingInfo); - assertEquals(o.getShipping(), shippingInfo); - - assertEquals(3, o.getLineItems().size()); - - for (LineItem lineItem : o.getLineItems()) { - assertEquals(lineItem, item); - } - - assertNull(provider.read()); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/ShippingFieldSetMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/ShippingFieldSetMapperTests.java deleted file mode 100644 index 017ebccd3..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/order/ShippingFieldSetMapperTests.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.samples.domain.order; - -import org.springframework.batch.item.file.mapping.FieldSetMapper; -import org.springframework.batch.item.file.transform.DefaultFieldSet; -import org.springframework.batch.item.file.transform.FieldSet; -import org.springframework.batch.samples.file.patternmatching.ShippingInfo; -import org.springframework.batch.samples.file.patternmatching.internal.mapper.ShippingFieldSetMapper; -import org.springframework.batch.samples.support.AbstractFieldSetMapperTests; - -class ShippingFieldSetMapperTests extends AbstractFieldSetMapperTests { - - private static final String SHIPPER_ID = "1"; - - private static final String SHIPPING_INFO = "most interesting and informative shipping info ever"; - - private static final String SHIPPING_TYPE_ID = "X"; - - @Override - protected Object expectedDomainObject() { - ShippingInfo info = new ShippingInfo(); - info.setShipperId(SHIPPER_ID); - info.setShippingInfo(SHIPPING_INFO); - info.setShippingTypeId(SHIPPING_TYPE_ID); - return info; - } - - @Override - protected FieldSet fieldSet() { - String[] tokens = new String[] { SHIPPER_ID, SHIPPING_INFO, SHIPPING_TYPE_ID }; - String[] columnNames = new String[] { ShippingFieldSetMapper.SHIPPER_ID_COLUMN, - ShippingFieldSetMapper.ADDITIONAL_SHIPPING_INFO_COLUMN, - ShippingFieldSetMapper.SHIPPING_TYPE_ID_COLUMN }; - return new DefaultFieldSet(tokens, columnNames); - } - - @Override - protected FieldSetMapper fieldSetMapper() { - return new ShippingFieldSetMapper(); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/CompositeCustomerUpdateLineTokenizerTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/CompositeCustomerUpdateLineTokenizerTests.java deleted file mode 100644 index 7b40d7d81..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/CompositeCustomerUpdateLineTokenizerTests.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * 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.samples.domain.trade; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.batch.item.file.transform.DefaultFieldSet; -import org.springframework.batch.item.file.transform.FieldSet; -import org.springframework.batch.item.file.transform.LineTokenizer; -import org.springframework.lang.Nullable; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -/** - * @author Lucas Ward - * @author Glenn Renfro - * - */ -class CompositeCustomerUpdateLineTokenizerTests { - - private StubLineTokenizer customerTokenizer; - - private final FieldSet customerFieldSet = new DefaultFieldSet(null); - - private final FieldSet footerFieldSet = new DefaultFieldSet(null); - - private CompositeCustomerUpdateLineTokenizer compositeTokenizer; - - @BeforeEach - void init() { - customerTokenizer = new StubLineTokenizer(customerFieldSet); - compositeTokenizer = new CompositeCustomerUpdateLineTokenizer(); - compositeTokenizer.setCustomerTokenizer(customerTokenizer); - compositeTokenizer.setFooterTokenizer(new StubLineTokenizer(footerFieldSet)); - } - - @Test - void testCustomerAdd() { - String customerAddLine = "AFDASFDASFDFSA"; - FieldSet fs = compositeTokenizer.tokenize(customerAddLine); - assertEquals(customerFieldSet, fs); - assertEquals(customerAddLine, customerTokenizer.getTokenizedLine()); - } - - @Test - void testCustomerDelete() { - String customerAddLine = "DFDASFDASFDFSA"; - FieldSet fs = compositeTokenizer.tokenize(customerAddLine); - assertEquals(customerFieldSet, fs); - assertEquals(customerAddLine, customerTokenizer.getTokenizedLine()); - } - - @Test - void testCustomerUpdate() { - String customerAddLine = "UFDASFDASFDFSA"; - FieldSet fs = compositeTokenizer.tokenize(customerAddLine); - assertEquals(customerFieldSet, fs); - assertEquals(customerAddLine, customerTokenizer.getTokenizedLine()); - } - - @Test - void testInvalidLine() { - String invalidLine = "INVALID"; - assertThrows(IllegalArgumentException.class, () -> compositeTokenizer.tokenize(invalidLine)); - } - - private static class StubLineTokenizer implements LineTokenizer { - - private final FieldSet fieldSetToReturn; - - private String tokenizedLine; - - public StubLineTokenizer(FieldSet fieldSetToReturn) { - this.fieldSetToReturn = fieldSetToReturn; - } - - @Override - public FieldSet tokenize(@Nullable String line) { - this.tokenizedLine = line; - return fieldSetToReturn; - } - - public String getTokenizedLine() { - return tokenizedLine; - } - - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/CustomerUpdateProcessorTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/CustomerUpdateProcessorTests.java deleted file mode 100644 index 477af4f86..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/CustomerUpdateProcessorTests.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2008-2023 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.samples.domain.trade; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.math.BigDecimal; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -/** - * @author Lucas Ward - * @author Glenn Renfro - * - */ -class CustomerUpdateProcessorTests { - - private CustomerDao customerDao; - - private InvalidCustomerLogger logger; - - private CustomerUpdateProcessor processor; - - @BeforeEach - void init() { - customerDao = mock(); - logger = mock(); - processor = new CustomerUpdateProcessor(); - processor.setCustomerDao(customerDao); - processor.setInvalidCustomerLogger(logger); - } - - @Test - void testSuccessfulAdd() throws Exception { - CustomerUpdate customerUpdate = new CustomerUpdate(CustomerOperation.ADD, "test customer", - new BigDecimal("232.2")); - when(customerDao.getCustomerByName("test customer")).thenReturn(null); - assertEquals(customerUpdate, processor.process(customerUpdate)); - } - - @Test - void testInvalidAdd() throws Exception { - CustomerUpdate customerUpdate = new CustomerUpdate(CustomerOperation.ADD, "test customer", - new BigDecimal("232.2")); - when(customerDao.getCustomerByName("test customer")).thenReturn(new CustomerCredit()); - logger.log(customerUpdate); - assertNull(processor.process(customerUpdate), "Processor should return null"); - } - - @Test - void testDelete() throws Exception { - CustomerUpdate customerUpdate = new CustomerUpdate(CustomerOperation.DELETE, "test customer", - new BigDecimal("232.2")); - logger.log(customerUpdate); - assertNull(processor.process(customerUpdate), "Processor should return null"); - } - - @Test - void testSuccessfulUpdate() throws Exception { - CustomerUpdate customerUpdate = new CustomerUpdate(CustomerOperation.UPDATE, "test customer", - new BigDecimal("232.2")); - when(customerDao.getCustomerByName("test customer")).thenReturn(new CustomerCredit()); - assertEquals(customerUpdate, processor.process(customerUpdate)); - } - - @Test - void testInvalidUpdate() throws Exception { - CustomerUpdate customerUpdate = new CustomerUpdate(CustomerOperation.UPDATE, "test customer", - new BigDecimal("232.2")); - when(customerDao.getCustomerByName("test customer")).thenReturn(null); - logger.log(customerUpdate); - assertNull(processor.process(customerUpdate), "Processor should return null"); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/TradeTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/TradeTests.java deleted file mode 100644 index b950ce4ab..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/TradeTests.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.samples.domain.trade; - -import org.junit.jupiter.api.Test; - -import java.math.BigDecimal; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -class TradeTests { - - @Test - void testEquality() { - Trade trade1 = new Trade("isin", 1, new BigDecimal("1.1"), "customer1"); - Trade trade1Clone = new Trade("isin", 1, new BigDecimal("1.1"), "customer1"); - Trade trade2 = new Trade("isin", 1, new BigDecimal("2.3"), "customer2"); - - assertEquals(trade1, trade1Clone); - assertNotEquals(trade1, trade2); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/CustomerCreditIncreaseProcessorTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/CustomerCreditIncreaseProcessorTests.java deleted file mode 100644 index d8eca6cec..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/CustomerCreditIncreaseProcessorTests.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.samples.domain.trade.internal; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.springframework.batch.samples.domain.trade.CustomerCredit; - -import java.math.BigDecimal; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * Tests for {@link CustomerCreditIncreaseProcessor}. - * - * @author Robert Kasanicky - * @author Glenn Renfro - */ -class CustomerCreditIncreaseProcessorTests { - - private final CustomerCreditIncreaseProcessor tested = new CustomerCreditIncreaseProcessor(); - - /* - * Increases customer's credit by fixed value - */ - @Test - void testProcess() throws Exception { - final BigDecimal oldCredit = new BigDecimal("10.54"); - CustomerCredit customerCredit = new CustomerCredit(); - customerCredit.setCredit(oldCredit); - - Assertions.assertEquals(oldCredit.add(CustomerCreditIncreaseProcessor.FIXED_AMOUNT), - tested.process(customerCredit).getCredit()); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/CustomerCreditRowMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/CustomerCreditRowMapperTests.java deleted file mode 100644 index 1b4673179..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/CustomerCreditRowMapperTests.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.samples.domain.trade.internal; - -import static org.mockito.Mockito.when; - -import java.math.BigDecimal; -import java.sql.ResultSet; -import java.sql.SQLException; - -import org.springframework.batch.samples.domain.trade.CustomerCredit; -import org.springframework.batch.samples.support.AbstractRowMapperTests; -import org.springframework.jdbc.core.RowMapper; - -class CustomerCreditRowMapperTests extends AbstractRowMapperTests { - - private static final int ID = 12; - - private static final String CUSTOMER = "Jozef Mak"; - - private static final BigDecimal CREDIT = new BigDecimal("0.1"); - - @Override - protected CustomerCredit expectedDomainObject() { - CustomerCredit credit = new CustomerCredit(); - credit.setId(ID); - credit.setCredit(CREDIT); - credit.setName(CUSTOMER); - return credit; - } - - @Override - protected RowMapper rowMapper() { - return new CustomerCreditRowMapper(); - } - - @Override - protected void setUpResultSetMock(ResultSet rs) throws SQLException { - when(rs.getInt(CustomerCreditRowMapper.ID_COLUMN)).thenReturn(ID); - when(rs.getString(CustomerCreditRowMapper.NAME_COLUMN)).thenReturn(CUSTOMER); - when(rs.getBigDecimal(CustomerCreditRowMapper.CREDIT_COLUMN)).thenReturn(CREDIT); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/CustomerCreditUpdatePreparedStatementSetterTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/CustomerCreditUpdatePreparedStatementSetterTests.java deleted file mode 100644 index 5dc781338..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/CustomerCreditUpdatePreparedStatementSetterTests.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2006-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.samples.domain.trade.internal; - -import static org.mockito.Mockito.mock; - -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.SQLException; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.batch.samples.domain.trade.CustomerCredit; - -/** - * @author Dave Syer - * @author Glenn Renfro - * - */ -class CustomerCreditUpdatePreparedStatementSetterTests { - - private final CustomerCreditUpdatePreparedStatementSetter setter = new CustomerCreditUpdatePreparedStatementSetter(); - - private CustomerCredit credit; - - private PreparedStatement ps; - - @BeforeEach - void setUp() { - ps = mock(); - credit = new CustomerCredit(); - credit.setId(13); - credit.setCredit(new BigDecimal(12000)); - credit.setName("foo"); - } - - @Test - void testSetValues() throws SQLException { - ps.setBigDecimal(1, credit.getCredit().add(CustomerCreditUpdatePreparedStatementSetter.FIXED_AMOUNT)); - ps.setLong(2, credit.getId()); - setter.setValues(credit, ps); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/CustomerCreditUpdateProcessorTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/CustomerCreditUpdateProcessorTests.java deleted file mode 100644 index fe23e676c..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/CustomerCreditUpdateProcessorTests.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.samples.domain.trade.internal; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.batch.item.Chunk; -import org.springframework.batch.samples.domain.trade.CustomerCredit; -import org.springframework.batch.samples.domain.trade.CustomerCreditDao; - -import java.math.BigDecimal; - -import static org.mockito.Mockito.mock; - -class CustomerCreditUpdateProcessorTests { - - private CustomerCreditDao dao; - - private CustomerCreditUpdateWriter writer; - - private static final double CREDIT_FILTER = 355.0; - - @BeforeEach - void setUp() { - dao = mock(); - - writer = new CustomerCreditUpdateWriter(); - writer.setDao(dao); - writer.setCreditFilter(CREDIT_FILTER); - } - - @Test - void testProcess() throws Exception { - CustomerCredit credit = new CustomerCredit(); - credit.setCredit(new BigDecimal(CREDIT_FILTER)); - - writer.write(Chunk.of(credit)); - - credit.setCredit(new BigDecimal(CREDIT_FILTER + 1)); - - dao.writeCredit(credit); - - writer.write(Chunk.of(credit)); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/CustomerUpdateProcessorTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/CustomerUpdateProcessorTests.java deleted file mode 100644 index 3bd08dd09..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/CustomerUpdateProcessorTests.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2008-2023 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.samples.domain.trade.internal; - -import org.junit.jupiter.api.Test; -import org.springframework.batch.item.Chunk; -import org.springframework.batch.samples.domain.trade.CustomerDebitDao; -import org.springframework.batch.samples.domain.trade.Trade; - -import java.math.BigDecimal; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class CustomerUpdateProcessorTests { - - @Test - void testProcess() { - Trade trade = new Trade(); - trade.setCustomer("testCustomerName"); - trade.setPrice(new BigDecimal("123.0")); - - CustomerDebitDao dao = customerDebit -> { - assertEquals("testCustomerName", customerDebit.getName()); - assertEquals(new BigDecimal("123.0"), customerDebit.getDebit()); - }; - - CustomerUpdateWriter processor = new CustomerUpdateWriter(); - processor.setDao(dao); - - processor.write(Chunk.of(trade)); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/FlatFileCustomerCreditDaoTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/FlatFileCustomerCreditDaoTests.java deleted file mode 100644 index 090fa8094..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/FlatFileCustomerCreditDaoTests.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2006-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.samples.domain.trade.internal; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.batch.item.Chunk; -import org.springframework.batch.item.ExecutionContext; -import org.springframework.batch.item.ItemStream; -import org.springframework.batch.item.ItemWriter; -import org.springframework.batch.samples.domain.trade.CustomerCredit; - -import java.math.BigDecimal; - -import static org.mockito.Mockito.mock; - -class FlatFileCustomerCreditDaoTests { - - private ResourceLifecycleItemWriter output; - - private FlatFileCustomerCreditDao writer; - - @BeforeEach - void setUp() { - output = mock(); - - writer = new FlatFileCustomerCreditDao(); - writer.setItemWriter(output); - } - - @Test - void testOpen() throws Exception { - ExecutionContext executionContext = new ExecutionContext(); - - output.open(executionContext); - - writer.open(executionContext); - } - - @Test - void testClose() throws Exception { - output.close(); - - writer.close(); - } - - @Test - void testWrite() throws Exception { - CustomerCredit credit = new CustomerCredit(); - credit.setCredit(new BigDecimal(1)); - credit.setName("testName"); - - writer.setSeparator(";"); - - output.write(Chunk.of("testName;1")); - output.open(new ExecutionContext()); - - writer.writeCredit(credit); - } - - private interface ResourceLifecycleItemWriter extends ItemWriter, ItemStream { - - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/GeneratingItemReaderTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/GeneratingItemReaderTests.java deleted file mode 100644 index d5c3597c2..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/GeneratingItemReaderTests.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.samples.domain.trade.internal; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -/** - * Tests for {@link GeneratingTradeItemReader}. - * - * @author Robert Kasanicky - * @author Glenn Renfro - */ -class GeneratingItemReaderTests { - - private final GeneratingTradeItemReader reader = new GeneratingTradeItemReader(); - - /* - * Generates a given number of not-null records, consecutive calls return null. - */ - @Test - void testRead() throws Exception { - int counter = 0; - int limit = 10; - reader.setLimit(limit); - - while (reader.read() != null) { - counter++; - } - - assertNull(reader.read()); - assertEquals(limit, counter); - assertEquals(counter, reader.getCounter()); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/JdbcTradeWriterTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/JdbcTradeWriterTests.java deleted file mode 100644 index 1cc1db2df..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/JdbcTradeWriterTests.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2006-2023 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.samples.domain.trade.internal; - -import java.math.BigDecimal; - -import javax.sql.DataSource; - -import org.junit.jupiter.api.Test; - -import org.springframework.batch.samples.domain.trade.Trade; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.jdbc.core.JdbcOperations; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.support.incrementer.AbstractDataFieldMaxValueIncrementer; -import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -import org.springframework.transaction.annotation.Transactional; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -@SpringJUnitConfig(locations = { "/data-source-context.xml" }) -class JdbcTradeWriterTests implements InitializingBean { - - private JdbcOperations jdbcTemplate; - - private JdbcTradeDao writer; - - private AbstractDataFieldMaxValueIncrementer incrementer; - - @Autowired - public void setDataSource(DataSource dataSource) { - this.jdbcTemplate = new JdbcTemplate(dataSource); - this.writer = new JdbcTradeDao(); - this.writer.setDataSource(dataSource); - } - - @Autowired - public void setIncrementer(@Qualifier("incrementerParent") AbstractDataFieldMaxValueIncrementer incrementer) { - incrementer.setIncrementerName("TRADE_SEQ"); - this.incrementer = incrementer; - } - - @Test - @Transactional - void testWrite() { - Trade trade = new Trade(); - trade.setCustomer("testCustomer"); - trade.setIsin("5647238492"); - trade.setPrice(new BigDecimal("99.69")); - trade.setQuantity(5); - - writer.writeTrade(trade); - - jdbcTemplate.query("SELECT * FROM TRADE WHERE ISIN = '5647238492'", rs -> { - assertEquals("testCustomer", rs.getString("CUSTOMER")); - assertEquals(new BigDecimal(Double.toString(99.69)), rs.getBigDecimal("PRICE")); - assertEquals(5, rs.getLong("QUANTITY")); - }); - } - - @Override - public void afterPropertiesSet() { - this.writer.setIncrementer(incrementer); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/TradeFieldSetMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/TradeFieldSetMapperTests.java deleted file mode 100644 index 5311cd406..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/TradeFieldSetMapperTests.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.samples.domain.trade.internal; - -import java.math.BigDecimal; - -import org.springframework.batch.item.file.mapping.FieldSetMapper; -import org.springframework.batch.item.file.transform.DefaultFieldSet; -import org.springframework.batch.item.file.transform.FieldSet; -import org.springframework.batch.samples.domain.trade.Trade; -import org.springframework.batch.samples.support.AbstractFieldSetMapperTests; - -class TradeFieldSetMapperTests extends AbstractFieldSetMapperTests { - - private static final String CUSTOMER = "Mike Tomcat"; - - private static final BigDecimal PRICE = new BigDecimal(1.3); - - private static final long QUANTITY = 7; - - private static final String ISIN = "fj893gnsalX"; - - @Override - protected Object expectedDomainObject() { - Trade trade = new Trade(); - trade.setIsin(ISIN); - trade.setQuantity(QUANTITY); - trade.setPrice(PRICE); - trade.setCustomer(CUSTOMER); - return trade; - } - - @Override - protected FieldSet fieldSet() { - String[] tokens = new String[4]; - tokens[TradeFieldSetMapper.ISIN_COLUMN] = ISIN; - tokens[TradeFieldSetMapper.QUANTITY_COLUMN] = String.valueOf(QUANTITY); - tokens[TradeFieldSetMapper.PRICE_COLUMN] = String.valueOf(PRICE); - tokens[TradeFieldSetMapper.CUSTOMER_COLUMN] = CUSTOMER; - - return new DefaultFieldSet(tokens); - } - - @Override - protected FieldSetMapper fieldSetMapper() { - return new TradeFieldSetMapper(); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/TradeProcessorTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/TradeProcessorTests.java deleted file mode 100644 index 45ebcbd24..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/TradeProcessorTests.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.samples.domain.trade.internal; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.batch.item.Chunk; -import org.springframework.batch.samples.domain.trade.Trade; -import org.springframework.batch.samples.domain.trade.TradeDao; - -import static org.mockito.Mockito.mock; - -class TradeProcessorTests { - - private TradeDao writer; - - private TradeWriter processor; - - @BeforeEach - void setUp() { - writer = mock(); - - processor = new TradeWriter(); - processor.setDao(writer); - } - - @Test - void testProcess() { - Trade trade = new Trade(); - - writer.writeTrade(trade); - - processor.write(Chunk.of(trade)); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/TradeRowMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/TradeRowMapperTests.java deleted file mode 100644 index bf7152d38..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/domain/trade/internal/TradeRowMapperTests.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.samples.domain.trade.internal; - -import static org.mockito.Mockito.when; - -import java.math.BigDecimal; -import java.sql.ResultSet; -import java.sql.SQLException; - -import org.springframework.batch.samples.domain.trade.Trade; -import org.springframework.batch.samples.support.AbstractRowMapperTests; -import org.springframework.jdbc.core.RowMapper; - -class TradeRowMapperTests extends AbstractRowMapperTests { - - private static final String ISIN = "jsgk342"; - - private static final long QUANTITY = 0; - - private static final BigDecimal PRICE = new BigDecimal("1.1"); - - private static final String CUSTOMER = "Martin Hrancok"; - - @Override - protected Trade expectedDomainObject() { - Trade trade = new Trade(); - trade.setIsin(ISIN); - trade.setQuantity(QUANTITY); - trade.setPrice(PRICE); - trade.setCustomer(CUSTOMER); - - return trade; - } - - @Override - protected RowMapper rowMapper() { - return new TradeRowMapper(); - } - - @Override - protected void setUpResultSetMock(ResultSet rs) throws SQLException { - when(rs.getLong(TradeRowMapper.ID_COLUMN)).thenReturn(12L); - when(rs.getString(TradeRowMapper.ISIN_COLUMN)).thenReturn(ISIN); - when(rs.getLong(TradeRowMapper.QUANTITY_COLUMN)).thenReturn(QUANTITY); - when(rs.getBigDecimal(TradeRowMapper.PRICE_COLUMN)).thenReturn(PRICE); - when(rs.getString(TradeRowMapper.CUSTOMER_COLUMN)).thenReturn(CUSTOMER); - when(rs.getInt(TradeRowMapper.VERSION_COLUMN)).thenReturn(0); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/delimited/DelimitedFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/delimited/DelimitedFunctionalTests.java index 3a82ae0c6..e33a0eabe 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/delimited/DelimitedFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/delimited/DelimitedFunctionalTests.java @@ -40,7 +40,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; * @since 2.0 */ @SpringJUnitConfig(locations = { "/org/springframework/batch/samples/file/delimited/job/delimited.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) + "/simple-job-launcher-context.xml" }) class DelimitedFunctionalTests { @Autowired diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/fixed/FixedLengthFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/fixed/FixedLengthFunctionalTests.java index a588fd913..3ce89133d 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/fixed/FixedLengthFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/fixed/FixedLengthFunctionalTests.java @@ -33,7 +33,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.junit.jupiter.api.Assertions.assertEquals; @SpringJUnitConfig(locations = { "/org/springframework/batch/samples/file/fixed/job/fixedLength.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) + "/simple-job-launcher-context.xml" }) class FixedLengthFunctionalTests { @Autowired diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/multiline/MultiLineFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/multiline/MultiLineFunctionalTests.java index 985509303..cb3dcaf02 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/multiline/MultiLineFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/multiline/MultiLineFunctionalTests.java @@ -45,7 +45,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; * @since 2.0 */ @SpringJUnitConfig(locations = { "/org/springframework/batch/samples/file/multiline/job/multiLine.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) + "/simple-job-launcher-context.xml" }) class MultiLineFunctionalTests { private static final String INPUT_FILE = "org/springframework/batch/samples/file/multiline/data/multiLine.txt"; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/multilineaggregate/MultilineAggregateJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/multilineaggregate/MultilineAggregateJobFunctionalTests.java index 3521ade85..1f85659a6 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/multilineaggregate/MultilineAggregateJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/multilineaggregate/MultilineAggregateJobFunctionalTests.java @@ -31,7 +31,7 @@ import org.springframework.util.StringUtils; import static org.junit.jupiter.api.Assertions.assertEquals; @SpringJUnitConfig(locations = { "/org/springframework/batch/samples/file/multilineaggregate/job/multilineJob.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) + "/simple-job-launcher-context.xml" }) class MultilineAggregateJobFunctionalTests { @Autowired diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/multirecordtype/MultiRecordTypeFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/multirecordtype/MultiRecordTypeFunctionalTests.java index 5c6216676..8a1985d7e 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/multirecordtype/MultiRecordTypeFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/multirecordtype/MultiRecordTypeFunctionalTests.java @@ -45,7 +45,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; * @since 2.0 */ @SpringJUnitConfig(locations = { "/org/springframework/batch/samples/file/multirecordtype/job/multiRecordType.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) + "/simple-job-launcher-context.xml" }) class MultiRecordTypeFunctionalTests { private static final String OUTPUT_FILE = "target/test-outputs/multiRecordTypeOutput.txt"; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/multiresource/MultiResourceFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/multiresource/MultiResourceFunctionalTests.java index 21c9c9712..209ac5ce3 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/multiresource/MultiResourceFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/multiresource/MultiResourceFunctionalTests.java @@ -39,7 +39,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; * @since 2.0 */ @SpringJUnitConfig(locations = { "/org/springframework/batch/samples/file/multiresource/job/multiResource.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) + "/simple-job-launcher-context.xml" }) class MultiResourceFunctionalTests { @Autowired diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/patternmatching/PatternMatchingJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/patternmatching/PatternMatchingJobFunctionalTests.java index b5ff7ea69..6d6df834e 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/patternmatching/PatternMatchingJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/patternmatching/PatternMatchingJobFunctionalTests.java @@ -29,7 +29,7 @@ import org.springframework.core.io.FileSystemResource; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; @SpringJUnitConfig(locations = { "/org/springframework/batch/samples/file/patternmatching/job/multilineOrderJob.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) + "/simple-job-launcher-context.xml" }) class PatternMatchingJobFunctionalTests { private static final String ACTUAL = "target/test-outputs/multilineOrderOutput.txt"; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/patternmatching/internal/validator/OrderValidatorTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/patternmatching/internal/validator/OrderValidatorTests.java deleted file mode 100644 index 58b4ab9fa..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/patternmatching/internal/validator/OrderValidatorTests.java +++ /dev/null @@ -1,359 +0,0 @@ -/* - * Copyright 2014-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.samples.file.patternmatching.internal.validator; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import org.springframework.batch.samples.file.patternmatching.Address; -import org.springframework.batch.samples.file.patternmatching.BillingInfo; -import org.springframework.batch.samples.file.patternmatching.Customer; -import org.springframework.batch.samples.file.patternmatching.LineItem; -import org.springframework.batch.samples.file.patternmatching.Order; -import org.springframework.batch.samples.file.patternmatching.ShippingInfo; -import org.springframework.validation.BeanPropertyBindingResult; -import org.springframework.validation.Errors; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -class OrderValidatorTests { - - private OrderValidator orderValidator; - - @BeforeEach - void setUp() throws Exception { - orderValidator = new OrderValidator(); - } - - @Test - void testSupports() { - assertTrue(orderValidator.supports(Order.class)); - } - - @Test - void testNotAnOrder() { - String notAnOrder = "order"; - Errors errors = new BeanPropertyBindingResult(notAnOrder, "validOrder"); - - orderValidator.validate(notAnOrder, errors); - - assertEquals(1, errors.getAllErrors().size()); - assertEquals("Incorrect type", errors.getAllErrors().get(0).getCode()); - - errors = new BeanPropertyBindingResult(notAnOrder, "validOrder"); - - orderValidator.validate(null, errors); - assertEquals(0, errors.getAllErrors().size()); - } - - @Test - void testValidOrder() { - Order order = new Order(); - order.setOrderId(-5); - order.setOrderDate(new Date(new Date().getTime() + 1000000000L)); - order.setTotalLines(10); - order.setLineItems(new ArrayList<>()); - - Errors errors = new BeanPropertyBindingResult(order, "validOrder"); - - orderValidator.validateOrder(order, errors); - - assertEquals(3, errors.getAllErrors().size()); - assertEquals("error.order.id", errors.getFieldError("orderId").getCode()); - assertEquals("error.order.date.future", errors.getFieldError("orderDate").getCode()); - assertEquals("error.order.lines.badcount", errors.getFieldError("totalLines").getCode()); - - order = new Order(); - order.setOrderId(Long.MAX_VALUE); - order.setOrderDate(new Date(new Date().getTime() - 1000)); - order.setTotalLines(0); - List items = new ArrayList<>(); - items.add(new LineItem()); - order.setLineItems(items); - - errors = new BeanPropertyBindingResult(order, "validOrder"); - - orderValidator.validateOrder(order, errors); - - assertEquals(2, errors.getAllErrors().size()); - assertEquals("error.order.id", errors.getFieldError("orderId").getCode()); - assertEquals("error.order.lines.badcount", errors.getFieldError("totalLines").getCode()); - - order = new Order(); - order.setOrderId(5L); - order.setOrderDate(new Date(new Date().getTime() - 1000)); - order.setTotalLines(1); - items = new ArrayList<>(); - items.add(new LineItem()); - order.setLineItems(items); - - errors = new BeanPropertyBindingResult(order, "validOrder"); - - orderValidator.validateOrder(order, errors); - - assertEquals(0, errors.getAllErrors().size()); - } - - @Test - void testValidCustomer() { - Order order = new Order(); - Customer customer = new Customer(); - customer.setRegistered(false); - customer.setBusinessCustomer(true); - order.setCustomer(customer); - - Errors errors = new BeanPropertyBindingResult(order, "validOrder"); - orderValidator.validateCustomer(customer, errors); - - assertEquals(2, errors.getAllErrors().size()); - assertEquals("error.customer.registration", errors.getFieldError("customer.registered").getCode()); - assertEquals("error.customer.companyname", errors.getFieldError("customer.companyName").getCode()); - - customer = new Customer(); - customer.setRegistered(true); - customer.setBusinessCustomer(false); - customer.setRegistrationId(Long.MIN_VALUE); - order.setCustomer(customer); - - errors = new BeanPropertyBindingResult(order, "validOrder"); - orderValidator.validateCustomer(customer, errors); - - assertEquals(3, errors.getAllErrors().size()); - assertEquals("error.customer.firstname", errors.getFieldError("customer.firstName").getCode()); - assertEquals("error.customer.lastname", errors.getFieldError("customer.lastName").getCode()); - assertEquals("error.customer.registrationid", errors.getFieldError("customer.registrationId").getCode()); - - customer = new Customer(); - customer.setRegistered(true); - customer.setBusinessCustomer(false); - customer.setRegistrationId(Long.MAX_VALUE); - order.setCustomer(customer); - - errors = new BeanPropertyBindingResult(order, "validOrder"); - orderValidator.validateCustomer(customer, errors); - - assertEquals(3, errors.getAllErrors().size()); - assertEquals("error.customer.firstname", errors.getFieldError("customer.firstName").getCode()); - assertEquals("error.customer.lastname", errors.getFieldError("customer.lastName").getCode()); - assertEquals("error.customer.registrationid", errors.getFieldError("customer.registrationId").getCode()); - - customer = new Customer(); - customer.setRegistered(true); - customer.setBusinessCustomer(true); - customer.setCompanyName("Acme Inc"); - customer.setRegistrationId(5L); - order.setCustomer(customer); - - errors = new BeanPropertyBindingResult(order, "validOrder"); - orderValidator.validateCustomer(customer, errors); - - assertEquals(0, errors.getAllErrors().size()); - - customer = new Customer(); - customer.setRegistered(true); - customer.setBusinessCustomer(false); - customer.setFirstName("John"); - customer.setLastName("Doe"); - customer.setRegistrationId(5L); - order.setCustomer(customer); - - errors = new BeanPropertyBindingResult(order, "validOrder"); - orderValidator.validateCustomer(customer, errors); - - assertEquals(0, errors.getAllErrors().size()); - } - - @Test - void testValidAddress() { - Order order = new Order(); - - Errors errors = new BeanPropertyBindingResult(order, "validOrder"); - orderValidator.validateAddress(null, errors, "billingAddress"); - - assertEquals(0, errors.getAllErrors().size()); - - Address address = new Address(); - order.setBillingAddress(address); - - orderValidator.validateAddress(address, errors, "billingAddress"); - - assertEquals(4, errors.getAllErrors().size()); - assertEquals("error.baddress.addrline1.length", errors.getFieldError("billingAddress.addrLine1").getCode()); - assertEquals("error.baddress.city.length", errors.getFieldError("billingAddress.city").getCode()); - assertEquals("error.baddress.zipcode.length", errors.getFieldError("billingAddress.zipCode").getCode()); - assertEquals("error.baddress.country.length", errors.getFieldError("billingAddress.country").getCode()); - - address = new Address(); - address.setAddressee("1234567890123456789012345678901234567890123456789012345678901234567890"); - address.setAddrLine1("123456789012345678901234567890123456789012345678901234567890"); - address.setAddrLine2("123456789012345678901234567890123456789012345678901234567890"); - address.setCity("1234567890123456789012345678901234567890"); - address.setZipCode("1234567890"); - address.setState("1234567890"); - address.setCountry("123456789012345678901234567890123456789012345678901234567890"); - order.setBillingAddress(address); - - errors = new BeanPropertyBindingResult(order, "validOrder"); - orderValidator.validateAddress(address, errors, "billingAddress"); - - assertEquals(8, errors.getAllErrors().size()); - assertEquals("error.baddress.addresse.length", errors.getFieldError("billingAddress.addressee").getCode()); - assertEquals("error.baddress.addrline1.length", errors.getFieldError("billingAddress.addrLine1").getCode()); - assertEquals("error.baddress.addrline2.length", errors.getFieldError("billingAddress.addrLine2").getCode()); - assertEquals("error.baddress.city.length", errors.getFieldError("billingAddress.city").getCode()); - assertEquals("error.baddress.state.length", errors.getFieldError("billingAddress.state").getCode()); - assertEquals("error.baddress.zipcode.length", errors.getFieldErrors("billingAddress.zipCode").get(0).getCode()); - assertEquals("error.baddress.zipcode.format", errors.getFieldErrors("billingAddress.zipCode").get(1).getCode()); - assertEquals("error.baddress.country.length", errors.getFieldError("billingAddress.country").getCode()); - - address = new Address(); - address.setAddressee("John Doe"); - address.setAddrLine1("123 4th Street"); - address.setCity("Chicago"); - address.setState("IL"); - address.setZipCode("60606"); - address.setCountry("United States"); - order.setBillingAddress(address); - - errors = new BeanPropertyBindingResult(order, "validOrder"); - orderValidator.validateAddress(address, errors, "billingAddress"); - - assertEquals(0, errors.getAllErrors().size()); - } - - @Test - void testValidPayment() { - Order order = new Order(); - BillingInfo info = new BillingInfo(); - info.setPaymentId("INVALID"); - info.setPaymentDesc("INVALID"); - order.setBilling(info); - - Errors errors = new BeanPropertyBindingResult(order, "validOrder"); - orderValidator.validatePayment(info, errors); - - assertEquals(2, errors.getAllErrors().size()); - assertEquals("error.billing.type", errors.getFieldError("billing.paymentId").getCode()); - assertEquals("error.billing.desc", errors.getFieldError("billing.paymentDesc").getCode()); - - info = new BillingInfo(); - info.setPaymentId("VISA"); - info.setPaymentDesc("ADFI-1234567890"); - order.setBilling(info); - - errors = new BeanPropertyBindingResult(order, "validOrder"); - orderValidator.validatePayment(info, errors); - - assertEquals(0, errors.getAllErrors().size()); - } - - @Test - void testValidShipping() { - Order order = new Order(); - ShippingInfo info = new ShippingInfo(); - info.setShipperId("INVALID"); - info.setShippingTypeId("INVALID"); - order.setShipping(info); - - Errors errors = new BeanPropertyBindingResult(order, "validOrder"); - orderValidator.validateShipping(info, errors); - - assertEquals(2, errors.getAllErrors().size()); - assertEquals("error.shipping.shipper", errors.getFieldError("shipping.shipperId").getCode()); - assertEquals("error.shipping.type", errors.getFieldError("shipping.shippingTypeId").getCode()); - - info = new ShippingInfo(); - info.setShipperId("FEDX"); - info.setShippingTypeId("EXP"); - info.setShippingInfo( - "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); - order.setShipping(info); - - errors = new BeanPropertyBindingResult(order, "validOrder"); - orderValidator.validateShipping(info, errors); - - assertEquals(1, errors.getAllErrors().size()); - assertEquals("error.shipping.shippinginfo.length", errors.getFieldError("shipping.shippingInfo").getCode()); - - info = new ShippingInfo(); - info.setShipperId("FEDX"); - info.setShippingTypeId("EXP"); - info.setShippingInfo("Info"); - order.setShipping(info); - - errors = new BeanPropertyBindingResult(order, "validOrder"); - orderValidator.validateShipping(info, errors); - - assertEquals(0, errors.getAllErrors().size()); - } - - @Test - void testValidLineItems() { - Order order = new Order(); - List lineItems = new ArrayList<>(); - lineItems.add(buildLineItem(-5, 5.00, 0, 0, 2, 3, 3, 30)); - lineItems.add(buildLineItem(Long.MAX_VALUE, 5.00, 0, 0, 2, 3, 3, 30)); - lineItems.add(buildLineItem(6, -5.00, 0, 0, 2, 3, 3, 0)); - lineItems.add(buildLineItem(6, Integer.MAX_VALUE, 0, 0, 2, 3, 3, 30)); - lineItems.add(buildLineItem(6, 5.00, 900, 0, 2, 3, 3, 30)); - lineItems.add(buildLineItem(6, 5.00, -90, 0, 2, 3, 3, 30)); - lineItems.add(buildLineItem(6, 5.00, 10, 20, 2, 3, 3, 30)); - lineItems.add(buildLineItem(6, 5.00, 0, -10, 2, 3, 3, 30)); - lineItems.add(buildLineItem(6, 5.00, 0, 50, 2, 3, 3, 30)); - lineItems.add(buildLineItem(6, 5.00, 0, 0, -2, 3, 3, 30)); - lineItems.add(buildLineItem(6, 5.00, 0, 0, Long.MAX_VALUE, 3, 3, 30)); - lineItems.add(buildLineItem(6, 5.00, 0, 0, 2, -3, 3, 30)); - lineItems.add(buildLineItem(6, 5.00, 0, 0, 2, Long.MAX_VALUE, 3, 30)); - lineItems.add(buildLineItem(6, 5.00, 0, 0, 2, 3, -3, 30)); - lineItems.add(buildLineItem(6, 5.00, 0, 0, 2, 3, Integer.MAX_VALUE, 30)); - lineItems.add(buildLineItem(6, 5.00, 0, 0, 2, 3, 3, -5)); - lineItems.add(buildLineItem(6, 5.00, 0, 0, 2, 3, 3, Integer.MAX_VALUE)); - order.setLineItems(lineItems); - - Errors errors = new BeanPropertyBindingResult(order, "validOrder"); - orderValidator.validateLineItems(lineItems, errors); - - assertEquals(7, errors.getAllErrors().size()); - assertEquals("error.lineitems.id", errors.getFieldErrors("lineItems").get(0).getCode()); - assertEquals("error.lineitems.price", errors.getFieldErrors("lineItems").get(1).getCode()); - assertEquals("error.lineitems.discount", errors.getFieldErrors("lineItems").get(2).getCode()); - assertEquals("error.lineitems.shipping", errors.getFieldErrors("lineItems").get(3).getCode()); - assertEquals("error.lineitems.handling", errors.getFieldErrors("lineItems").get(4).getCode()); - assertEquals("error.lineitems.quantity", errors.getFieldErrors("lineItems").get(5).getCode()); - assertEquals("error.lineitems.totalprice", errors.getFieldErrors("lineItems").get(6).getCode()); - } - - private LineItem buildLineItem(long itemId, double price, int discountPercentage, int discountAmount, - long shippingPrice, long handlingPrice, int qty, int totalPrice) { - LineItem invalidId = new LineItem(); - invalidId.setItemId(itemId); - invalidId.setPrice(new BigDecimal(price)); - invalidId.setDiscountPerc(new BigDecimal(discountPercentage)); - invalidId.setDiscountAmount(new BigDecimal(discountAmount)); - invalidId.setShippingPrice(new BigDecimal(shippingPrice)); - invalidId.setHandlingPrice(new BigDecimal(handlingPrice)); - invalidId.setQuantity(qty); - invalidId.setTotalPrice(new BigDecimal(totalPrice)); - return invalidId; - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/xml/XmlFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/xml/XmlFunctionalTests.java index 6b4d86806..ea6d40ba5 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/xml/XmlFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/file/xml/XmlFunctionalTests.java @@ -38,8 +38,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; * @author Mahmoud Ben Hassine * @since 2.0 */ -@SpringJUnitConfig(locations = { "/org/springframework/batch/samples/file/xml/job/xml.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) +@SpringJUnitConfig( + locations = { "/org/springframework/batch/samples/file/xml/job/xml.xml", "/simple-job-launcher-context.xml" }) class XmlFunctionalTests { @Autowired diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/filter/CustomerFilterJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/filter/CustomerFilterJobFunctionalTests.java index 834b5059d..bd97db549 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/filter/CustomerFilterJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/filter/CustomerFilterJobFunctionalTests.java @@ -37,7 +37,7 @@ import org.springframework.test.jdbc.JdbcTestUtils; import static org.junit.jupiter.api.Assertions.assertEquals; @SpringJUnitConfig(locations = { "/org/springframework/batch/samples/filter/job/customerFilterJob.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) + "/simple-job-launcher-context.xml" }) class CustomerFilterJobFunctionalTests { private static final String GET_CUSTOMERS = "select NAME, CREDIT from CUSTOMER order by NAME"; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/football/FootballJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/football/FootballJobFunctionalTests.java index f065943c4..c8aa20778 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/football/FootballJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/football/FootballJobFunctionalTests.java @@ -33,7 +33,7 @@ import org.springframework.test.jdbc.JdbcTestUtils; import static org.junit.jupiter.api.Assertions.assertTrue; @SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", - "/org/springframework/batch/samples/football/job/footballJob.xml", "/job-runner-context.xml" }) + "/org/springframework/batch/samples/football/job/footballJob.xml" }) class FootballJobFunctionalTests { @Autowired diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/football/internal/JdbcGameDaoIntegrationTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/football/internal/JdbcGameDaoIntegrationTests.java deleted file mode 100644 index 260d8cf84..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/football/internal/JdbcGameDaoIntegrationTests.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2006-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.samples.football.internal; - -import java.sql.ResultSet; -import java.sql.SQLException; - -import javax.sql.DataSource; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import org.springframework.batch.item.Chunk; -import org.springframework.batch.samples.football.Game; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.JdbcOperations; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowMapper; -import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -import org.springframework.transaction.annotation.Transactional; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * @author Lucas Ward - * @author Mahmoud Ben Hassine - * @author Glenn Renfro - * - */ - -@SpringJUnitConfig(locations = { "/data-source-context.xml" }) -class JdbcGameDaoIntegrationTests { - - private JdbcGameDao gameDao; - - private final Game game = new Game(); - - private JdbcOperations jdbcTemplate; - - @Autowired - public void setDataSource(DataSource dataSource) { - this.jdbcTemplate = new JdbcTemplate(dataSource); - gameDao = new JdbcGameDao(); - gameDao.setDataSource(dataSource); - gameDao.afterPropertiesSet(); - } - - @BeforeEach - void onSetUpBeforeTransaction() throws Exception { - game.setId("XXXXX00"); - game.setYear(1996); - game.setTeam("mia"); - game.setWeek(10); - game.setOpponent("nwe"); - game.setAttempts(0); - game.setCompletes(0); - game.setPassingYards(0); - game.setPassingTd(0); - game.setInterceptions(0); - game.setRushes(29); - game.setRushYards(109); - game.setReceptions(1); - game.setReceptionYards(16); - game.setTotalTd(2); - } - - @Transactional - @Test - void testWrite() { - gameDao.write(Chunk.of(game)); - - Game tempGame = jdbcTemplate.queryForObject("SELECT * FROM GAMES where PLAYER_ID=? AND YEAR_NO=?", - new GameRowMapper(), "XXXXX00 ", game.getYear()); - assertEquals(tempGame, game); - } - - private static class GameRowMapper implements RowMapper { - - @Override - public Game mapRow(ResultSet rs, int arg1) throws SQLException { - if (rs == null) { - return null; - } - - Game game = new Game(); - game.setId(rs.getString("PLAYER_ID").trim()); - game.setYear(rs.getInt("year_no")); - game.setTeam(rs.getString("team")); - game.setWeek(rs.getInt("week")); - game.setOpponent(rs.getString("opponent")); - game.setCompletes(rs.getInt("completes")); - game.setAttempts(rs.getInt("attempts")); - game.setPassingYards(rs.getInt("passing_Yards")); - game.setPassingTd(rs.getInt("passing_Td")); - game.setInterceptions(rs.getInt("interceptions")); - game.setRushes(rs.getInt("rushes")); - game.setRushYards(rs.getInt("rush_Yards")); - game.setReceptions(rs.getInt("receptions")); - game.setReceptionYards(rs.getInt("receptions_Yards")); - game.setTotalTd(rs.getInt("total_Td")); - - return game; - } - - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/football/internal/JdbcPlayerDaoIntegrationTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/football/internal/JdbcPlayerDaoIntegrationTests.java deleted file mode 100644 index 414c7aa0e..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/football/internal/JdbcPlayerDaoIntegrationTests.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2006-2023 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.samples.football.internal; - -import javax.sql.DataSource; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import org.springframework.batch.samples.football.Player; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -import org.springframework.test.jdbc.JdbcTestUtils; -import org.springframework.transaction.annotation.Transactional; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * @author Lucas Ward - * @author Mahmoud Ben Hassine - * @author Glenn Renfro - * - */ -@SpringJUnitConfig(locations = { "/data-source-context.xml" }) -class JdbcPlayerDaoIntegrationTests { - - private JdbcPlayerDao playerDao; - - private Player player; - - private static final String GET_PLAYER = "SELECT * from PLAYERS"; - - private JdbcTemplate jdbcTemplate; - - @Autowired - public void init(DataSource dataSource) { - this.jdbcTemplate = new JdbcTemplate(dataSource); - playerDao = new JdbcPlayerDao(); - playerDao.setDataSource(dataSource); - - player = new Player(); - player.setId("AKFJDL00"); - player.setFirstName("John"); - player.setLastName("Doe"); - player.setPosition("QB"); - player.setBirthYear(1975); - player.setDebutYear(1998); - } - - @BeforeEach - void onSetUpInTransaction() { - JdbcTestUtils.deleteFromTables(jdbcTemplate, "PLAYERS"); - } - - @Test - @Transactional - void testSavePlayer() { - playerDao.savePlayer(player); - jdbcTemplate.query(GET_PLAYER, rs -> { - assertEquals(rs.getString("PLAYER_ID"), "AKFJDL00"); - assertEquals(rs.getString("LAST_NAME"), "Doe"); - assertEquals(rs.getString("FIRST_NAME"), "John"); - assertEquals(rs.getString("POS"), "QB"); - assertEquals(rs.getInt("YEAR_OF_BIRTH"), 1975); - assertEquals(rs.getInt("YEAR_DRAFTED"), 1998); - }); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/football/internal/JdbcPlayerSummaryDaoIntegrationTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/football/internal/JdbcPlayerSummaryDaoIntegrationTests.java deleted file mode 100644 index faf9e937f..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/football/internal/JdbcPlayerSummaryDaoIntegrationTests.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2006-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.samples.football.internal; - -import javax.sql.DataSource; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import org.springframework.batch.item.Chunk; -import org.springframework.batch.samples.football.PlayerSummary; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -import org.springframework.test.jdbc.JdbcTestUtils; -import org.springframework.transaction.annotation.Transactional; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * @author Lucas Ward - * @author Mahmoud Ben Hassine - * @author Glenn Renfro - * - */ -@SpringJUnitConfig(locations = { "/data-source-context.xml" }) -class JdbcPlayerSummaryDaoIntegrationTests { - - private JdbcPlayerSummaryDao playerSummaryDao; - - private PlayerSummary summary; - - private JdbcTemplate jdbcTemplate; - - @Autowired - public void init(DataSource dataSource) { - this.jdbcTemplate = new JdbcTemplate(dataSource); - playerSummaryDao = new JdbcPlayerSummaryDao(); - playerSummaryDao.setDataSource(dataSource); - - summary = new PlayerSummary(); - summary.setId("AikmTr00"); - summary.setYear(1997); - summary.setCompletes(294); - summary.setAttempts(517); - summary.setPassingYards(3283); - summary.setPassingTd(19); - summary.setInterceptions(12); - summary.setRushes(25); - summary.setRushYards(79); - summary.setReceptions(0); - summary.setReceptionYards(0); - summary.setTotalTd(0); - } - - @BeforeEach - void onSetUpInTransaction() { - JdbcTestUtils.deleteFromTables(jdbcTemplate, "PLAYER_SUMMARY"); - } - - @Test - @Transactional - void testWrite() { - playerSummaryDao.write(Chunk.of(summary)); - - PlayerSummary testSummary = jdbcTemplate.queryForObject("SELECT * FROM PLAYER_SUMMARY", - new PlayerSummaryMapper()); - - assertEquals(summary, testSummary); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/headerfooter/HeaderFooterSampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/headerfooter/HeaderFooterSampleFunctionalTests.java index 8333d3a0b..0ebf63b7f 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/headerfooter/HeaderFooterSampleFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/headerfooter/HeaderFooterSampleFunctionalTests.java @@ -29,7 +29,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.springframework.test.util.AssertionErrors.assertTrue; @SpringJUnitConfig(locations = { "/org/springframework/batch/samples/headerfooter/job/headerFooterSample.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) + "/simple-job-launcher-context.xml" }) class HeaderFooterSampleFunctionalTests { @Autowired diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/jdbc/JdbcCursorFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/jdbc/JdbcCursorFunctionalTests.java index baa4cccbc..cf8f0463d 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/jdbc/JdbcCursorFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/jdbc/JdbcCursorFunctionalTests.java @@ -39,7 +39,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; * @since 2.0 */ @SpringJUnitConfig(locations = { "/org/springframework/batch/samples/jdbc/job/jdbcCursor.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) + "/simple-job-launcher-context.xml" }) class JdbcCursorFunctionalTests { @Autowired diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/jdbc/JdbcPagingFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/jdbc/JdbcPagingFunctionalTests.java index 95cdbdd27..cda54a445 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/jdbc/JdbcPagingFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/jdbc/JdbcPagingFunctionalTests.java @@ -39,7 +39,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; * @author Mahmoud Ben Hassine * @since 2.0 */ -@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/job-runner-context.xml", +@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/org/springframework/batch/samples/jdbc/job/jdbcPaging.xml" }) class JdbcPagingFunctionalTests { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/jobstep/JobStepFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/jobstep/JobStepFunctionalTests.java index 7d8407d89..925b79316 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/jobstep/JobStepFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/jobstep/JobStepFunctionalTests.java @@ -40,7 +40,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; */ @SpringJUnitConfig(locations = { "classpath:/org/springframework/batch/samples/jobstep/job/jobStepSample.xml", - "classpath:/simple-job-launcher-context.xml", "/job-runner-context.xml" }) + "classpath:/simple-job-launcher-context.xml" }) class JobStepFunctionalTests { @Autowired diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/jpa/JpaFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/jpa/JpaFunctionalTests.java index e42e57e54..e1d9a8373 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/jpa/JpaFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/jpa/JpaFunctionalTests.java @@ -22,7 +22,6 @@ import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.launch.JobLauncher; -import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -30,16 +29,13 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.junit.jupiter.api.Assertions.assertEquals; -@SpringJUnitConfig(locations = { "/org/springframework/batch/samples/jpa/job/jpa.xml", "/job-runner-context.xml" }) +@SpringJUnitConfig(locations = { "/org/springframework/batch/samples/jpa/job/jpa.xml" }) class JpaFunctionalTests { - @Autowired - private JobLauncherTestUtils jobLauncherTestUtils; - @Test - void testLaunchJobWithXmlConfig() throws Exception { + void testLaunchJobWithXmlConfig(@Autowired JobLauncher jobLauncher, @Autowired Job job) throws Exception { // when - JobExecution jobExecution = this.jobLauncherTestUtils.launchJob(); + JobExecution jobExecution = jobLauncher.run(job, new JobParameters()); // then assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/jpa/RepositoryFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/jpa/RepositoryFunctionalTests.java index d3d516d2e..56cb54eb1 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/jpa/RepositoryFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/jpa/RepositoryFunctionalTests.java @@ -23,7 +23,6 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.launch.JobLauncher; -import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -31,20 +30,16 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.junit.jupiter.api.Assertions.assertEquals; -@SpringJUnitConfig( - locations = { "/org/springframework/batch/samples/jpa/job/repository.xml", "/job-runner-context.xml" }) +@SpringJUnitConfig(locations = { "/org/springframework/batch/samples/jpa/job/repository.xml" }) class RepositoryFunctionalTests { - @Autowired - private JobLauncherTestUtils jobLauncherTestUtils; - @Test - void testLaunchJobWithXmlConfig() throws Exception { + void testLaunchJobWithXmlConfig(@Autowired JobLauncher jobLauncher, @Autowired Job job) throws Exception { // given JobParameters jobParameters = new JobParametersBuilder().addDouble("credit", 10000D).toJobParameters(); // when - JobExecution jobExecution = this.jobLauncherTestUtils.launchJob(jobParameters); + JobExecution jobExecution = jobLauncher.run(job, jobParameters); // then assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/loop/LoopFlowSampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/loop/LoopFlowSampleFunctionalTests.java index 921dd51fb..910ebabe9 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/loop/LoopFlowSampleFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/loop/LoopFlowSampleFunctionalTests.java @@ -34,7 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; */ @SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", - "/org/springframework/batch/samples/loop/loopFlowSample.xml", "/job-runner-context.xml" }) + "/org/springframework/batch/samples/loop/loopFlowSample.xml" }) class LoopFlowSampleFunctionalTests { @Autowired diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/mail/MailJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/mail/MailJobFunctionalTests.java index 7a2f3e374..a9d57ce1d 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/mail/MailJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/mail/MailJobFunctionalTests.java @@ -43,8 +43,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; * @author Glenn Renfro * @since 2.1 */ -@SpringJUnitConfig(locations = { "/org/springframework/batch/samples/mail/mailJob.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) +@SpringJUnitConfig( + locations = { "/org/springframework/batch/samples/mail/mailJob.xml", "/simple-job-launcher-context.xml" }) class MailJobFunctionalTests { private static final String email = "to@company.com"; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/misc/groovy/GroovyJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/misc/groovy/GroovyJobFunctionalTests.java index 1c41543bc..82f75cc4f 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/misc/groovy/GroovyJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/misc/groovy/GroovyJobFunctionalTests.java @@ -31,7 +31,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @SpringJUnitConfig(locations = { "/org/springframework/batch/samples/misc/groovy/job/groovyJob.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) + "/simple-job-launcher-context.xml" }) public class GroovyJobFunctionalTests { @Autowired diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/misc/jmx/JobExecutionNotificationPublisherTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/misc/jmx/JobExecutionNotificationPublisherTests.java deleted file mode 100644 index b5704eb27..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/misc/jmx/JobExecutionNotificationPublisherTests.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2006-2023 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.samples.misc.jmx; - -import org.junit.jupiter.api.Test; - -import javax.management.Notification; -import java.util.ArrayList; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * @author Dave Syer - * @author Thomas Risberg - * @author Glenn Renfro - * @author Mahmoud Ben Hassine - * - */ -class JobExecutionNotificationPublisherTests { - - private final JobExecutionNotificationPublisher publisher = new JobExecutionNotificationPublisher(); - - @Test - void testRepeatOperationsOpenUsed() { - final List list = new ArrayList<>(); - - publisher.setNotificationPublisher(list::add); - - publisher.onApplicationEvent(new SimpleMessageApplicationEvent(this, "foo")); - assertEquals(1, list.size()); - String message = list.get(0).getMessage(); - assertTrue(message.contains("foo"), "Message does not contain 'foo': "); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/file/PartitionFileJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/file/PartitionFileJobFunctionalTests.java index 6b838ccfe..7b02c1937 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/file/PartitionFileJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/file/PartitionFileJobFunctionalTests.java @@ -42,7 +42,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @SpringJUnitConfig(locations = { "/org/springframework/batch/samples/partition/file/job/partitionFileJob.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) + "/simple-job-launcher-context.xml" }) class PartitionFileJobFunctionalTests implements ApplicationContextAware { @Autowired diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/jdbc/PartitionJdbcJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/jdbc/PartitionJdbcJobFunctionalTests.java index 23f694ce5..97719a96d 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/jdbc/PartitionJdbcJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/jdbc/PartitionJdbcJobFunctionalTests.java @@ -42,7 +42,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @SpringJUnitConfig(locations = { "/org/springframework/batch/samples/partition/jdbc/partitionJdbcJob.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) + "/simple-job-launcher-context.xml" }) class PartitionJdbcJobFunctionalTests implements ApplicationContextAware { @Autowired diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/remote/RemotePartitioningJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/remote/RemotePartitioningJobFunctionalTests.java index da2783214..19057666b 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/remote/RemotePartitioningJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/remote/RemotePartitioningJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 the original author or authors. + * Copyright 2018-2023 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. @@ -27,7 +27,8 @@ import org.junit.jupiter.api.Test; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; -import org.springframework.batch.test.JobLauncherTestUtils; +import org.springframework.batch.core.JobParameters; +import org.springframework.batch.core.launch.JobLauncher; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -49,13 +50,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @PropertySource("classpath:org/springframework/batch/samples/partitioning/remote/remote-partitioning.properties") public abstract class RemotePartitioningJobFunctionalTests { - private static final String BROKER_DATA_DIRECTORY = "target/activemq-data"; - @Value("${broker.url}") private String brokerUrl; @Autowired - protected JobLauncherTestUtils jobLauncherTestUtils; + protected JobLauncher jobLauncher; @Autowired private DataSource dataSource; @@ -83,11 +82,8 @@ public abstract class RemotePartitioningJobFunctionalTests { @Test void testRemotePartitioningJob(@Autowired Job job) throws Exception { - // given - this.jobLauncherTestUtils.setJob(job); - // when - JobExecution jobExecution = this.jobLauncherTestUtils.launchJob(); + JobExecution jobExecution = this.jobLauncher.run(job, new JobParameters()); // then assertEquals(ExitStatus.COMPLETED.getExitCode(), jobExecution.getExitStatus().getExitCode()); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/remote/RemotePartitioningJobWithMessageAggregationFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/remote/RemotePartitioningJobWithMessageAggregationFunctionalTests.java index 7daefb59b..d9b4bfde2 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/remote/RemotePartitioningJobWithMessageAggregationFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/remote/RemotePartitioningJobWithMessageAggregationFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 the original author or authors. + * Copyright 2018-2023 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. @@ -15,7 +15,6 @@ */ package org.springframework.batch.samples.partition.remote; -import org.springframework.batch.samples.config.JobRunnerConfiguration; import org.springframework.batch.samples.partitioning.remote.aggregating.ManagerConfiguration; import org.springframework.batch.samples.partitioning.remote.aggregating.WorkerConfiguration; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; @@ -25,7 +24,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; * * @author Mahmoud Ben Hassine */ -@SpringJUnitConfig(classes = { JobRunnerConfiguration.class, ManagerConfiguration.class }) +@SpringJUnitConfig(classes = { ManagerConfiguration.class }) class RemotePartitioningJobWithMessageAggregationFunctionalTests extends RemotePartitioningJobFunctionalTests { @Override diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/remote/RemotePartitioningJobWithRepositoryPollingFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/remote/RemotePartitioningJobWithRepositoryPollingFunctionalTests.java index e926da48f..c2ad3c6ee 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/remote/RemotePartitioningJobWithRepositoryPollingFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/remote/RemotePartitioningJobWithRepositoryPollingFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 the original author or authors. + * Copyright 2018-2023 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. @@ -15,7 +15,6 @@ */ package org.springframework.batch.samples.partition.remote; -import org.springframework.batch.samples.config.JobRunnerConfiguration; import org.springframework.batch.samples.partitioning.remote.polling.ManagerConfiguration; import org.springframework.batch.samples.partitioning.remote.polling.WorkerConfiguration; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; @@ -25,7 +24,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; * * @author Mahmoud Ben Hassine */ -@SpringJUnitConfig(classes = { JobRunnerConfiguration.class, ManagerConfiguration.class }) +@SpringJUnitConfig(classes = { ManagerConfiguration.class }) class RemotePartitioningJobWithRepositoryPollingFunctionalTests extends RemotePartitioningJobFunctionalTests { @Override diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/processindicator/ProcessIndicatorJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/processindicator/ProcessIndicatorJobFunctionalTests.java index dcf717f53..221d658d2 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/processindicator/ProcessIndicatorJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/processindicator/ProcessIndicatorJobFunctionalTests.java @@ -31,7 +31,7 @@ import org.springframework.test.jdbc.JdbcTestUtils; import static org.junit.jupiter.api.Assertions.assertEquals; @SpringJUnitConfig(locations = { "/org/springframework/batch/samples/processindicator/job/parallelJob.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) + "/simple-job-launcher-context.xml" }) class ProcessIndicatorJobFunctionalTests { @Autowired diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/restart/fail/RestartFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/restart/fail/RestartFunctionalTests.java index 916359e3d..2efbe557b 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/restart/fail/RestartFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/restart/fail/RestartFunctionalTests.java @@ -43,7 +43,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * @author Glenn Renfro */ @SpringJUnitConfig(locations = { "/org/springframework/batch/samples/restart/fail/job/failRestartSample.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) + "/simple-job-launcher-context.xml" }) class RestartFunctionalTests { private JdbcTemplate jdbcTemplate; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/restart/stop/GracefulShutdownFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/restart/stop/GracefulShutdownFunctionalTests.java index d70c04de4..20c8a11e0 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/restart/stop/GracefulShutdownFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/restart/stop/GracefulShutdownFunctionalTests.java @@ -44,7 +44,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * */ @SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", - "/org/springframework/batch/samples/restart/stop/stopRestartSample.xml", "/job-runner-context.xml" }) + "/org/springframework/batch/samples/restart/stop/stopRestartSample.xml" }) class GracefulShutdownFunctionalTests { /** Logger */ diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/retry/RetrySampleConfigurationTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/retry/RetrySampleConfigurationTests.java deleted file mode 100644 index 4aace6233..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/retry/RetrySampleConfigurationTests.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2012-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.samples.retry; - -import org.junit.jupiter.api.Test; - -import org.springframework.batch.core.Job; -import org.springframework.batch.samples.config.DataSourceConfiguration; -import org.springframework.batch.samples.config.JobRunnerConfiguration; -import org.springframework.batch.samples.domain.trade.internal.GeneratingTradeItemReader; -import org.springframework.batch.samples.support.RetrySampleItemWriter; -import org.springframework.batch.test.JobLauncherTestUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * Checks that expected number of items have been processed. - * - * @author Robert Kasanicky - * @author Dave Syer - * @author Mahmoud Ben Hassine - * @author Glenn Renfro - */ -@SpringJUnitConfig( - classes = { DataSourceConfiguration.class, RetrySampleConfiguration.class, JobRunnerConfiguration.class }) -class RetrySampleConfigurationTests { - - @Autowired - private GeneratingTradeItemReader itemGenerator; - - @Autowired - private RetrySampleItemWriter itemProcessor; - - @Autowired - private JobLauncherTestUtils jobLauncherTestUtils; - - @Test - void testLaunchJob(@Autowired Job job) throws Exception { - this.jobLauncherTestUtils.setJob(job); - this.jobLauncherTestUtils.launchJob(); - // items processed = items read + 2 exceptions - assertEquals(itemGenerator.getLimit() + 2, itemProcessor.getCounter()); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/retry/RetrySampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/retry/RetrySampleFunctionalTests.java index 590291648..48fdb57b9 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/retry/RetrySampleFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/retry/RetrySampleFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2022 the original author or authors. + * Copyright 2008-2023 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. @@ -17,10 +17,17 @@ package org.springframework.batch.samples.retry; import org.junit.jupiter.api.Test; +import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.Job; +import org.springframework.batch.core.JobExecution; +import org.springframework.batch.core.JobParameters; +import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.samples.domain.trade.internal.GeneratingTradeItemReader; import org.springframework.batch.samples.support.RetrySampleItemWriter; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -33,8 +40,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; * @author Glenn Renfro */ -@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", - "/org/springframework/batch/samples/retry/retrySample.xml", "/job-runner-context.xml" }) +@SpringJUnitConfig( + locations = { "/simple-job-launcher-context.xml", "/org/springframework/batch/samples/retry/retrySample.xml" }) class RetrySampleFunctionalTests { @Autowired @@ -47,10 +54,28 @@ class RetrySampleFunctionalTests { private JobLauncherTestUtils jobLauncherTestUtils; @Test - void testLaunchJob() throws Exception { + void testLaunchJobWithXmlConfig() throws Exception { this.jobLauncherTestUtils.launchJob(); // items processed = items read + 2 exceptions assertEquals(itemGenerator.getLimit() + 2, itemProcessor.getCounter()); } + @Test + public void testLaunchJobWithJavaConfig() throws Exception { + // given + ApplicationContext context = new AnnotationConfigApplicationContext(RetrySampleConfiguration.class); + JobLauncher jobLauncher = context.getBean(JobLauncher.class); + Job job = context.getBean(Job.class); + GeneratingTradeItemReader itemGenerator = context.getBean(GeneratingTradeItemReader.class); + RetrySampleItemWriter itemProcessor = context.getBean(RetrySampleItemWriter.class); + + // when + JobExecution jobExecution = jobLauncher.run(job, new JobParameters()); + + // then + assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); + // items processed = items read + 2 exceptions + assertEquals(itemGenerator.getLimit() + 2, itemProcessor.getCounter()); + } + } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/support/AbstractFieldSetMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/support/AbstractFieldSetMapperTests.java deleted file mode 100644 index 123c252b9..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/support/AbstractFieldSetMapperTests.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.samples.support; - -import org.junit.jupiter.api.Test; - -import org.springframework.batch.item.file.mapping.FieldSetMapper; -import org.springframework.batch.item.file.transform.FieldSet; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * Encapsulates basic logic for testing custom {@link FieldSetMapper} implementations. - * - * @author Robert Kasanicky - * @author Glenn Renfro - */ -public abstract class AbstractFieldSetMapperTests { - - /** - * @return FieldSet used for mapping - */ - protected abstract FieldSet fieldSet(); - - /** - * @return domain object excepted as a result of mapping the FieldSet - * returned by this.fieldSet() - */ - protected abstract Object expectedDomainObject(); - - /** - * @return mapper which takes this.fieldSet() and maps it to domain - * object. - */ - protected abstract FieldSetMapper fieldSetMapper(); - - /** - * Regular usage scenario. Assumes the domain object implements sensible - * equals(Object other) - */ - @Test - void testRegularUse() throws Exception { - assertEquals(expectedDomainObject(), fieldSetMapper().mapFieldSet(fieldSet())); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/support/AbstractRowMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/support/AbstractRowMapperTests.java deleted file mode 100644 index 5b9ef3cbf..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/support/AbstractRowMapperTests.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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.samples.support; - -import java.sql.ResultSet; -import java.sql.SQLException; - -import org.junit.jupiter.api.Test; - -import org.springframework.jdbc.core.RowMapper; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.mock; - -/** - * Encapsulates logic for testing custom {@link RowMapper} implementations. - * - * @author Robert Kasanicky - * @author Glenn Renfro - * @param the item type - */ -public abstract class AbstractRowMapperTests { - - // row number should be irrelevant - private static final int IGNORED_ROW_NUMBER = 0; - - // mock result set - private final ResultSet rs = mock(); - - /** - * @return Expected result of mapping the mock ResultSet by the mapper - * being tested. - */ - abstract protected T expectedDomainObject(); - - /** - * @return RowMapper implementation that is being tested. - */ - abstract protected RowMapper rowMapper(); - - /* - * Define the behaviour of mock ResultSet. - */ - abstract protected void setUpResultSetMock(ResultSet rs) throws SQLException; - - /* - * Regular usage scenario. - */ - @Test - void testRegularUse() throws SQLException { - setUpResultSetMock(rs); - - assertEquals(expectedDomainObject(), rowMapper().mapRow(rs, IGNORED_ROW_NUMBER)); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/support/ItemTrackingItemWriterTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/support/ItemTrackingItemWriterTests.java deleted file mode 100644 index 21c484cfa..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/support/ItemTrackingItemWriterTests.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2006-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.samples.support; - -import org.junit.jupiter.api.Test; -import org.springframework.batch.item.Chunk; -import org.springframework.batch.samples.domain.trade.Trade; -import org.springframework.batch.samples.domain.trade.internal.ItemTrackingTradeItemWriter; - -import java.io.IOException; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -/** - * @author Dave Syer - * @author Mahmoud Ben Hassine - * @author Glenn Renfro - * - */ -class ItemTrackingItemWriterTests { - - private final ItemTrackingTradeItemWriter writer = new ItemTrackingTradeItemWriter(); - - @Test - void testWrite() throws Exception { - assertEquals(0, writer.getItems().size()); - Trade a = new Trade("a", 0, null, null); - Trade b = new Trade("b", 0, null, null); - Trade c = new Trade("c", 0, null, null); - writer.write(Chunk.of(a, b, c)); - assertEquals(3, writer.getItems().size()); - } - - @Test - void testWriteFailure() throws Exception { - writer.setWriteFailureISIN("c"); - Trade a = new Trade("a", 0, null, null); - Trade b = new Trade("b", 0, null, null); - Trade c = new Trade("c", 0, null, null); - assertThrows(IOException.class, () -> writer.write(Chunk.of(a, b, c))); - assertEquals(0, writer.getItems().size()); - - Trade e = new Trade("e", 0, null, null); - Trade f = new Trade("f", 0, null, null); - Trade g = new Trade("g", 0, null, null); - writer.write(Chunk.of(e, f, g)); - assertEquals(3, writer.getItems().size()); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/support/RetrySampleItemWriterTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/support/RetrySampleItemWriterTests.java deleted file mode 100644 index 06022cec8..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/support/RetrySampleItemWriterTests.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.samples.support; - -import org.junit.jupiter.api.Test; -import org.springframework.batch.item.Chunk; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -/** - * Tests for {@link RetrySampleItemWriter}. - * - * @author Robert Kasanicky - * @author Mahmoud Ben Hassine - */ -class RetrySampleItemWriterTests { - - private final RetrySampleItemWriter processor = new RetrySampleItemWriter<>(); - - /* - * Processing throws exception on 2nd and 3rd call. - */ - @Test - void testProcess() throws Exception { - Object item = null; - processor.write(Chunk.of(item)); - - assertThrows(RuntimeException.class, () -> processor.write(Chunk.of(item, item, item))); - - processor.write(Chunk.of(item)); - - assertEquals(5, processor.getCounter()); - } - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/trade/TradeJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/trade/TradeJobFunctionalTests.java index fa2d9ce05..88297d303 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/trade/TradeJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/trade/TradeJobFunctionalTests.java @@ -37,8 +37,8 @@ import org.springframework.test.jdbc.JdbcTestUtils; import static org.junit.jupiter.api.Assertions.assertEquals; -@SpringJUnitConfig(locations = { "/org/springframework/batch/samples/trade/job/tradeJob.xml", - "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) +@SpringJUnitConfig( + locations = { "/org/springframework/batch/samples/trade/job/tradeJob.xml", "/simple-job-launcher-context.xml" }) class TradeJobFunctionalTests { private static final String GET_TRADES = "select ISIN, QUANTITY, PRICE, CUSTOMER, ID, VERSION from TRADE order by ISIN";