Search in sources :

Example 46 with JobExecution

use of org.springframework.batch.core.JobExecution in project RecordManager2 by moravianlibrary.

the class OAIHarvestJobTest method testHarvestUntilDate.

@Test
public void testHarvestUntilDate() throws Exception {
    reset(httpClient);
    InputStream response0 = this.getClass().getResourceAsStream("/sample/Identify.xml");
    InputStream response1 = this.getClass().getResourceAsStream("/sample/ListRecordsUntil.xml");
    expect(httpClient.executeGet("http://aleph.mzk.cz/OAI?verb=Identify")).andReturn(response0);
    expect(httpClient.executeGet("http://aleph.mzk.cz/OAI?verb=ListRecords&metadataPrefix=marc21&until=2014-12-09T01%3A00%3A00Z")).andReturn(response1);
    replay(httpClient);
    Map<String, JobParameter> params = new HashMap<>();
    params.put(Constants.JOB_PARAM_CONF_ID, new JobParameter(300L));
    params.put(Constants.JOB_PARAM_UNTIL_DATE, new JobParameter(new Date(1418083200000L)));
    JobExecution exec = jobExecutor.execute("oaiHarvestJob", new JobParameters(params));
    Assert.assertEquals(exec.getExitStatus(), ExitStatus.COMPLETED);
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) HashMap(java.util.HashMap) InputStream(java.io.InputStream) JobParameters(org.springframework.batch.core.JobParameters) JobParameter(org.springframework.batch.core.JobParameter) Date(java.util.Date) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 47 with JobExecution

use of org.springframework.batch.core.JobExecution in project RecordManager2 by moravianlibrary.

the class AdresarHarvestTest method harvestRecords.

@Test
public void harvestRecords() throws Exception {
    reset(httpClient);
    InputStream response1 = this.getClass().getResourceAsStream("/sample/adresar/adr000000001.xml");
    InputStream response2 = this.getClass().getResourceAsStream("/sample/adresar/adr000000002.xml");
    expect(httpClient.executeGet("http://aleph.nkp.cz/X?op=find-doc&doc_num=000000001&base=ADR")).andReturn(response1);
    expect(httpClient.executeGet("http://aleph.nkp.cz/X?op=find-doc&doc_num=000000002&base=ADR")).andReturn(response2);
    replay(httpClient);
    Map<String, JobParameter> params = new HashMap<String, JobParameter>();
    params.put(Constants.JOB_PARAM_CONF_ID, new JobParameter(300L));
    params.put(Constants.JOB_PARAM_FIRST_ID, new JobParameter("1"));
    params.put(Constants.JOB_PARAM_LAST_ID, new JobParameter("2"));
    JobParameters jobParams = new JobParameters(params);
    JobExecution exec = jobExecutor.execute(Constants.JOB_ID_HARVEST_ADRESAR, jobParams);
    Assert.assertEquals(exec.getExitStatus(), ExitStatus.COMPLETED);
    Assert.assertNotNull(hrDao.findByIdAndHarvestConfiguration("000000001", 300L));
    Assert.assertNotNull(hrDao.findByIdAndHarvestConfiguration("000000002", 300L));
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) HashMap(java.util.HashMap) InputStream(java.io.InputStream) JobParameters(org.springframework.batch.core.JobParameters) JobParameter(org.springframework.batch.core.JobParameter) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 48 with JobExecution

use of org.springframework.batch.core.JobExecution in project RecordManager2 by moravianlibrary.

the class DeleteAllRecordsFromSolrJobTest method executeWithQuery.

@Test
public void executeWithQuery() throws Exception {
    String query = "id:MZK.MZK01-000000117";
    reset(solrServerFactory);
    reset(mockedSolrServer);
    expect(solrServerFactory.create(eq(SOLR_URL))).andReturn(mockedSolrServer).anyTimes();
    mockedSolrServer.deleteByQuery(query);
    mockedSolrServer.commit();
    replay(solrServerFactory, mockedSolrServer);
    Job job = jobRegistry.getJob("deleteAllRecordsFromSolrJob");
    Map<String, JobParameter> params = new HashMap<String, JobParameter>();
    params.put(Constants.JOB_PARAM_SOLR_URL, new JobParameter(SOLR_URL, true));
    params.put(Constants.JOB_PARAM_SOLR_QUERY, new JobParameter(query, true));
    JobParameters jobParams = new JobParameters(params);
    JobExecution execution = jobLauncher.run(job, jobParams);
    Assert.assertEquals(execution.getExitStatus(), ExitStatus.COMPLETED);
    verify(solrServerFactory, mockedSolrServer);
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) HashMap(java.util.HashMap) JobParameters(org.springframework.batch.core.JobParameters) Job(org.springframework.batch.core.Job) JobParameter(org.springframework.batch.core.JobParameter) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 49 with JobExecution

