Search in sources :

Example 21 with MarcRecord

use of cz.mzk.recordmanager.server.marc.MarcRecord in project RecordManager2 by moravianlibrary.

the class CosmotronHarvestJobTest method test996BeforeRecord.

@Test
public void test996BeforeRecord() throws Exception {
    reset(httpClient);
    InputStream response0 = this.getClass().getResourceAsStream("/sample/Identify.xml");
    InputStream response1 = this.getClass().getResourceAsStream("/sample/cosmotron/996BeforeRecord.xml");
    expect(httpClient.executeGet("http://katalog.cbvk.cz/i2/i2.ws.oai.cls?verb=Identify")).andReturn(response0);
    expect(httpClient.executeGet("http://katalog.cbvk.cz/i2/i2.ws.oai.cls?verb=ListRecords&metadataPrefix=oai_marcxml_cpk")).andReturn(response1);
    replay(httpClient);
    final Long confID = 328L;
    Map<String, JobParameter> params = new HashMap<>();
    params.put(Constants.JOB_PARAM_CONF_ID, new JobParameter(confID));
    JobExecution exec = jobExecutor.execute(Constants.JOB_ID_HARVEST_COSMOTRON, new JobParameters(params));
    Assert.assertEquals(exec.getExitStatus(), ExitStatus.COMPLETED);
    OAIHarvestConfiguration config = configDao.get(confID);
    HarvestedRecord hr = recordDao.findByIdAndHarvestConfiguration("CbvkUsCat" + Constants.COSMOTRON_RECORD_ID_CHAR + "m0000002", config);
    Assert.assertNotNull(hr);
    Assert.assertNotNull(cosmotronDao.findByIdAndHarvestConfiguration("CbvkUsCat" + Constants.COSMOTRON_RECORD_ID_CHAR + "0000003", config));
    Assert.assertNotNull(cosmotronDao.findByIdAndHarvestConfiguration("CbvkUsCat" + Constants.COSMOTRON_RECORD_ID_CHAR + "0000004", config));
    Assert.assertNotNull(cosmotronDao.findByIdAndHarvestConfiguration("CbvkUsCat" + Constants.COSMOTRON_RECORD_ID_CHAR + "0000005", config));
    InputStream is = new ByteArrayInputStream(hr.getRawRecord());
    Record record = marcXmlParser.parseUnderlyingRecord(is);
    MarcRecord marcRecord = new MarcRecordImpl(record);
    Assert.assertEquals(marcRecord.getDataFields("996").size(), 3);
}
Also used : OAIHarvestConfiguration(cz.mzk.recordmanager.server.model.OAIHarvestConfiguration) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) JobExecution(org.springframework.batch.core.JobExecution) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) Record(org.marc4j.marc.Record) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord) JobParameters(org.springframework.batch.core.JobParameters) JobParameter(org.springframework.batch.core.JobParameter) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 22 with MarcRecord

use of cz.mzk.recordmanager.server.marc.MarcRecord in project RecordManager2 by moravianlibrary.

the class CosmotronHarvestJobTest method testNew996.

@Test
public void testNew996() throws Exception {
    reset(httpClient);
    InputStream response0 = this.getClass().getResourceAsStream("/sample/Identify.xml");
    InputStream response1 = this.getClass().getResourceAsStream("/sample/cosmotron/New9961.xml");
    InputStream response2 = this.getClass().getResourceAsStream("/sample/cosmotron/New9962.xml");
    expect(httpClient.executeGet("http://katalog.cbvk.cz/i2/i2.ws.oai.cls?verb=Identify")).andReturn(response0);
    expect(httpClient.executeGet("http://katalog.cbvk.cz/i2/i2.ws.oai.cls?verb=ListRecords&metadataPrefix=oai_marcxml_cpk")).andReturn(response1);
    expect(httpClient.executeGet("http://katalog.cbvk.cz/i2/i2.ws.oai.cls?verb=ListRecords&resumptionToken=12345")).andReturn(response2);
    replay(httpClient);
    final Long confID = 328L;
    Map<String, JobParameter> params = new HashMap<>();
    params.put(Constants.JOB_PARAM_CONF_ID, new JobParameter(confID));
    JobExecution exec = jobExecutor.execute(Constants.JOB_ID_HARVEST_COSMOTRON, new JobParameters(params));
    Assert.assertEquals(exec.getExitStatus(), ExitStatus.COMPLETED);
    OAIHarvestConfiguration config = configDao.get(confID);
    HarvestedRecord hr = recordDao.findByIdAndHarvestConfiguration("CbvkUsCat" + Constants.COSMOTRON_RECORD_ID_CHAR + "m0000002", config);
    Assert.assertNotNull(hr);
    Assert.assertNotNull(cosmotronDao.findByIdAndHarvestConfiguration("CbvkUsCat" + Constants.COSMOTRON_RECORD_ID_CHAR + "0000003", config));
    Assert.assertNotNull(cosmotronDao.findByIdAndHarvestConfiguration("CbvkUsCat" + Constants.COSMOTRON_RECORD_ID_CHAR + "0000004", config));
    InputStream is = new ByteArrayInputStream(hr.getRawRecord());
    Record record = marcXmlParser.parseUnderlyingRecord(is);
    MarcRecord marcRecord = new MarcRecordImpl(record);
    Assert.assertEquals(marcRecord.getDataFields("996").size(), 5);
}
Also used : OAIHarvestConfiguration(cz.mzk.recordmanager.server.model.OAIHarvestConfiguration) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) JobExecution(org.springframework.batch.core.JobExecution) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) Record(org.marc4j.marc.Record) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord) JobParameters(org.springframework.batch.core.JobParameters) JobParameter(org.springframework.batch.core.JobParameter) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 23 with MarcRecord

