use of org.opencastproject.search.api.SearchQuery in project opencast by opencast.
the class SearchServiceImplTest method testSearchForEpisodeWithSeriesMetadata.
/**
* Tests whether an episode can be found based on its series metadata.
*/
@Test
public void testSearchForEpisodeWithSeriesMetadata() throws Exception {
MediaPackage mediaPackage = getMediaPackage("/manifest-full.xml");
Job job = service.add(mediaPackage);
JobBarrier barrier = new JobBarrier(null, serviceRegistry, 1000, job);
barrier.waitForJobs();
assertEquals("Job to add mediapckage did not finish", Job.Status.FINISHED, job.getStatus());
SearchResult episodeMetadataResult = service.getByQuery(new SearchQuery().withText("Vegetation"));
SearchResult seriesMetadataResult = service.getByQuery(new SearchQuery().withText("Atmospheric Science"));
assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmospheric")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("atmospheric")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("atmospheric science")).size());
assertEquals(1, episodeMetadataResult.getItems().length);
assertEquals(1, seriesMetadataResult.getItems().length);
}
use of org.opencastproject.search.api.SearchQuery in project opencast by opencast.
the class SearchServiceImplTest method testPopulateIndex.
@SuppressWarnings("unchecked")
@Test
public void testPopulateIndex() throws Exception {
// This service registry must return a list of jobs
List<String> args = new ArrayList<String>();
args.add(new DefaultOrganization().getId());
List<Job> jobs = new ArrayList<Job>();
for (long i = 0; i < 10; i++) {
MediaPackage mediaPackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
mediaPackage.setIdentifier(IdBuilderFactory.newInstance().newIdBuilder().createNew());
searchDatabase.storeMediaPackage(mediaPackage, acl, new Date());
String payload = MediaPackageParser.getAsXml(mediaPackage);
Job job = new JobImpl(i);
job.setArguments(args);
job.setPayload(payload);
job.setStatus(Status.FINISHED);
jobs.add(job);
}
ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
EasyMock.expect(serviceRegistry.createJob((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (List<String>) EasyMock.anyObject(), (String) EasyMock.anyObject(), EasyMock.anyBoolean())).andReturn(new JobImpl()).anyTimes();
EasyMock.expect(serviceRegistry.updateJob((Job) EasyMock.anyObject())).andReturn(new JobImpl()).anyTimes();
EasyMock.expect(serviceRegistry.getJobs((String) EasyMock.anyObject(), (Status) EasyMock.anyObject())).andReturn(jobs).anyTimes();
EasyMock.replay(serviceRegistry);
service.setServiceRegistry(serviceRegistry);
OrganizationDirectoryService orgDirectory = EasyMock.createNiceMock(OrganizationDirectoryService.class);
EasyMock.expect(orgDirectory.getOrganization((String) EasyMock.anyObject())).andReturn(new DefaultOrganization()).anyTimes();
EasyMock.replay(orgDirectory);
service.setOrganizationDirectoryService(orgDirectory);
// We should have nothing in the search index
assertEquals(0, service.getByQuery(new SearchQuery()).size());
service.populateIndex("System Admin");
// This time we should have 10 results
assertEquals(10, service.getByQuery(new SearchQuery()).size());
}
use of org.opencastproject.search.api.SearchQuery in project opencast by opencast.
the class SearchServiceImplTest method testDeleteMediaPackage.
/**
* Test removal from the search index.
*/
@Test
public void testDeleteMediaPackage() throws Exception {
MediaPackage mediaPackage = getMediaPackage("/manifest-simple.xml");
// Make sure our mocked ACL has the read and write permission
acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, READ.toString(), true));
acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, WRITE.toString(), true));
// Add the media package to the search index
Job job = service.add(mediaPackage);
JobBarrier barrier = new JobBarrier(null, serviceRegistry, 1000, job);
barrier.waitForJobs();
// Now take the role away from the user
userResponder.setResponse(userWithoutPermissions);
Map<String, Integer> servers = new HashMap<String, Integer>();
servers.put("http://localhost", 8080);
organizationResponder.setResponse(new JaxbOrganization(DefaultOrganization.DEFAULT_ORGANIZATION_ID, DefaultOrganization.DEFAULT_ORGANIZATION_NAME, servers, DefaultOrganization.DEFAULT_ORGANIZATION_ADMIN, DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, null));
// Try to delete it
job = service.delete(mediaPackage.getIdentifier().toString());
barrier = new JobBarrier(null, serviceRegistry, 1000, job);
barrier.waitForJobs();
assertEquals("Job to delete mediapackage did not finish", Job.Status.FINISHED, job.getStatus());
assertEquals("Unauthorized user was able to delete a mediapackage", Boolean.FALSE.toString(), job.getPayload());
// Second try with a "fixed" roleset
User adminUser = new JaxbUser("admin", "test", defaultOrganization, new JaxbRole(defaultOrganization.getAdminRole(), defaultOrganization));
userResponder.setResponse(adminUser);
Date deletedDate = new Date();
job = service.delete(mediaPackage.getIdentifier().toString());
barrier = new JobBarrier(null, serviceRegistry, 1000, job);
barrier.waitForJobs();
assertEquals("Unauthorized user was able to delete a mediapackage", Job.Status.FINISHED, job.getStatus());
// Now go back to the original security service and user
userResponder.setResponse(defaultUser);
organizationResponder.setResponse(defaultOrganization);
SearchQuery q = new SearchQuery();
q.includeEpisodes(true);
q.includeSeries(false);
q.withId("10.0000/1");
assertEquals(0, service.getByQuery(q).size());
// Clear the ID requirement
q.withId(null);
assertEquals(0, service.getByQuery(q).size());
q = new SearchQuery();
q.withDeletedSince(deletedDate);
assertEquals(1, service.getByQuery(q).size());
}
use of org.opencastproject.search.api.SearchQuery in project opencast by opencast.
the class SearchServiceImplTest method testSearchForPartialStrings.
@Test
public void testSearchForPartialStrings() throws Exception {
MediaPackage mediaPackage = getMediaPackage("/manifest-simple.xml");
Job job = service.add(mediaPackage);
JobBarrier barrier = new JobBarrier(null, serviceRegistry, 1000, job);
barrier.waitForJobs();
assertEquals("Job to add mediapckage did not finish", Job.Status.FINISHED, job.getStatus());
assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmo")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmos")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmosp")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmosph")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmosphe")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmospher")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmospheri")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmospheric")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("atmospheri")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("tmospheric")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("tmospheri")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("Vegetatio")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("vege")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("egetatio")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("egetation")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("lecture")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("lectur")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("ecture")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("ectur")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("Science")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("Scienc")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("ience")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("cienc")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("ducti")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("Institute")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("nstitute")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("nstitut")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("Institut")).size());
assertEquals(1, service.getByQuery(new SearchQuery().withText("2008-03-05")).size());
}
use of org.opencastproject.search.api.SearchQuery in project opencast by opencast.
the class SolrRequester method getByQuery.
/**
* Returns the search results for a solr query string with read access for the current user.
*
* @param q
* the query
* @param limit
* the limit
* @param offset
* the offset
* @return the search results
* @throws SolrServerException
*/
public SearchResult getByQuery(String q, int limit, int offset) throws SolrServerException {
SearchQuery q1 = new SearchQuery();
q1.withQuery(q).withLimit(limit).withOffset(offset);
return getForRead(q1);
}
Aggregations