Remove deprecated APIs

Resolves #3836
This commit is contained in:
Mahmoud Ben Hassine
2021-08-17 20:55:08 +02:00
parent f8bdf5521e
commit bb3809cf55
37 changed files with 217 additions and 2712 deletions

View File

@@ -72,19 +72,6 @@ public class JobExecutionTests {
assertFalse(execution.isRunning());
}
/**
* Test method for
* {@link org.springframework.batch.core.JobExecution#getEndTime()}.
*/
@Test
public void testIsRunningWithStoppedExecution() {
execution.setStartTime(new Date());
assertTrue(execution.isRunning());
execution.stop();
assertTrue(execution.isRunning());
assertTrue(execution.isStopping());
}
/**
* Test method for
* {@link org.springframework.batch.core.JobExecution#getStartTime()}.
@@ -206,14 +193,6 @@ public class JobExecutionTests {
assertEquals(2, execution.getStepExecutions().size());
}
@Test
public void testStop() throws Exception {
StepExecution stepExecution = execution.createStepExecution("step");
assertFalse(stepExecution.isTerminateOnly());
execution.stop();
assertTrue(stepExecution.isTerminateOnly());
}
@Test
public void testToString() throws Exception {
assertTrue("JobExecution string does not contain id", execution.toString().indexOf("id=") >= 0);

View File

@@ -102,7 +102,6 @@ public class SimpleJobTests {
@Before
public void setUp() throws Exception {
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
@@ -394,17 +393,6 @@ public class SimpleJobTests {
"no steps configured") >= 0);
}
@Test
public void testNotExecutedIfAlreadyStopped() throws Exception {
jobExecution.stop();
job.execute(jobExecution);
assertEquals(0, list.size());
checkRepository(BatchStatus.STOPPED, ExitStatus.NOOP);
ExitStatus exitStatus = jobExecution.getExitStatus();
assertEquals(ExitStatus.NOOP.getExitCode(), exitStatus.getExitCode());
}
@Test
public void testRestart() throws Exception {
step1.setAllowStartIfComplete(true);
@@ -493,31 +481,6 @@ public class SimpleJobTests {
assertFalse(step2.passedInJobContext.isEmpty());
}
@Test
public void testInterruptJob() throws Exception {
step1 = new StubStep("interruptStep", jobRepository) {
@Override
public void execute(StepExecution stepExecution) throws JobInterruptedException,
UnexpectedJobExecutionException {
stepExecution.getJobExecution().stop();
super.execute(stepExecution);
}
};
job.setSteps(Arrays.asList(new Step[] { step1, step2 }));
job.execute(jobExecution);
assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());
assertEquals(1, jobExecution.getAllFailureExceptions().size());
Throwable expected = jobExecution.getAllFailureExceptions().get(0);
assertTrue("Wrong exception " + expected, expected instanceof JobInterruptedException);
assertEquals("JobExecution interrupted.", expected.getMessage());
assertNull("Second step was not supposed to be executed", step2.passedInStepContext);
}
@Test
public void testGetStepExists() {
step1 = new StubStep("step1", jobRepository);

View File

@@ -1,111 +0,0 @@
/*
* Copyright 2006-2013 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.core.launch.support;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import junit.framework.TestCase;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.util.StringUtils;
/**
* @author Lucas Ward
*
*/
public class ScheduledJobParametersFactoryTests extends TestCase {
ScheduledJobParametersFactory factory;
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
@Override
protected void setUp() throws Exception {
super.setUp();
factory = new ScheduledJobParametersFactory();
}
public void testGetParameters() throws Exception {
String jobKey = "job.key=myKey";
String scheduleDate = "schedule.date=2008/01/23";
String vendorId = "vendor.id=33243243";
String[] args = new String[] { jobKey, scheduleDate, vendorId };
JobParameters props = factory.getJobParameters(StringUtils.splitArrayElementsIntoProperties(args, "="));
assertNotNull(props);
assertEquals("myKey", props.getString("job.key"));
assertEquals("33243243", props.getString("vendor.id"));
Date date = dateFormat.parse("01/23/2008");
assertEquals(date, props.getDate("schedule.date"));
}
public void testGetProperties() throws Exception {
JobParameters parameters = new JobParametersBuilder().addDate("schedule.date", dateFormat.parse("01/23/2008"))
.addString("job.key", "myKey").addString("vendor.id", "33243243").toJobParameters();
Properties props = factory.getProperties(parameters);
assertNotNull(props);
assertEquals("myKey", props.getProperty("job.key"));
assertEquals("33243243", props.getProperty("vendor.id"));
assertEquals("2008/01/23", props.getProperty("schedule.date"));
}
public void testEmptyArgs() {
JobParameters props = factory.getJobParameters(new Properties());
assertTrue(props.getParameters().isEmpty());
}
public void testNullArgs() {
assertEquals(new JobParameters(), factory.getJobParameters(null));
assertEquals(new Properties(), factory.getProperties(null));
}
public void testGetParametersWithDateFormat() throws Exception {
String[] args = new String[] { "schedule.date=2008/23/01" };
factory.setDateFormat(new SimpleDateFormat("yyyy/dd/MM"));
JobParameters props = factory.getJobParameters(StringUtils.splitArrayElementsIntoProperties(args, "="));
assertNotNull(props);
Date date = dateFormat.parse("01/23/2008");
assertEquals(date, props.getDate("schedule.date"));
}
public void testGetParametersWithBogusDate() throws Exception {
String[] args = new String[] { "schedule.date=20080123" };
try {
factory.getJobParameters(StringUtils.splitArrayElementsIntoProperties(args, "="));
} catch (IllegalArgumentException e) {
String message = e.getMessage();
assertTrue("Message should contain wrong date: " + message, contains(message, "20080123"));
}
}
private boolean contains(String str, String searchStr) {
return str.indexOf(searchStr) != -1;
}
}

