use of org.opencastproject.oaipmh.persistence.SearchResultElementItem in project opencast by opencast.
the class OaiPmhPersistenceTest method testRetrieving.
@Test
public void testRetrieving() throws Exception {
oaiPmhDatabase.store(mp1, REPOSITORY_ID_1);
SearchResult search = oaiPmhDatabase.search(query().mediaPackageId(mp1).build());
Assert.assertEquals(1, search.size());
SearchResultItem searchResultItem = search.getItems().get(0);
Assert.assertEquals(REPOSITORY_ID_1, searchResultItem.getRepository());
Assert.assertEquals(mp1.getIdentifier().toString(), searchResultItem.getId());
Assert.assertEquals(mp1, searchResultItem.getMediaPackage());
Assert.assertFalse(searchResultItem.isDeleted());
Assert.assertEquals(DefaultOrganization.DEFAULT_ORGANIZATION_ID, searchResultItem.getOrganization());
Assert.assertTrue(searchResultItem.getModificationDate() != null);
Date modificationDate = searchResultItem.getModificationDate();
Assert.assertEquals(2, searchResultItem.getElements().size());
for (SearchResultElementItem catalogItem : searchResultItem.getElements()) {
Assert.assertNotNull(catalogItem.getFlavor());
Assert.assertNotNull(catalogItem.getXml());
Assert.assertEquals("dublincore/episode".equals(catalogItem.getFlavor().toLowerCase()), catalogItem.isEpisodeDublinCore());
Assert.assertEquals("dublincore/series".equals(catalogItem.getFlavor().toLowerCase()), catalogItem.isSeriesDublinCore());
}
Date dateBeforeStoring = new Date();
oaiPmhDatabase.store(mp1, REPOSITORY_ID_2);
search = oaiPmhDatabase.search(query().mediaPackageId(mp1).build());
Assert.assertEquals(2, search.size());
search = oaiPmhDatabase.search(query().mediaPackageId(mp1).repositoryId(REPOSITORY_ID_2).build());
Assert.assertEquals(1, search.size());
searchResultItem = search.getItems().get(0);
Assert.assertEquals(REPOSITORY_ID_2, searchResultItem.getRepository());
Assert.assertEquals(mp1.getIdentifier().toString(), searchResultItem.getId());
Assert.assertEquals(mp1, searchResultItem.getMediaPackage());
Assert.assertFalse(searchResultItem.isDeleted());
Assert.assertEquals(DefaultOrganization.DEFAULT_ORGANIZATION_ID, searchResultItem.getOrganization());
Assert.assertTrue(searchResultItem.getModificationDate() != null);
Assert.assertTrue(searchResultItem.getModificationDate().after(modificationDate));
Assert.assertEquals(2, searchResultItem.getElements().size());
for (SearchResultElementItem catalogItem : searchResultItem.getElements()) {
Assert.assertNotNull(catalogItem.getFlavor());
Assert.assertNotNull(catalogItem.getXml());
Assert.assertEquals("dublincore/episode".equals(catalogItem.getFlavor().toLowerCase()), catalogItem.isEpisodeDublinCore());
Assert.assertEquals("dublincore/series".equals(catalogItem.getFlavor().toLowerCase()), catalogItem.isSeriesDublinCore());
}
search = oaiPmhDatabase.search(query().mediaPackageId(mp1).repositoryId(REPOSITORY_ID_1).build());
Assert.assertEquals(1, search.size());
search = oaiPmhDatabase.search(query().mediaPackageId(mp1).repositoryId(REPOSITORY_ID_2).build());
Assert.assertEquals(1, search.size());
search = oaiPmhDatabase.search(query().mediaPackageId(mp1).repositoryId(REPOSITORY_ID_2).modifiedAfter(new Date()).build());
Assert.assertEquals(0, search.size());
search = oaiPmhDatabase.search(query().mediaPackageId(mp1).repositoryId(REPOSITORY_ID_2).modifiedAfter(dateBeforeStoring).build());
Assert.assertEquals(1, search.size());
search = oaiPmhDatabase.search(query().modifiedAfter(dateBeforeStoring).build());
Assert.assertEquals(1, search.size());
Date dateBeforeDeletion = new Date();
oaiPmhDatabase.delete(mp2.getIdentifier().toString(), REPOSITORY_ID_2);
Thread.sleep(10);
search = oaiPmhDatabase.search(query().modifiedAfter(new Date()).build());
Assert.assertEquals(0, search.size());
search = oaiPmhDatabase.search(query().modifiedAfter(dateBeforeDeletion).build());
Assert.assertEquals(1, search.size());
}
use of org.opencastproject.oaipmh.persistence.SearchResultElementItem in project opencast by opencast.
the class OaiPmhRepositoryTest method searchResultItem.
private SearchResultItem searchResultItem(String id, Date modified, boolean deleted) {
final String seriesDcXml = IoSupport.loadFileFromClassPathAsString("/series-dublincore.xml").get();
final String episodeDcXml = IoSupport.loadFileFromClassPathAsString("/episode-dublincore.xml").get();
final DublinCoreCatalog seriesDc = DublinCores.read(IOUtils.toInputStream(seriesDcXml));
final DublinCoreCatalog episodeDc = DublinCores.read(IOUtils.toInputStream(episodeDcXml));
final String mpXml = IoSupport.loadFileFromClassPathAsString("/manifest-full.xml").get();
final String xacml = IoSupport.loadFileFromClassPathAsString("/xacml.xml").get();
//
SearchResultItem item = EasyMock.createNiceMock(SearchResultItem.class);
EasyMock.expect(item.getModificationDate()).andReturn(modified).anyTimes();
EasyMock.expect(item.getId()).andReturn(id).anyTimes();
EasyMock.expect(item.isDeleted()).andReturn(deleted).anyTimes();
EasyMock.expect(item.getMediaPackageXml()).andReturn(mpXml).anyTimes();
SearchResultElementItem episodeDcElement = EasyMock.createNiceMock(SearchResultElementItem.class);
EasyMock.expect(episodeDcElement.getType()).andReturn("catalog").anyTimes();
EasyMock.expect(episodeDcElement.getFlavor()).andReturn("dublincore/episode").anyTimes();
EasyMock.expect(episodeDcElement.getXml()).andReturn(episodeDcXml).anyTimes();
EasyMock.expect(episodeDcElement.isEpisodeDublinCore()).andReturn(true).anyTimes();
EasyMock.expect(episodeDcElement.isSeriesDublinCore()).andReturn(false).anyTimes();
try {
EasyMock.expect(episodeDcElement.asDublinCore()).andReturn(episodeDc).anyTimes();
} catch (OaiPmhDatabaseException ex) {
}
SearchResultElementItem seriesDcElement = EasyMock.createNiceMock(SearchResultElementItem.class);
EasyMock.expect(seriesDcElement.getType()).andReturn("catalog").anyTimes();
EasyMock.expect(seriesDcElement.getFlavor()).andReturn("dublincore/series").anyTimes();
EasyMock.expect(seriesDcElement.getXml()).andReturn(seriesDcXml).anyTimes();
EasyMock.expect(seriesDcElement.isEpisodeDublinCore()).andReturn(false).anyTimes();
EasyMock.expect(seriesDcElement.isSeriesDublinCore()).andReturn(true).anyTimes();
try {
EasyMock.expect(seriesDcElement.asDublinCore()).andReturn(seriesDc).anyTimes();
} catch (OaiPmhDatabaseException ex) {
}
SearchResultElementItem securityXacmlElement = EasyMock.createNiceMock(SearchResultElementItem.class);
EasyMock.expect(securityXacmlElement.getType()).andReturn("catalog").anyTimes();
EasyMock.expect(securityXacmlElement.getFlavor()).andReturn("security/xacml+series").anyTimes();
EasyMock.expect(securityXacmlElement.getXml()).andReturn(xacml).anyTimes();
EasyMock.expect(securityXacmlElement.isEpisodeDublinCore()).andReturn(false).anyTimes();
EasyMock.expect(securityXacmlElement.isSeriesDublinCore()).andReturn(false).anyTimes();
try {
EasyMock.expect(securityXacmlElement.asDublinCore()).andThrow(new OaiPmhDatabaseException("this is not a dublincore catalog")).anyTimes();
} catch (OaiPmhDatabaseException ex) {
}
EasyMock.expect(item.getElements()).andReturn(Collections.list(episodeDcElement, seriesDcElement, securityXacmlElement)).anyTimes();
try {
EasyMock.expect(item.getEpisodeDublinCore()).andReturn(episodeDc).anyTimes();
EasyMock.expect(item.getSeriesDublinCore()).andReturn(seriesDc).anyTimes();
} catch (OaiPmhDatabaseException ex) {
}
EasyMock.replay(item, episodeDcElement, seriesDcElement, securityXacmlElement);
return item;
}
Aggregations