Add wildcard search functionality from BATCH-1797 to MapJobInstanceDao and tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2013 the original author or authors.
|
||||
* Copyright 2008-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.
|
||||
@@ -91,18 +91,16 @@ public class JdbcJobInstanceDaoTests extends AbstractJobInstanceDaoTests {
|
||||
|
||||
@Test
|
||||
public void testJobInstanceWildcard() {
|
||||
//look up a job using a wildcard (* substituted to %)
|
||||
// unrelated job instance that should be ignored by the query
|
||||
dao.createJobInstance("anotherJob", new JobParameters());
|
||||
// we need two instances of the same job to check ordering
|
||||
dao.createJobInstance("someJob", new JobParameters());
|
||||
//now look for them
|
||||
|
||||
List<JobInstance> jobInstances = dao.findJobInstancesByName("*Job", 0, 2);
|
||||
assertEquals(2, jobInstances.size());
|
||||
|
||||
for (JobInstance instance : jobInstances) {
|
||||
assertTrue(instance.getJobName().contains("Job"));
|
||||
}//end for
|
||||
//try with after wildcards
|
||||
}
|
||||
|
||||
jobInstances = dao.getJobInstances("Job*", 0, 2);
|
||||
assertTrue(jobInstances.isEmpty());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2012 the original author or authors.
|
||||
* Copyright 2008-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.
|
||||
@@ -15,8 +15,15 @@
|
||||
*/
|
||||
package org.springframework.batch.core.repository.dao;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class MapJobInstanceDaoTests extends AbstractJobInstanceDaoTests {
|
||||
@@ -26,4 +33,30 @@ public class MapJobInstanceDaoTests extends AbstractJobInstanceDaoTests {
|
||||
return new MapJobInstanceDao();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWildcardPrefix() {
|
||||
MapJobInstanceDao mapJobInstanceDao = new MapJobInstanceDao();
|
||||
mapJobInstanceDao.createJobInstance("testJob", new JobParameters());
|
||||
mapJobInstanceDao.createJobInstance("Jobtest", new JobParameters());
|
||||
List<JobInstance> jobInstances = mapJobInstanceDao.findJobInstancesByName("*Job", 0, 2);
|
||||
assertTrue("Invalid matching job instances found, expected 1, got: " + jobInstances.size(), jobInstances.size() == 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWildcardSuffix() {
|
||||
MapJobInstanceDao mapJobInstanceDao = new MapJobInstanceDao();
|
||||
mapJobInstanceDao.createJobInstance("testJob", new JobParameters());
|
||||
mapJobInstanceDao.createJobInstance("Jobtest", new JobParameters());
|
||||
List<JobInstance> jobInstances = mapJobInstanceDao.findJobInstancesByName("Job*", 0, 2);
|
||||
assertTrue("No matching job instances found, expected 1, got: " + jobInstances.size(), jobInstances.size() == 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWildcardRange() {
|
||||
MapJobInstanceDao mapJobInstanceDao = new MapJobInstanceDao();
|
||||
mapJobInstanceDao.createJobInstance("testJob", new JobParameters());
|
||||
mapJobInstanceDao.createJobInstance("Jobtest", new JobParameters());
|
||||
List<JobInstance> jobInstances = mapJobInstanceDao.findJobInstancesByName("*Job*", 0, 2);
|
||||
assertTrue("No matching job instances found, expected 2, got: " + jobInstances.size(), jobInstances.size() == 2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user