use of org.springframework.batch.core.JobExecution in project RecordManager2 by moravianlibrary.

the class DeleteAllRecordsFromSolrJobTest method executeWitouthQuery.

@Test
public void executeWitouthQuery() throws Exception {
    reset(solrServerFactory);
    reset(mockedSolrServer);
    expect(solrServerFactory.create(eq(SOLR_URL))).andReturn(mockedSolrServer).anyTimes();
    mockedSolrServer.deleteByQuery("*:*");
    mockedSolrServer.commit();
    replay(solrServerFactory, mockedSolrServer);
    Job job = jobRegistry.getJob("deleteAllRecordsFromSolrJob");
    Map<String, JobParameter> params = new HashMap<String, JobParameter>();
    params.put(Constants.JOB_PARAM_SOLR_URL, new JobParameter(SOLR_URL, true));
    JobParameters jobParams = new JobParameters(params);
    JobExecution execution = jobLauncher.run(job, jobParams);
    Assert.assertEquals(execution.getExitStatus(), ExitStatus.COMPLETED);
    verify(solrServerFactory, mockedSolrServer);
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) HashMap(java.util.HashMap) JobParameters(org.springframework.batch.core.JobParameters) Job(org.springframework.batch.core.Job) JobParameter(org.springframework.batch.core.JobParameter) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 50 with JobExecution

use of org.springframework.batch.core.JobExecution in project RecordManager2 by moravianlibrary.

the class IndexIndividualRecordsToSolrJobTest method execute.

@Test
public void execute() throws Exception {
    SolrServerFacade server = solrServerFactory.create(SOLR_URL);
    Job job = jobRegistry.getJob("indexIndividualRecordsToSolrJob");
    Map<String, JobParameter> params = new HashMap<String, JobParameter>();
    params.put(Constants.JOB_PARAM_SOLR_URL, new JobParameter(SOLR_URL));
    params.put(Constants.JOB_PARAM_RECORD_IDS, new JobParameter("MZK.MZK01-000000117"));
    JobParameters jobParams = new JobParameters(params);
    JobExecution execution = jobLauncher.run(job, jobParams);
    Assert.assertEquals(execution.getExitStatus(), ExitStatus.COMPLETED);
    {
        SolrQuery allDocsQuery = new SolrQuery();
        allDocsQuery.set("q", "id:60");
        allDocsQuery.set("rows", 10000);
        QueryResponse allDocsResponse = server.query(allDocsQuery);
        Assert.assertEquals(allDocsResponse.getResults().size(), 1);
    }
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) HashMap(java.util.HashMap) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) JobParameters(org.springframework.batch.core.JobParameters) Job(org.springframework.batch.core.Job) JobParameter(org.springframework.batch.core.JobParameter) SolrQuery(org.apache.solr.client.solrj.SolrQuery) SolrServerFacade(cz.mzk.recordmanager.server.solr.SolrServerFacade) Test(org.testng.annotations.Test)

Aggregations

JobExecution (org.springframework.batch.core.JobExecution)75 JobParameters (org.springframework.batch.core.JobParameters)52 JobParameter (org.springframework.batch.core.JobParameter)42 HashMap (java.util.HashMap)41 Test (org.testng.annotations.Test)36 AbstractTest (cz.mzk.recordmanager.server.AbstractTest)30 InputStream (java.io.InputStream)25 Job (org.springframework.batch.core.Job)16 Date (java.util.Date)15 JobInstance (org.springframework.batch.core.JobInstance)14 Test (org.junit.Test)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 JobExplorer (org.springframework.batch.core.explore.JobExplorer)11 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)9 OAIHarvestConfiguration (cz.mzk.recordmanager.server.model.OAIHarvestConfiguration)9 JobExecutionFailure (cz.mzk.recordmanager.server.facade.exception.JobExecutionFailure)6 MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)5 MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)5 Record (org.marc4j.marc.Record)5 JobLauncher (org.springframework.batch.core.launch.JobLauncher)5