View File

@@ -1,42 +0,0 @@
/*
* Copyright 2008-2016 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.core.repository.dao;
import org.junit.Before;
import org.springframework.batch.core.repository.ExecutionContextSerializer;
/**
* @author Thomas Risberg
* @author Michael Minella
*/
public class XStreamExecutionContextStringSerializerTests extends AbstractExecutionContextSerializerTests {
ExecutionContextSerializer serializer;
@Before
public void onSetUp() throws Exception {
@SuppressWarnings("deprecation")
XStreamExecutionContextStringSerializer serializerDeserializer = new XStreamExecutionContextStringSerializer();
(serializerDeserializer).afterPropertiesSet();
serializer = serializerDeserializer;
}
@Override
protected ExecutionContextSerializer getSerializer() {
return this.serializer;
}
}

View File

@@ -1,146 +0,0 @@
/*
* Copyright 2006-2013 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.core.resource;
import static org.junit.Assert.assertEquals;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.sql.DataSource;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.job.AbstractJob;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.database.support.ListPreparedStatementSetter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
/**
* @author Lucas Ward
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"/org/springframework/batch/core/resource/ListPreparedStatementSetterTests-context.xml",
"/org/springframework/batch/core/repository/dao/data-source-context.xml" })
public class ListPreparedStatementSetterTests {
ListPreparedStatementSetter pss;
StepExecution stepExecution;
private JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@Autowired
private AbstractJob job;
@Autowired
private JobLauncher jobLauncher;
@Autowired
private FooStoringItemWriter fooStoringItemWriter;
@Before
public void onSetUpInTransaction() throws Exception {
List<Long> parameters = new ArrayList<>();
parameters.add(1L);
parameters.add(4L);
pss = new ListPreparedStatementSetter(parameters);
}
@Transactional
@Test
public void testSetValues() {
final List<String> results = new ArrayList<>();
jdbcTemplate.query("SELECT NAME from T_FOOS where ID > ? and ID < ?", pss,
new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
results.add(rs.getString(1));
}
});
assertEquals(2, results.size());
assertEquals("bar2", results.get(0));
assertEquals("bar3", results.get(1));
}
@Transactional
@Test(expected = IllegalArgumentException.class)
public void testAfterPropertiesSet() throws Exception {
pss = new ListPreparedStatementSetter(null);
pss.afterPropertiesSet();
}
@Test
public void testXmlConfiguration() throws Exception {
this.jdbcTemplate.update("create table FOO (ID integer, NAME varchar(40), VALUE integer)");
try {
this.jdbcTemplate.update("insert into FOO values (?,?,?)", 0, "zero", 0);
this.jdbcTemplate.update("insert into FOO values (?,?,?)", 1, "one", 1);
this.jdbcTemplate.update("insert into FOO values (?,?,?)", 2, "two", 2);
this.jdbcTemplate.update("insert into FOO values (?,?,?)", 3, "three", 3);
JobParametersBuilder builder = new JobParametersBuilder().addLong("min.id", 1L).addLong("max.id", 2L);
JobExecution jobExecution = this.jobLauncher.run(this.job, builder.toJobParameters());
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
List<Foo> foos = fooStoringItemWriter.getFoos();
assertEquals(2, foos.size());
System.err.println(foos.get(0));
System.err.println(foos.get(1));
assertEquals(new Foo(1, "one", 1), foos.get(0));
assertEquals(new Foo(2, "two", 2), foos.get(1));
}
finally {
this.jdbcTemplate.update("drop table FOO");
}
}
public static class FooStoringItemWriter implements ItemWriter<Foo> {
private List<Foo> foos = new ArrayList<>();
@Override
public void write(List<? extends Foo> items) throws Exception {
foos.addAll(items);
}
public List<Foo> getFoos() {
return foos;
}
}
}