use of org.opencastproject.oaipmh.persistence.Query in project opencast by opencast.
the class OaiPmhRepositoryTest method testResumption.
@Ignore
@Test
@SuppressWarnings("unchecked")
public void testResumption() throws Exception {
List<SearchResultItem> items1 = new ArrayList<SearchResultItem>();
items1.add(searchResultItem("id-1", utcDate(2011, 5, 10), false));
items1.add(searchResultItem("id-2", utcDate(2011, 5, 11), false));
items1.add(searchResultItem("id-3", utcDate(2011, 5, 12), false));
List<SearchResultItem> items2 = new ArrayList<SearchResultItem>();
items2.add(searchResultItem("id-4", utcDate(2011, 5, 13), false));
items2.add(searchResultItem("id-5", utcDate(2011, 5, 14), false));
// setup episode service mock
// this setup is really ugly since it needs knowledge about implementation details
OaiPmhDatabase persistence = EasyMock.createMock(OaiPmhDatabase.class);
SearchResult result = EasyMock.createMock(SearchResult.class);
EasyMock.expect(result.getItems()).andReturn(items1).times(3).andReturn(items2).times(3);
EasyMock.expect(result.getLimit()).andReturn(RESULT_LIMIT).anyTimes();
EasyMock.expect(result.getOffset()).andReturn(0L).times(3).andReturn(RESULT_LIMIT).anyTimes();
EasyMock.expect(result.size()).andReturn((long) items1.size()).times(4).andReturn((long) items2.size()).times(4);
EasyMock.expect(persistence.search(EasyMock.<Query>anyObject())).andReturn(result).anyTimes();
EasyMock.replay(persistence);
EasyMock.replay(result);
// do testing
final OaiPmhRepository repo = repo(persistence, Granularity.DAY);
runChecks(OaiPmhConstants.VERB_LIST_IDENTIFIERS, repo.selectVerb(params("ListIdentifiers", null, "oai_dc", null, null, null)), some(IsValid), list(hasXPath("count(//oai20:ListIdentifiers/oai20:header)", NS_CTX, returningANumber(), equalTo(3.0)), hasXPath("//oai20:ListIdentifiers/oai20:resumptionToken/text()", NS_CTX, returningAString(), equalTo("r-token")), hasXPath("//oai20:ListIdentifiers/oai20:header[1]/oai20:identifier/text()", NS_CTX, returningAString(), equalTo("id-1")), hasXPath("//oai20:ListIdentifiers/oai20:header[2]/oai20:identifier/text()", NS_CTX, returningAString(), equalTo("id-2")), hasXPath("//oai20:ListIdentifiers/oai20:header[3]/oai20:identifier/text()", NS_CTX, returningAString(), equalTo("id-3"))));
// resume query
runChecks(OaiPmhConstants.VERB_LIST_IDENTIFIERS, repo.selectVerb(params("ListIdentifiers", null, null, null, null, "r-token")), some(IsValid), list(hasXPath("count(//oai20:ListIdentifiers/oai20:header)", NS_CTX, returningANumber(), equalTo(2.0)), hasXPath("//oai20:ListIdentifiers/oai20:header[1]/oai20:identifier/text()", NS_CTX, returningAString(), equalTo("id-4")), hasXPath("//oai20:ListIdentifiers/oai20:header[2]/oai20:identifier/text()", NS_CTX, returningAString(), equalTo("id-5")), // token must be empty now since there are no more pages
hasXPath("//oai20:ListIdentifiers/oai20:resumptionToken/text()", NS_CTX, returningAString(), equalTo(""))));
EasyMock.verify(repo.getPersistence());
}
use of org.opencastproject.oaipmh.persistence.Query in project opencast by opencast.
the class OaiPmhRepositoryTest method oaiPmhPersistenceMock.
private static OaiPmhDatabase oaiPmhPersistenceMock(SearchResultItem... items) {
final SearchResult result = EasyMock.createNiceMock(SearchResult.class);
final List<SearchResultItem> db = list(items);
EasyMock.expect(result.getItems()).andReturn(db).anyTimes();
EasyMock.expect(result.size()).andReturn((long) items.length).anyTimes();
EasyMock.replay(result);
return new OaiPmhDatabase() {
@Override
public void store(MediaPackage mediaPackage, String repository) throws OaiPmhDatabaseException {
// To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void delete(String mediaPackageId, String repository) throws OaiPmhDatabaseException, NotFoundException {
// To change body of implemented methods use File | Settings | File Templates.
}
@Override
public SearchResult search(Query q) {
return result;
}
};
}
Aggregations