Update samples
- Restructure contexts - Remove unused resources - Remove irrelevant tests Issue #4329
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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).<Trade, Object>chunk(1, this.transactionManager)
|
||||
protected Step step(JobRepository jobRepository, JdbcTransactionManager transactionManager) {
|
||||
return new StepBuilder("step", jobRepository).<Trade, Object>chunk(1, transactionManager)
|
||||
.reader(reader())
|
||||
.writer(writer())
|
||||
.faultTolerant()
|
||||
@@ -60,15 +58,28 @@ public class RetrySampleConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
protected ItemReader<Trade> reader() {
|
||||
protected GeneratingTradeItemReader reader() {
|
||||
GeneratingTradeItemReader reader = new GeneratingTradeItemReader();
|
||||
reader.setLimit(10);
|
||||
return reader;
|
||||
}
|
||||
|
||||
@Bean
|
||||
protected ItemWriter<Object> writer() {
|
||||
protected RetrySampleItemWriter<Object> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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_
|
||||
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
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">
|
||||
|
||||
<bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
|
||||
<property name="customEditors">
|
||||
<map>
|
||||
<entry key="int[]" value="org.springframework.batch.support.IntArrayPropertyEditor" />
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -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">
|
||||
|
||||
<!-- Initialise the database before every test case: -->
|
||||
<jdbc:initialize-database data-source="dataSource">
|
||||
<jdbc:script location="${batch.drop.script}"/>
|
||||
<jdbc:script location="${batch.schema.script}"/>
|
||||
<jdbc:script location="${batch.business.schema.script}"/>
|
||||
</jdbc:initialize-database>
|
||||
<jdbc:initialize-database>
|
||||
<jdbc:script location="org/springframework/batch/core/schema-drop-hsqldb.sql"/>
|
||||
<jdbc:script location="org/springframework/batch/core/schema-hsqldb.sql"/>
|
||||
<jdbc:script location="org/springframework/batch/samples/common/business-schema-hsqldb.sql"/>
|
||||
</jdbc:initialize-database>
|
||||
|
||||
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
|
||||
<property name="driverClassName" value="${batch.jdbc.driver}" />
|
||||
<property name="url" value="${batch.jdbc.url}" />
|
||||
<property name="username" value="${batch.jdbc.user}" />
|
||||
<property name="password" value="${batch.jdbc.password}" />
|
||||
<property name="maxTotal" value="${batch.jdbc.pool.size}"/>
|
||||
<property name="validationQuery" value="${batch.jdbc.validationQuery}"/>
|
||||
<property name="testWhileIdle" value="${batch.jdbc.testWhileIdle}"/>
|
||||
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
|
||||
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
|
||||
<property name="url" value="jdbc:hsqldb:mem:testdb;sql.enforce_strict_size=true;hsqldb.tx=mvcc" />
|
||||
<property name="username" value="sa" />
|
||||
<property name="password" value="" />
|
||||
</bean>
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.jdbc.support.JdbcTransactionManager" lazy-init="true">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<!-- Set up or detect a System property called "ENVIRONMENT" used to construct a properties file on the classpath. The default is "hsql". -->
|
||||
<bean id="environment"
|
||||
class="org.springframework.batch.support.SystemPropertyInitializer">
|
||||
<property name="defaultValue" value="hsql"/>
|
||||
<property name="keyName" value="ENVIRONMENT"/>
|
||||
</bean>
|
||||
|
||||
<!-- Use this to set additional properties on beans at run time -->
|
||||
<bean id="overrideProperties" class="org.springframework.beans.factory.config.PropertyOverrideConfigurer"
|
||||
depends-on="environment">
|
||||
<property name="location" value="classpath:batch-${ENVIRONMENT}.properties" />
|
||||
<!-- Allow system properties (-D) to override those from file -->
|
||||
<property name="localOverride" value="true" />
|
||||
<property name="properties">
|
||||
<bean class="java.lang.System" factory-method="getProperties" />
|
||||
</property>
|
||||
<property name="ignoreInvalidKeys" value="true" />
|
||||
<property name="order" value="2" />
|
||||
</bean>
|
||||
|
||||
<bean id="placeholderProperties" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer"
|
||||
depends-on="environment">
|
||||
<property name="location" value="classpath:batch-${ENVIRONMENT}.properties" />
|
||||
<property name="ignoreUnresolvablePlaceholders" value="true" />
|
||||
<property name="order" value="1" />
|
||||
</bean>
|
||||
|
||||
<bean id="sequenceIncrementerParent" class="${batch.database.incrementer.class}" abstract="true">
|
||||
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="columnIncrementerParent" class="${batch.database.incrementer.class}" abstract="true" parent="sequenceIncrementerParent">
|
||||
<property name="columnName" value="ID" />
|
||||
</bean>
|
||||
|
||||
<bean id="incrementerParent" parent="${batch.database.incrementer.parent}">
|
||||
<property name="incrementerName" value="DUMMY"/>
|
||||
</bean>
|
||||
|
||||
<bean id="lobHandler" class="${batch.lob.handler.class}"/>
|
||||
<bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler"/>
|
||||
</beans>
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<context:annotation-config/>
|
||||
|
||||
<bean class="org.springframework.batch.test.JobLauncherTestUtils"/>
|
||||
<bean class="org.springframework.batch.test.context.BatchTestContextBeanPostProcessor"/>
|
||||
</beans>
|
||||
@@ -64,7 +64,9 @@
|
||||
<bean id="tradeDao" class="org.springframework.batch.samples.domain.trade.internal.JdbcTradeDao">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="incrementer">
|
||||
<bean parent="incrementerParent">
|
||||
<bean class="org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="columnName" value="ID" />
|
||||
<property name="incrementerName" value="TRADE_SEQ" />
|
||||
</bean>
|
||||
</property>
|
||||
|
||||
@@ -65,10 +65,11 @@
|
||||
<bean id="tradeDao" class="org.springframework.batch.samples.domain.trade.internal.JdbcTradeDao">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="incrementer">
|
||||
<bean parent="incrementerParent">
|
||||
<bean class="org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="columnName" value="ID" />
|
||||
<property name="incrementerName" value="TRADE_SEQ" />
|
||||
</bean>
|
||||
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
@@ -66,8 +66,10 @@
|
||||
class="org.springframework.batch.samples.domain.trade.internal.JdbcCustomerDao">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="incrementer">
|
||||
<bean parent="${batch.database.incrementer.parent}">
|
||||
<property name="incrementerName" value="CUSTOMER_SEQ"/>
|
||||
<bean class="org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="columnName" value="ID" />
|
||||
<property name="incrementerName" value="CUSTOMER_SEQ" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
<step id="playerLoad" next="gameLoad">
|
||||
<tasklet>
|
||||
<chunk reader="playerFileItemReader" writer="playerWriter"
|
||||
commit-interval="${job.commit.interval}" />
|
||||
commit-interval="2" />
|
||||
</tasklet>
|
||||
</step>
|
||||
<step id="gameLoad" next="playerSummarization">
|
||||
<tasklet>
|
||||
<chunk reader="gameFileItemReader" writer="gameWriter"
|
||||
commit-interval="${job.commit.interval}" />
|
||||
commit-interval="2" />
|
||||
</tasklet>
|
||||
</step>
|
||||
<step id="playerSummarization" parent="summarizationStep" />
|
||||
@@ -23,7 +23,7 @@
|
||||
<step id="summarizationStep" xmlns="http://www.springframework.org/schema/batch">
|
||||
<tasklet>
|
||||
<chunk reader="playerSummarizationSource" writer="summaryWriter"
|
||||
commit-interval="${job.commit.interval}" />
|
||||
commit-interval="2" />
|
||||
</tasklet>
|
||||
</step>
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
</bean>
|
||||
|
||||
<bean id="playerFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
|
||||
<property name="resource" value="classpath:org/springframework/batch/samples/football/data/${player.file.name}" />
|
||||
<property name="resource" value="classpath:org/springframework/batch/samples/football/data/player-small1.csv" />
|
||||
<property name="lineMapper">
|
||||
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
|
||||
<property name="lineTokenizer">
|
||||
@@ -60,7 +60,7 @@
|
||||
</bean>
|
||||
|
||||
<bean id="gameFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
|
||||
<property name="resource" value="classpath:org/springframework/batch/samples/football/data/${games.file.name}" />
|
||||
<property name="resource" value="classpath:org/springframework/batch/samples/football/data/games-small.csv" />
|
||||
<property name="lineMapper">
|
||||
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
|
||||
<property name="lineTokenizer">
|
||||
@@ -90,18 +90,6 @@
|
||||
GAMES.player_id group by GAMES.player_id, GAMES.year_no
|
||||
</value>
|
||||
</property>
|
||||
<property name="verifyCursorPosition" value="${batch.verify.cursor.position}"/>
|
||||
</bean>
|
||||
|
||||
<bean id="footballProperties" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
|
||||
<property name="properties">
|
||||
<value>
|
||||
games.file.name=games-small.csv
|
||||
player.file.name=player-small1.csv
|
||||
job.commit.interval=2
|
||||
</value>
|
||||
</property>
|
||||
<property name="ignoreUnresolvablePlaceholders" value="true" />
|
||||
<property name="order" value="1" />
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"classpath://org/hibernate/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping>
|
||||
<class name="org.springframework.batch.samples.domain.trade.CustomerCredit"
|
||||
table="CUSTOMER">
|
||||
<id name="id">
|
||||
<!-- To make the job fail on flush we need assigned IDs -->
|
||||
<generator class="assigned" />
|
||||
</id>
|
||||
<property name="name" />
|
||||
<property name="credit" />
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
||||
@@ -56,10 +56,11 @@
|
||||
<bean id="tradeDao" class="org.springframework.batch.samples.domain.trade.internal.JdbcTradeDao">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="incrementer">
|
||||
<bean parent="incrementerParent">
|
||||
<bean class="org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="columnName" value="ID" />
|
||||
<property name="incrementerName" value="TRADE_SEQ" />
|
||||
</bean>
|
||||
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
</bean>
|
||||
</property>
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="verifyCursorPosition" value="${batch.verify.cursor.position}"/>
|
||||
</bean>
|
||||
|
||||
<bean id="itemWriter" class="org.springframework.batch.item.mail.SimpleMailMessageItemWriter">
|
||||
|
||||
@@ -1,9 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
https://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<import resource="classpath:simple-job-launcher-context.xml" />
|
||||
<import resource="classpath:data-source-context.xml" />
|
||||
|
||||
<bean id="jobLauncher"
|
||||
class="org.springframework.batch.core.launch.support.TaskExecutorJobLauncher">
|
||||
<property name="jobRepository" ref="jobRepository" />
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
|
||||
<property name="jobRegistry" ref="jobRegistry"/>
|
||||
</bean>
|
||||
|
||||
<bean id="jobRepository"
|
||||
class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean"
|
||||
p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager" p:lobHandler-ref="lobHandler"/>
|
||||
|
||||
<bean id="jobExplorer"
|
||||
class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean"
|
||||
p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager"/>
|
||||
|
||||
<bean id="jobRegistry"
|
||||
class="org.springframework.batch.core.configuration.support.MapJobRegistry" />
|
||||
|
||||
<bean class="org.springframework.jmx.export.MBeanExporter">
|
||||
<property name="beans">
|
||||
@@ -31,7 +52,6 @@
|
||||
</bean>
|
||||
|
||||
<bean id="notificationPublisher" class="org.springframework.batch.samples.misc.jmx.JobExecutionNotificationPublisher" />
|
||||
<bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry" />
|
||||
<bean id="jobOperator" class="org.springframework.batch.core.launch.support.SimpleJobOperator">
|
||||
<property name="jobExplorer" ref="jobExplorer"/>
|
||||
<property name="jobRepository" ref="jobRepository" />
|
||||
@@ -50,4 +70,5 @@
|
||||
<bean id="loader" class="org.springframework.batch.samples.launch.DefaultJobLoader">
|
||||
<property name="registry" ref="jobRegistry" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1,14 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
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
|
||||
http://www.springframework.org/schema/batch
|
||||
https://www.springframework.org/schema/batch/spring-batch.xsd
|
||||
http://www.springframework.org/schema/aop
|
||||
https://www.springframework.org/schema/aop/spring-aop.xsd">
|
||||
https://www.springframework.org/schema/batch/spring-batch.xsd">
|
||||
|
||||
<!-- The tasklet used in this job will run in an infinite loop. This is useful for testing graceful shutdown from
|
||||
multiple environments. -->
|
||||
@@ -27,17 +24,4 @@
|
||||
<bean id="jobParametersIncrementer"
|
||||
class="org.springframework.batch.core.launch.support.RunIdIncrementer"/>
|
||||
|
||||
<aop:config>
|
||||
<aop:aspect ref="eventAdvice">
|
||||
<aop:before
|
||||
pointcut="execution( * org.springframework.batch..Step+.execute(..)) and args(stepExecution)"
|
||||
method="before" />
|
||||
<aop:after
|
||||
pointcut="execution( * org.springframework.batch..Step+.execute(..)) and args(stepExecution)"
|
||||
method="after" />
|
||||
<aop:after-throwing throwing="t"
|
||||
pointcut="execution( * org.springframework.batch..Step+.execute(..)) and args(stepExecution)"
|
||||
method="onError" />
|
||||
</aop:aspect>
|
||||
</aop:config>
|
||||
</beans>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<job id="partitionJdbcJob" xmlns="http://www.springframework.org/schema/batch">
|
||||
<step id="step">
|
||||
<partition step="step1" partitioner="partitioner">
|
||||
<handler grid-size="${batch.grid.size}" task-executor="taskExecutor"/>
|
||||
<handler grid-size="5" task-executor="taskExecutor"/>
|
||||
</partition>
|
||||
</step>
|
||||
</job>
|
||||
@@ -91,7 +91,6 @@
|
||||
</value>
|
||||
</property>
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="verifyCursorPosition" value="${batch.verify.cursor.position}"/>
|
||||
<property name="rowMapper">
|
||||
<bean class="org.springframework.batch.samples.domain.trade.internal.CustomerCreditRowMapper" />
|
||||
</property>
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd
|
||||
http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
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">
|
||||
|
||||
<job id="parallelJob" xmlns="http://www.springframework.org/schema/batch">
|
||||
@@ -34,7 +32,9 @@
|
||||
<bean id="stagingItemWriter" class="org.springframework.batch.samples.common.StagingItemWriter">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="incrementer">
|
||||
<bean parent="incrementerParent">
|
||||
<bean class="org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="columnName" value="ID" />
|
||||
<property name="incrementerName" value="BATCH_STAGING_SEQ" />
|
||||
</bean>
|
||||
</property>
|
||||
@@ -90,21 +90,15 @@
|
||||
class="org.springframework.batch.samples.domain.trade.internal.JdbcTradeDao">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="incrementer">
|
||||
<bean parent="incrementerParent">
|
||||
<bean class="org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="columnName" value="ID" />
|
||||
<property name="incrementerName" value="TRADE_SEQ" />
|
||||
</bean>
|
||||
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="fieldSetMapper"
|
||||
class="org.springframework.batch.samples.domain.trade.internal.TradeFieldSetMapper" />
|
||||
|
||||
<aop:config>
|
||||
<aop:aspect id="moduleLogging" ref="logAdvice">
|
||||
<aop:after
|
||||
pointcut="execution( * org.springframework.batch.item.ItemWriter+.write(Object)) and args(item)"
|
||||
method="doStronglyTypedLogging" />
|
||||
</aop:aspect>
|
||||
</aop:config>
|
||||
</beans>
|
||||
@@ -6,7 +6,9 @@
|
||||
|
||||
<bean id="processor" class="org.springframework.batch.samples.common.StagingItemWriter">
|
||||
<property name="incrementer">
|
||||
<bean parent="${batch.database.incrementer.parent}">
|
||||
<bean class="org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="columnName" value="ID" />
|
||||
<property name="incrementerName" value="BATCH_STAGING_SEQ" />
|
||||
</bean>
|
||||
</property>
|
||||
|
||||
@@ -53,10 +53,11 @@
|
||||
<bean id="tradeDao" class="org.springframework.batch.samples.domain.trade.internal.JdbcTradeDao">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="incrementer">
|
||||
<bean parent="incrementerParent">
|
||||
<bean class="org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="columnName" value="ID" />
|
||||
<property name="incrementerName" value="TRADE_SEQ" />
|
||||
</bean>
|
||||
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<import resource="classpath:data-source-context.xml" />
|
||||
<import resource="classpath:common-context.xml" />
|
||||
|
||||
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.TaskExecutorJobLauncher">
|
||||
<property name="jobRepository" ref="jobRepository" />
|
||||
@@ -39,9 +38,9 @@
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="logAdvice" class="org.springframework.batch.samples.common.LogAdvice" />
|
||||
|
||||
<bean id="customerIncrementer" parent="incrementerParent">
|
||||
<bean id="customerIncrementer" class="org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="columnName" value="ID" />
|
||||
<property name="incrementerName" value="CUSTOMER_SEQ" />
|
||||
</bean>
|
||||
</beans>
|
||||
|
||||
@@ -99,7 +99,9 @@
|
||||
<bean class="org.springframework.batch.samples.domain.trade.internal.JdbcTradeDao">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="incrementer">
|
||||
<bean parent="incrementerParent">
|
||||
<bean class="org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="columnName" value="ID" />
|
||||
<property name="incrementerName" value="TRADE_SEQ" />
|
||||
</bean>
|
||||
</property>
|
||||
@@ -123,7 +125,6 @@
|
||||
<property name="rowMapper">
|
||||
<bean class="org.springframework.batch.samples.domain.trade.internal.TradeRowMapper" />
|
||||
</property>
|
||||
<property name="verifyCursorPosition" value="${batch.verify.cursor.position}"/>
|
||||
</bean>
|
||||
|
||||
<bean id="errorLogTasklet" class="org.springframework.batch.samples.common.ErrorLogTasklet" scope="step">
|
||||
|
||||
@@ -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">
|
||||
|
||||
<batch:job-repository />
|
||||
|
||||
<job id="tradeJob" xmlns="http://www.springframework.org/schema/batch">
|
||||
<step id="step1" next="step2">
|
||||
<tasklet>
|
||||
@@ -54,7 +52,6 @@
|
||||
<property name="rowMapper">
|
||||
<bean class="org.springframework.batch.samples.domain.trade.internal.TradeRowMapper" />
|
||||
</property>
|
||||
<property name="verifyCursorPosition" value="${batch.verify.cursor.position}"/>
|
||||
</bean>
|
||||
|
||||
<bean id="customerSqlItemReader" class="org.springframework.batch.item.database.JdbcCursorItemReader">
|
||||
@@ -68,7 +65,9 @@
|
||||
<bean id="tradeDao" class="org.springframework.batch.samples.domain.trade.internal.JdbcTradeDao"
|
||||
p:dataSource-ref="dataSource">
|
||||
<property name="incrementer">
|
||||
<bean parent="incrementerParent">
|
||||
<bean class="org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="columnName" value="ID" />
|
||||
<property name="incrementerName" value="TRADE_SEQ" />
|
||||
</bean>
|
||||
</property>
|
||||
|
||||
@@ -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">
|
||||
|
||||
<import resource="data-source-context.xml" />
|
||||
<import resource="common-context.xml" />
|
||||
|
||||
<bean id="jobLauncher"
|
||||
class="org.springframework.batch.core.launch.support.TaskExecutorJobLauncher">
|
||||
<property name="jobRepository" ref="jobRepository" />
|
||||
@@ -16,7 +17,6 @@
|
||||
|
||||
<bean id="jobRepository"
|
||||
class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean"
|
||||
p:isolationLevelForCreate = "${batch.isolationlevel}"
|
||||
p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager" p:lobHandler-ref="lobHandler"/>
|
||||
|
||||
<bean id="jobOperator"
|
||||
@@ -31,12 +31,7 @@
|
||||
<bean id="jobRegistry"
|
||||
class="org.springframework.batch.core.configuration.support.MapJobRegistry" />
|
||||
|
||||
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
<bean class="org.springframework.batch.test.JobLauncherTestUtils"/>
|
||||
<bean class="org.springframework.batch.test.context.BatchTestContextBeanPostProcessor"/>
|
||||
|
||||
<bean id="logAdvice" class="org.springframework.batch.samples.common.LogAdvice" />
|
||||
|
||||
<bean id="eventAdvice"
|
||||
class="org.springframework.batch.samples.common.StepExecutionApplicationEventAdvice" />
|
||||
</beans>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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<String, ExecutionContext> partition = partitioner.partition(2);
|
||||
assertEquals(2, partition.size());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<String> itemReader;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
List<String> 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<String> 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<T> implements ItemReader<T>, ItemStream {
|
||||
|
||||
private static final String CURRENT_INDEX = "current.index";
|
||||
|
||||
private final List<T> items;
|
||||
|
||||
private int currentIndex = 0;
|
||||
|
||||
public CustomItemReader(List<T> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<String> 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<T> implements ItemWriter<T> {
|
||||
|
||||
private final List<T> output = TransactionAwareProxyFactory.createTransactionalList();
|
||||
|
||||
@Override
|
||||
public void write(Chunk<? extends T> chunk) throws Exception {
|
||||
output.addAll(chunk.getItems());
|
||||
}
|
||||
|
||||
public List<T> getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<String> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<String> writer;
|
||||
|
||||
@Autowired
|
||||
private StagingItemReader<String> 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<String> wrapper = reader.read();
|
||||
String item = wrapper.getItem();
|
||||
assertEquals("FOO", item);
|
||||
|
||||
StagingItemProcessor<String> 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<Void>) 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<String> 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<String> 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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";
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<String> 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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<AggregateItem<String>> input;
|
||||
|
||||
private AggregateItemReader<String> provider;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
input = new ItemReader<>() {
|
||||
private int count = 0;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AggregateItem<String> 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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Address> fieldSetMapper() {
|
||||
return new AddressFieldSetMapper();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<BillingInfo> fieldSetMapper() {
|
||||
return new BillingFieldSetMapper();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Customer> fieldSetMapper() {
|
||||
return new CustomerFieldSetMapper();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Order> fieldSetMapper() {
|
||||
return new HeaderFieldSetMapper();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<LineItem> fieldSetMapper() {
|
||||
return new OrderItemFieldSetMapper();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<FieldSet> 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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<ShippingInfo> fieldSetMapper() {
|
||||
return new ShippingFieldSetMapper();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<CustomerCredit> {
|
||||
|
||||
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<CustomerCredit> 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<String>, ItemStream {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Trade> fieldSetMapper() {
|
||||
return new TradeFieldSetMapper();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Trade> {
|
||||
|
||||
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<Trade> 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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<LineItem> 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<LineItem> 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<Game> {
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<Notification> 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': ");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 <code>FieldSet</code> used for mapping
|
||||
*/
|
||||
protected abstract FieldSet fieldSet();
|
||||
|
||||
/**
|
||||
* @return domain object excepted as a result of mapping the <code>FieldSet</code>
|
||||
* returned by <code>this.fieldSet()</code>
|
||||
*/
|
||||
protected abstract Object expectedDomainObject();
|
||||
|
||||
/**
|
||||
* @return mapper which takes <code>this.fieldSet()</code> and maps it to domain
|
||||
* object.
|
||||
*/
|
||||
protected abstract FieldSetMapper<?> fieldSetMapper();
|
||||
|
||||
/**
|
||||
* Regular usage scenario. Assumes the domain object implements sensible
|
||||
* <code>equals(Object other)</code>
|
||||
*/
|
||||
@Test
|
||||
void testRegularUse() throws Exception {
|
||||
assertEquals(expectedDomainObject(), fieldSetMapper().mapFieldSet(fieldSet()));
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user