Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @author Sebastien Lorber <i>(lorber.sebastien@gmail.com)</i>
- */
- @RunWith(SpringJUnit4ClassRunner.class)
- @Category(IntegrationTest.class)
- @ContextConfiguration(classes = Config.class)
- public class JobExecutionsImportTest {
- @Value("#{solrClientsHolder.jobExecutionsClient}")
- protected JobExecutionsSolrClient client;
- @Autowired
- protected JobDashboardSearchService jobsService;
- @Autowired
- protected JdbcTemplate jdbcTemplate;
- private void cleanIndex() throws Exception {
- client.getSolrServer().deleteByQuery("*:*");
- client.getSolrServer().commit();
- }
- /**
- * La derniere date d'indexation est settée dans un properties
- */
- private void deleteLastIndexDate() {
- new File("./target/test-classes/solr/JobExecutionsCore/conf/data-import.properties").delete();
- }
- private void assertIndexedDocuments(long expectedCount) throws Exception {
- SolrQuery query = new SolrQuery();
- query.setQuery("*:*");
- QueryResponse response;
- response = client.getSolrServer().query(query);
- long count = response.getResults().getNumFound();
- assertThat(count).isEqualTo(expectedCount);
- }
- @Test
- public void test_full_import_when_never_indexed() throws Exception {
- cleanIndex();
- deleteLastIndexDate();
- assertIndexedDocuments(0);
- jobsService.fullImport();
- assertIndexedDocuments(2);
- }
- @Test
- @Ignore("Worked with Solr 1.4 but doesn't work anymore because of SOLR-4376")
- public void test_delta_import_when_never_indexed() throws Exception {
- cleanIndex();
- deleteLastIndexDate();
- assertIndexedDocuments(0);
- jobsService.deltaImport();
- assertIndexedDocuments(2);
- }
- @Test
- public void test_full_import_when_already_indexed_and_index_cleaned() throws Exception {
- jobsService.fullImport();
- cleanIndex();
- assertIndexedDocuments(0);
- jobsService.fullImport();
- assertIndexedDocuments(2);
- }
- @Test
- public void test_delta_import_when_already_indexed_and_index_cleaned() throws Exception {
- jobsService.fullImport();
- cleanIndex();
- assertIndexedDocuments(0);
- jobsService.deltaImport();
- // normal because dataimport.properties last index date is after the db date of job executions in db
- assertIndexedDocuments(0);
- }
- @Test
- public void test_full_import_when_already_indexed_and_index_not_cleaned() throws Exception {
- jobsService.fullImport();
- assertIndexedDocuments(2);
- jobsService.fullImport();
- assertIndexedDocuments(2);
- }
- @Test
- public void test_delta_import_when_already_indexed_and_index_not_cleaned() throws Exception {
- jobsService.fullImport();
- assertIndexedDocuments(2);
- jobsService.deltaImport();
- assertIndexedDocuments(2);
- }
- @Test
- @DirtiesContext
- public void test_full_import_does_not_keep_jobs_removed_from_db() throws Exception {
- jobsService.fullImport();
- assertIndexedDocuments(2);
- jdbcTemplate.execute("DELETE FROM BATCH_STEP_EXECUTION_CONTEXT WHERE STEP_EXECUTION_ID=3");
- jdbcTemplate.execute("DELETE FROM BATCH_STEP_EXECUTION WHERE STEP_EXECUTION_ID=3");
- jdbcTemplate.execute("DELETE FROM BATCH_JOB_EXECUTION_CONTEXT WHERE JOB_EXECUTION_ID=2");
- jdbcTemplate.execute("DELETE FROM BATCH_JOB_EXECUTION WHERE JOB_EXECUTION_ID=2");
- jobsService.fullImport();
- assertIndexedDocuments(1);
- }
- @Configuration
- @ImportResource("classpath:META-INF/spring/embedded-solr-server-test-context.xml")
- public static class Config extends AbstractH2DataSourceConfig {
- @Override
- protected List<String> getSqlScripts() {
- return ImmutableList.of("classpath:sql/ddl--springbatchexecutions-dataset.sql");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement