Search in sources :

Example 1 with AbstractJobProducer

use of org.opencastproject.job.api.AbstractJobProducer in project opencast by opencast.

the class OaiPmhPublicationServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    mp = MediaPackageSupport.loadFromClassPath("/mediapackage.xml");
    mp2 = MediaPackageSupport.loadFromClassPath("/mediapackage2.xml");
    validOaiPmhRepositories = Collections.list("default");
    OaiPmhServerInfo oaiPmhServerInfo = EasyMock.createNiceMock(OaiPmhServerInfo.class);
    EasyMock.expect(oaiPmhServerInfo.hasRepo(anyString())).andAnswer(() -> validOaiPmhRepositories.contains((String) EasyMock.getCurrentArguments()[0])).anyTimes();
    EasyMock.expect(oaiPmhServerInfo.getMountPoint()).andReturn(OAI_PMH_SERVER_MOUNT_POINT).anyTimes();
    DefaultOrganization org = new DefaultOrganization() {

        @Override
        public Map<String, String> getProperties() {
            HashMap<String, String> props = new HashMap<>();
            props.putAll(DEFAULT_PROPERTIES);
            props.put(ORG_CFG_OAIPMH_SERVER_HOSTURL, OAI_PMH_SERVER_URL);
            return props;
        }
    };
    HashSet<JaxbRole> roles = new HashSet<JaxbRole>();
    roles.add(new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ADMIN, org, ""));
    User user = new JaxbUser("admin", "test", org, roles);
    OrganizationDirectoryService orgDirectory = EasyMock.createNiceMock(OrganizationDirectoryService.class);
    EasyMock.expect(orgDirectory.getOrganization((String) EasyMock.anyObject())).andReturn(org).anyTimes();
    UserDirectoryService userDirectory = EasyMock.createNiceMock(UserDirectoryService.class);
    EasyMock.expect(userDirectory.loadUser("admin")).andReturn(user).anyTimes();
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getOrganization()).andReturn(org).anyTimes();
    EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
    serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectory, orgDirectory, EasyMock.createNiceMock(IncidentService.class));
    // Finish setting up the mocks
    EasyMock.replay(oaiPmhServerInfo, orgDirectory, userDirectory, securityService);
    service = new OaiPmhPublicationServiceImpl();
    service.setOaiPmhServerInfo(oaiPmhServerInfo);
    service.setSecurityService(securityService);
    service.setServiceRegistry(serviceRegistry);
    // mock streaming/download distribution jobs dispatching
    AbstractJobProducer distributionJobProducerMock = new AbstractJobProducer("distribute") {

        @Override
        protected ServiceRegistry getServiceRegistry() {
            return serviceRegistry;
        }

        @Override
        protected SecurityService getSecurityService() {
            return securityService;
        }

        @Override
        protected UserDirectoryService getUserDirectoryService() {
            return userDirectory;
        }

        @Override
        protected OrganizationDirectoryService getOrganizationDirectoryService() {
            return orgDirectory;
        }

        @Override
        protected String process(Job job) throws Exception {
            return job.getPayload();
        }

        @Override
        public boolean isReadyToAccept(Job job) throws ServiceRegistryException, UndispatchableJobException {
            return true;
        }
    };
    serviceRegistry.registerService(distributionJobProducerMock);
}
Also used : User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) HashMap(java.util.HashMap) JaxbUser(org.opencastproject.security.api.JaxbUser) EasyMock.anyString(org.easymock.EasyMock.anyString) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) OaiPmhServerInfo(org.opencastproject.oaipmh.server.OaiPmhServerInfo) JaxbRole(org.opencastproject.security.api.JaxbRole) AbstractJobProducer(org.opencastproject.job.api.AbstractJobProducer) SecurityService(org.opencastproject.security.api.SecurityService) Job(org.opencastproject.job.api.Job) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) HashSet(java.util.HashSet) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Before(org.junit.Before)

Aggregations

HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 EasyMock.anyString (org.easymock.EasyMock.anyString)1 Before (org.junit.Before)1 AbstractJobProducer (org.opencastproject.job.api.AbstractJobProducer)1 Job (org.opencastproject.job.api.Job)1 OaiPmhServerInfo (org.opencastproject.oaipmh.server.OaiPmhServerInfo)1 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)1 JaxbRole (org.opencastproject.security.api.JaxbRole)1 JaxbUser (org.opencastproject.security.api.JaxbUser)1 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)1 SecurityService (org.opencastproject.security.api.SecurityService)1 User (org.opencastproject.security.api.User)1 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)1 ServiceRegistryInMemoryImpl (org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl)1