use of org.opencastproject.metadata.api.StaticMetadataService in project opencast by opencast.
the class SearchServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
// workspace
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andAnswer(new IAnswer<File>() {
@Override
public File answer() throws Throwable {
return new File(new URI(EasyMock.getCurrentArguments()[0].toString()));
}
}).anyTimes();
EasyMock.replay(workspace);
// User, organization and service registry
userResponder = new Responder<User>(defaultUser);
organizationResponder = new Responder<Organization>(defaultOrganization);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andAnswer(userResponder).anyTimes();
EasyMock.expect(securityService.getOrganization()).andAnswer(organizationResponder).anyTimes();
EasyMock.replay(securityService);
User anonymous = new JaxbUser("anonymous", "test", defaultOrganization, new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, defaultOrganization));
UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(anonymous).anyTimes();
EasyMock.replay(userDirectoryService);
Organization organization = new DefaultOrganization();
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
EasyMock.replay(organizationDirectoryService);
// mpeg7 service
Mpeg7CatalogService mpeg7CatalogService = new Mpeg7CatalogService();
// Persistence storage
searchDatabase = new SearchServiceDatabaseImpl();
searchDatabase.setEntityManagerFactory(newTestEntityManagerFactory(SearchServiceDatabaseImpl.PERSISTENCE_UNIT));
searchDatabase.activate(null);
searchDatabase.setSecurityService(securityService);
// search service
service = new SearchServiceImpl();
serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
StaticMetadataService mdService = newStaticMetadataService(workspace);
SeriesService seriesService = EasyMock.createNiceMock(SeriesService.class);
DublinCoreCatalog seriesCatalog = getSeriesDublinCoreCatalog("/series-dublincore.xml");
AccessControlList seriesAcl = new AccessControlList();
EasyMock.expect(seriesService.getSeries((String) EasyMock.anyObject())).andReturn(seriesCatalog).anyTimes();
EasyMock.expect(seriesService.getSeriesAccessControl((String) EasyMock.anyObject())).andReturn(seriesAcl).anyTimes();
EasyMock.replay(seriesService);
service.setStaticMetadataService(mdService);
service.setWorkspace(workspace);
service.setMpeg7CatalogService(mpeg7CatalogService);
service.setSecurityService(securityService);
service.setOrganizationDirectoryService(organizationDirectoryService);
service.setUserDirectoryService(userDirectoryService);
service.setServiceRegistry(serviceRegistry);
service.setPersistence(searchDatabase);
SolrServer solrServer = SearchServiceImpl.setupSolr(new File(solrRoot));
service.testSetup(solrServer, new SolrRequester(solrServer, securityService), new SolrIndexManager(solrServer, workspace, Arrays.asList(mdService), seriesService, mpeg7CatalogService, securityService));
// acl
String anonymousRole = securityService.getOrganization().getAnonymousRole();
acl = new AccessControlList(new AccessControlEntry(anonymousRole, Permissions.Action.READ.toString(), true));
authorizationService = EasyMock.createNiceMock(AuthorizationService.class);
EasyMock.expect(authorizationService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
EasyMock.expect(authorizationService.hasPermission((MediaPackage) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(true).anyTimes();
service.setAuthorizationService(authorizationService);
EasyMock.replay(authorizationService);
}
Aggregations