use of cz.mzk.recordmanager.server.marc.MarcRecord in project RecordManager2 by moravianlibrary.

the class MarcScriptFactoryTest method test1.

@Test
@SuppressWarnings("unchecked")
public void test1() {
    MarcRecord record = parser.parseRecord(this.getClass().getResourceAsStream("/records/marcxml/MZK01-001439241.xml"));
    InputStream is1 = getClass().getResourceAsStream("/groovy/ExtendedMarc.groovy");
    InputStream is2 = getClass().getResourceAsStream("/groovy/BaseMarc.groovy");
    MappingScript<MarcFunctionContext> script = factory.create(is1, is2);
    MarcFunctionContext ctx = new MarcFunctionContext(record, metadataRecordFactory.getMetadataRecord(record));
    Map<String, Object> entries = script.parse(ctx);
    Assert.assertEquals(entries.get("author"), null);
    Assert.assertEquals(entries.get("published"), "Rožnov pod Radhoštěm : Proxima Bohemia, 2014");
    Assert.assertEquals(entries.get("title"), "Česká republika : města a obce České republiky : tradice, historie, památky, turistika, současnost /");
    Assert.assertNotNull(entries.get("language"));
    Assert.assertTrue(entries.get("language") instanceof List<?>);
    List<String> languages = (List<String>) entries.get("language");
    Assert.assertEquals(languages.size(), 1);
    Assert.assertEquals(languages.get(0), "Czech");
}
Also used : InputStream(java.io.InputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) List(java.util.List) MarcFunctionContext(cz.mzk.recordmanager.server.scripting.marc.MarcFunctionContext) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 24 with MarcRecord

use of cz.mzk.recordmanager.server.marc.MarcRecord in project RecordManager2 by moravianlibrary.

the class BoundingBoxMarcFunctionsTest method testPrague.

@Test
public void testPrague() throws Exception {
    List<String> data = new ArrayList<String>();
    data.add("034 $aa $b20000 $dE0141016 $eE0144724 $fN0501302 $gN0495545");
    MarcRecord record = MarcRecordFactory.recordFactory(data);
    String result = functions.getBoundingBox(new MarcFunctionContext(record, null, null));
    Assert.assertEquals(result, "14.171111111111111 49.92916666666667 14.79 50.217222222222226");
}
Also used : ArrayList(java.util.ArrayList) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) MarcFunctionContext(cz.mzk.recordmanager.server.scripting.marc.MarcFunctionContext) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 25 with MarcRecord

use of cz.mzk.recordmanager.server.marc.MarcRecord in project RecordManager2 by moravianlibrary.

the class BoundingBoxMarcFunctionsTest method testInvalidRecord.

@Test
public void testInvalidRecord() throws Exception {
    List<String> data = new ArrayList<String>();
    data.add("034 $aa $dE0142526 $eE0142526 $fN0500516 $gN0500516");
    MarcRecord record = MarcRecordFactory.recordFactory(data);
    String result = functions.getBoundingBox(new MarcFunctionContext(record, null, null));
    Assert.assertNull(result);
}
Also used : ArrayList(java.util.ArrayList) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) MarcFunctionContext(cz.mzk.recordmanager.server.scripting.marc.MarcFunctionContext) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Aggregations

MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)46 ByteArrayInputStream (java.io.ByteArrayInputStream)22 MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)21 InputStream (java.io.InputStream)19 Record (org.marc4j.marc.Record)19 AbstractTest (cz.mzk.recordmanager.server.AbstractTest)15 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)15 DataField (org.marc4j.marc.DataField)15 Test (org.testng.annotations.Test)15 List (java.util.List)13 ArrayList (java.util.ArrayList)11 TreeSet (java.util.TreeSet)11 ControlField (org.marc4j.marc.ControlField)11 RecordImpl (cz.mzk.recordmanager.server.marc.marc4j.RecordImpl)10 MarcFunctionContext (cz.mzk.recordmanager.server.scripting.marc.MarcFunctionContext)9 JobParameters (org.springframework.batch.core.JobParameters)8 HashMap (java.util.HashMap)7 JobParameter (org.springframework.batch.core.JobParameter)7 MarcFactoryImpl (cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl)5 MarcFactory (org.marc4j.marc.MarcFactory)5