Search in sources :

Example 1 with StreamingDistributionService

use of org.opencastproject.distribution.api.StreamingDistributionService 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)

Aggregations

HashSet (java.util.HashSet)1 Set (java.util.Set)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 DownloadDistributionService (org.opencastproject.distribution.api.DownloadDistributionService)1 StreamingDistributionService (org.opencastproject.distribution.api.StreamingDistributionService)1 MediaPackage (org.opencastproject.mediapackage.MediaPackage)1 Publication (org.opencastproject.mediapackage.Publication)1 OaiPmhDatabase (org.opencastproject.oaipmh.persistence.OaiPmhDatabase)1 SearchResultImpl (org.opencastproject.oaipmh.persistence.impl.SearchResultImpl)1