Search in sources :

Example 1 with OaiPmhDatabase

use of org.opencastproject.oaipmh.persistence.OaiPmhDatabase in project opencast by opencast.

the class OaiPmhPublicationServiceImplTest method testPublishInternal.

@Ignore
@Test
public void testPublishInternal() throws PublicationException, OaiPmhDatabaseException, MediaPackageException, DistributionException {
    OaiPmhDatabase oaiDb = EasyMock.createNiceMock(OaiPmhDatabase.class);
    // mock empty DB
    EasyMock.expect(oaiDb.search(EasyMock.anyObject(Query.class))).andReturn(new SearchResultImpl(0, 0, new ArrayList<>())).once();
    Capture<MediaPackage> storedMpCap = EasyMock.newCapture();
    // capture stored media package
    oaiDb.store(capture(storedMpCap), eq("default"));
    EasyMock.replay(oaiDb);
    service.setOaiPmhDatabase(oaiDb);
    // mock download distribution service
    DownloadDistributionService downloadDistributionService = EasyMock.createNiceMock(DownloadDistributionService.class);
    Capture<MediaPackage> downloadDistributedMpCap = EasyMock.newCapture();
    Capture<Set<String>> downloadDistributedElemIdsCap = EasyMock.newCapture();
    EasyMock.expect(downloadDistributionService.distribute(EasyMock.contains("default"), capture(downloadDistributedMpCap), capture(downloadDistributedElemIdsCap), eq(true))).andAnswer(() -> serviceRegistry.createJob("distribute", "download", null, serializeMediaPackageElements((MediaPackage) EasyMock.getCurrentArguments()[1]))).anyTimes();
    EasyMock.replay(downloadDistributionService);
    service.setDownloadDistributionService(downloadDistributionService);
    // mock streaming distribution service
    StreamingDistributionService streamingDistributionService = EasyMock.createNiceMock(StreamingDistributionService.class);
    Capture<MediaPackage> streamingDistributedMpCap = EasyMock.newCapture();
    Capture<Set<String>> streamingDistributedElemIdsCap = EasyMock.newCapture();
    EasyMock.expect(streamingDistributionService.distribute(EasyMock.contains("default"), capture(streamingDistributedMpCap), capture(streamingDistributedElemIdsCap))).andAnswer(() -> serviceRegistry.createJob("distribute", "streaming", null, serializeMediaPackageElements((MediaPackage) EasyMock.getCurrentArguments()[1]))).anyTimes();
    EasyMock.replay(streamingDistributionService);
    service.setStreamingDistributionService(streamingDistributionService);
    Publication publication = service.publish(null, mp, "default", Collections.set("catalog-1", "track-1"), Collections.set("track-1"), true);
    Assert.assertNotNull(publication);
    Assert.assertNotNull(publication.getChannel());
    Assert.assertTrue(publication.getChannel().contains("default"));
    Assert.assertNotNull(publication.getURI());
    Assert.assertEquals(URI.create(OAI_PMH_SERVER_URL).getHost(), publication.getURI().getHost());
    Assert.assertTrue(publication.getURI().getPath().startsWith(OAI_PMH_SERVER_MOUNT_POINT));
    Assert.assertTrue(downloadDistributedMpCap.hasCaptured());
    // check distributed elements
    // download distribution elements
    MediaPackage mp = downloadDistributedMpCap.getValue();
    Assert.assertEquals(2, mp.getElements().length);
    Assert.assertEquals(1, mp.getElementsByFlavor(parseFlavor("dublincore/episode")).length);
    Assert.assertNotEquals("catalog-1", mp.getElementsByFlavor(parseFlavor("dublincore/episode"))[0].getIdentifier());
    Assert.assertEquals(1, mp.getElementsByFlavor(parseFlavor("presentation/source")).length);
    Assert.assertNotEquals("track-1", mp.getElementsByFlavor(parseFlavor("presentation/source"))[0].getIdentifier());
    // streaming distribution elements
    Assert.assertTrue(streamingDistributedMpCap.hasCaptured());
    mp = streamingDistributedMpCap.getValue();
    Assert.assertEquals(1, mp.getElements().length);
    Assert.assertEquals(1, mp.getElementsByFlavor(parseFlavor("presentation/source")).length);
    Assert.assertNotEquals("track-1", mp.getElementsByFlavor(parseFlavor("presentation/source"))[0].getIdentifier());
    // check stored media package
    Assert.assertTrue(storedMpCap.hasCaptured());
    mp = storedMpCap.getValue();
    Assert.assertEquals(4, mp.getElements().length);
    Assert.assertEquals(1, mp.getElementsByFlavor(parseFlavor("dublincore/episode")).length);
    Assert.assertEquals(2, mp.getElementsByFlavor(parseFlavor("presentation/source")).length);
    Assert.assertEquals(1, mp.getPublications().length);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StreamingDistributionService(org.opencastproject.distribution.api.StreamingDistributionService) SearchResultImpl(org.opencastproject.oaipmh.persistence.impl.SearchResultImpl) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Publication(org.opencastproject.mediapackage.Publication) OaiPmhDatabase(org.opencastproject.oaipmh.persistence.OaiPmhDatabase) DownloadDistributionService(org.opencastproject.distribution.api.DownloadDistributionService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with OaiPmhDatabase

use of org.opencastproject.oaipmh.persistence.OaiPmhDatabase 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());
}
Also used : Query(org.opencastproject.oaipmh.persistence.Query) SearchResultItem(org.opencastproject.oaipmh.persistence.SearchResultItem) ArrayList(java.util.ArrayList) SearchResult(org.opencastproject.oaipmh.persistence.SearchResult) OaiPmhDatabase(org.opencastproject.oaipmh.persistence.OaiPmhDatabase) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with OaiPmhDatabase

use of org.opencastproject.oaipmh.persistence.OaiPmhDatabase 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;
        }
    };
}
Also used : Query(org.opencastproject.oaipmh.persistence.Query) SearchResultItem(org.opencastproject.oaipmh.persistence.SearchResultItem) MediaPackage(org.opencastproject.mediapackage.MediaPackage) SearchResult(org.opencastproject.oaipmh.persistence.SearchResult) XpathReturnType.returningAString(org.xmlmatchers.xpath.XpathReturnType.returningAString) OaiPmhDatabase(org.opencastproject.oaipmh.persistence.OaiPmhDatabase)

Aggregations

OaiPmhDatabase (org.opencastproject.oaipmh.persistence.OaiPmhDatabase)3 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2 MediaPackage (org.opencastproject.mediapackage.MediaPackage)2 Query (org.opencastproject.oaipmh.persistence.Query)2 SearchResult (org.opencastproject.oaipmh.persistence.SearchResult)2 SearchResultItem (org.opencastproject.oaipmh.persistence.SearchResultItem)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 DownloadDistributionService (org.opencastproject.distribution.api.DownloadDistributionService)1 StreamingDistributionService (org.opencastproject.distribution.api.StreamingDistributionService)1 Publication (org.opencastproject.mediapackage.Publication)1 SearchResultImpl (org.opencastproject.oaipmh.persistence.impl.SearchResultImpl)1 XpathReturnType.returningAString (org.xmlmatchers.xpath.XpathReturnType.returningAString)1