use of org.opencastproject.oaipmh.server.OaiPmhServerInfo 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);
}
Aggregations