Search in sources :

Example 26 with JobExecution

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

the class OAIHarvestJobTest method testHarvestSpecificSet.

@Test
public void testHarvestSpecificSet() throws Exception {
    reset(httpClient);
    InputStream response0 = this.getClass().getResourceAsStream("/sample/IdentifyMLP.xml");
    InputStream response1 = this.getClass().getResourceAsStream("/sample/ListRecordsMLPset.xml");
    expect(httpClient.executeGet("http://web2.mlp.cz/cgi/oai?verb=Identify")).andReturn(response0);
    expect(httpClient.executeGet("http://web2.mlp.cz/cgi/oai?verb=ListRecords&metadataPrefix=marc21&set=complete")).andReturn(response1);
    replay(httpClient);
    Map<String, JobParameter> params = new HashMap<>();
    params.put(Constants.JOB_PARAM_CONF_ID, new JobParameter(303L));
    JobExecution exec = jobExecutor.execute(Constants.JOB_ID_HARVEST, 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) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 27 with JobExecution

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

the class OAIHarvestJobTest method emptySet.

@Test
public void emptySet() throws Exception {
    reset(httpClient);
    InputStream response0 = this.getClass().getResourceAsStream("/sample/Identify.xml");
    InputStream response1 = this.getClass().getResourceAsStream("/sample/ListRecordsEmptySet.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&from=2015-01-01T01%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_FROM_DATE, new JobParameter(new Date(1420070400000L)));
    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 28 with JobExecution

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

the class OAIHarvestJobTest method testTimeGranularityConversion.

@Test
public void testTimeGranularityConversion() throws Exception {
    reset(httpClient);
    InputStream response0 = this.getClass().getResourceAsStream("/sample/IdentifyNonstandardGranularity.xml");
    InputStream response1 = this.getClass().getResourceAsStream("/sample/ListRecordsNLK.xml");
    expect(httpClient.executeGet("http://oai.medvik.cz/medvik2cpk/oai?verb=Identify")).andReturn(response0);
    expect(httpClient.executeGet("http://oai.medvik.cz/medvik2cpk/oai?verb=ListRecords&metadataPrefix=marc21&from=2015-01-01")).andReturn(response1);
    replay(httpClient);
    Map<String, JobParameter> params = new HashMap<>();
    params.put(Constants.JOB_PARAM_CONF_ID, new JobParameter(301L));
    params.put(Constants.JOB_PARAM_FROM_DATE, new JobParameter(new Date(1420070400000L)));
    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 29 with JobExecution

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

the class OAIHarvestJobTest method testHarvestOneByOne.

@Test
public void testHarvestOneByOne() throws Exception {
    reset(httpClient);
    InputStream response0 = this.getClass().getResourceAsStream("/sample/Identify.xml");
    InputStream response1 = this.getClass().getResourceAsStream("/sample/ListIdentifiersMZK.xml");
    InputStream response2 = this.getClass().getResourceAsStream("/sample/GetRecordMZK1.xml");
    InputStream response3 = this.getClass().getResourceAsStream("/sample/GetRecordMZK2.xml");
    expect(httpClient.executeGet("http://aleph.mzk.cz/OAI?verb=Identify")).andReturn(response0);
    expect(httpClient.executeGet("http://aleph.mzk.cz/OAI?verb=ListIdentifiers&metadataPrefix=marc21")).andReturn(response1);
    expect(httpClient.executeGet("http://aleph.mzk.cz/OAI?verb=GetRecord&metadataPrefix=marc21&identifier=oai%3Aaleph.mzk.cz%3AMZK01-100000151")).andReturn(response2);
    expect(httpClient.executeGet("http://aleph.mzk.cz/OAI?verb=GetRecord&metadataPrefix=marc21&identifier=oai%3Aaleph.mzk.cz%3AMZK01-100000152")).andReturn(response3);
    replay(httpClient);
    Map<String, JobParameter> params = new HashMap<>();
    params.put(Constants.JOB_PARAM_CONF_ID, new JobParameter(300L));
    JobExecution exec = jobExecutor.execute(Constants.JOB_ID_HARVEST_ONE_BY_ONE, new JobParameters(params));
    Assert.assertEquals(exec.getExitStatus(), ExitStatus.COMPLETED);
    Assert.assertNotNull(recordDao.findByIdAndHarvestConfiguration("MZK01-100000151", 300L));
    Assert.assertNotNull(recordDao.findByIdAndHarvestConfiguration("MZK01-100000152", 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 30 with JobExecution

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

the class OAIHarvestJobTest method reharvest.

@Test
public void reharvest() throws Exception {
    reset(httpClient);
    InputStream response0 = this.getClass().getResourceAsStream("/sample/Identify.xml");
    InputStream response1 = this.getClass().getResourceAsStream("/sample/ListRecordsEmptySet.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")).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_REHARVEST, new JobParameter(Constants.JOB_PARAM_TRUE_VALUE));
    params.put(Constants.JOB_PARAM_START_TIME, new JobParameter(new Date()));
    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)

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