Search in sources :

Example 1 with AbstractOaiPmhDatabase

use of org.opencastproject.oaipmh.persistence.impl.AbstractOaiPmhDatabase in project opencast by opencast.

the class OaiPmhRepositoryPersistenceTest method oaiPmhDatabase.

private static AbstractOaiPmhDatabase oaiPmhDatabase(MediaPackage... mps) {
    try {
        final Organization org = new DefaultOrganization();
        final SecurityService secSvc = EasyMock.createNiceMock(SecurityService.class);
        // security service
        final User user = createSystemUser("admin", org);
        expect(secSvc.getOrganization()).andReturn(org).anyTimes();
        expect(secSvc.getUser()).andReturn(user).anyTimes();
        EasyMock.replay(secSvc);
        // series service
        final SeriesService seriesService = EasyMock.createNiceMock(SeriesService.class);
        final String xacml = IOUtils.toString(OaiPmhRepositoryPersistenceTest.class.getResource("/xacml.xml").toURI());
        final AccessControlList securityACL = AccessControlParser.parseAcl(xacml);
        EasyMock.expect(seriesService.getSeriesAccessControl("10.0000/1")).andReturn(securityACL).anyTimes();
        EasyMock.replay(seriesService);
        // workspace
        final Workspace workspace = EasyMock.createNiceMock(Workspace.class);
        final File episodeDublinCore = new File(OaiPmhRepositoryPersistenceTest.class.getResource("/episode-dublincore.xml").toURI());
        final File seriesDublinCore = new File(OaiPmhRepositoryPersistenceTest.class.getResource("/series-dublincore.xml").toURI());
        expect(workspace.read(EasyMock.anyObject())).andAnswer(() -> {
            final String uri = getCurrentArguments()[0].toString();
            if ("dublincore.xml".equals(uri))
                return new FileInputStream(episodeDublinCore);
            if ("series-dublincore.xml".equals(uri))
                return new FileInputStream(seriesDublinCore);
            throw new Error("Workspace mock does not know about file " + uri);
        }).anyTimes();
        EasyMock.replay(workspace);
        // oai-pmh database
        final EntityManagerFactory emf = PersistenceUtil.newTestEntityManagerFactory(OaiPmhDatabaseImpl.PERSISTENCE_UNIT_NAME);
        final AbstractOaiPmhDatabase db = new AbstractOaiPmhDatabase() {

            @Override
            public EntityManagerFactory getEmf() {
                return emf;
            }

            @Override
            public SecurityService getSecurityService() {
                return secSvc;
            }

            @Override
            public Workspace getWorkspace() {
                return workspace;
            }

            @Override
            public Date currentDate() {
                return new Date();
            }
        };
        for (MediaPackage mp : mps) db.store(mp, REPOSITORY_ID);
        return db;
    } catch (Exception e) {
        return chuck(e);
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) AbstractOaiPmhDatabase(org.opencastproject.oaipmh.persistence.impl.AbstractOaiPmhDatabase) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) User(org.opencastproject.security.api.User) SecurityUtil.createSystemUser(org.opencastproject.security.util.SecurityUtil.createSystemUser) FileInputStream(java.io.FileInputStream) Date(java.util.Date) EncodingSchemeUtils.encodeDate(org.opencastproject.metadata.dublincore.EncodingSchemeUtils.encodeDate) TransformerException(javax.xml.transform.TransformerException) SeriesService(org.opencastproject.series.api.SeriesService) SecurityService(org.opencastproject.security.api.SecurityService) EntityManagerFactory(javax.persistence.EntityManagerFactory) MediaPackage(org.opencastproject.mediapackage.MediaPackage) File(java.io.File) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Workspace(org.opencastproject.workspace.api.Workspace)

Aggregations

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 Date (java.util.Date)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 TransformerException (javax.xml.transform.TransformerException)1 MediaPackage (org.opencastproject.mediapackage.MediaPackage)1 EncodingSchemeUtils.encodeDate (org.opencastproject.metadata.dublincore.EncodingSchemeUtils.encodeDate)1 AbstractOaiPmhDatabase (org.opencastproject.oaipmh.persistence.impl.AbstractOaiPmhDatabase)1 AccessControlList (org.opencastproject.security.api.AccessControlList)1 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)1 Organization (org.opencastproject.security.api.Organization)1 SecurityService (org.opencastproject.security.api.SecurityService)1 User (org.opencastproject.security.api.User)1 SecurityUtil.createSystemUser (org.opencastproject.security.util.SecurityUtil.createSystemUser)1 SeriesService (org.opencastproject.series.api.SeriesService)1 Workspace (org.opencastproject.workspace.api.Workspace)1