Хотел сделать тестовый пример Junit при выполнении функции в проекте springbatch, но у меня проблема с параметром в chunkcontext и stepcontribution. ниже код является самой функцией execute.
public class tasklet implements Tasklet, InitializingBean {
private Resource directory;
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(directory, "directory must be set");
}
@Override
public RepeatStatus execute(StepContribution contribution,
ChunkContext chunkContext) throws Exception {
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
String line = "";
String cvsSplitBy = ",";
BufferedReader br = new BufferedReader(new FileReader("person.csv"));
while ((line = br.readLine()) != null) {
Person p = new Person();
String[] personnel = line.split(cvsSplitBy);
p.setFirstName(personnel[0]);
p.setLastName(personnel[1]);
session.save(p);
}
br.close();
session.getTransaction().commit();
System.out.println("Completed");
return RepeatStatus.FINISHED;
}
public Resource getDirectory() {
return directory;
}
public void setDirectory(Resource directory) {
this.directory = directory;
}
public static String asString(Resource directory) throws IOException {
try(Reader reader = new InputStreamReader(directory.getInputStream(),UTF_8)){
return FileCopyUtils.copyToString(reader);
}catch (IOException e){
throw new UncheckedIOException(e);
}
}
}