use of org.opencastproject.search.api.SearchQuery in project opencast by opencast.
the class SearchServiceImplTest method testAddSeriesMediaPackage.
/**
* Adds a media package with a dublin core catalog for episode and series. Verifies series catalog can be retrieved
* via search service.
*/
@Test
public void testAddSeriesMediaPackage() throws Exception {
String seriesId = "foobar-series";
MediaPackage mediaPackage = getMediaPackage("/manifest-full.xml");
mediaPackage.setSeries(seriesId);
// Add the media package to the search index
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());
User adminUser = new JaxbUser("admin", "test", defaultOrganization, new JaxbRole(defaultOrganization.getAdminRole(), defaultOrganization));
userResponder.setResponse(adminUser);
// Make sure it's properly indexed and returned
SearchQuery q = new SearchQuery();
q.includeEpisodes(false);
q.includeSeries(true);
SearchResult result = service.getByQuery(q);
assertEquals(1, result.size());
assertEquals(seriesId, result.getItems()[0].getId());
}
use of org.opencastproject.search.api.SearchQuery in project opencast by opencast.
the class SearchServiceImplTest method testAddFullMediaPackage.
/**
* Ads a simple media package that has a dublin core for the episode only.
*/
@Test
public void testAddFullMediaPackage() throws Exception {
MediaPackage mediaPackage = getMediaPackage("/manifest-full.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();
assertEquals("Job to add mediapckage did not finish", Job.Status.FINISHED, job.getStatus());
// Make sure it's properly indexed and returned
SearchQuery q = new SearchQuery();
q.includeEpisodes(true);
q.includeSeries(false);
q.withId("10.0000/2");
assertEquals(1, service.getByQuery(q).size());
// Clear the ID requirement
q.withId(null);
assertEquals(1, service.getByQuery(q).size());
}
use of org.opencastproject.search.api.SearchQuery in project opencast by opencast.
the class SearchServiceImplTest method testDeleteIndexNotInDbMediaPackage.
/**
* Test removal from the search index even when it is missing from database #MH-11616
*/
@Test
public void testDeleteIndexNotInDbMediaPackage() 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();
// Delete the mediapackage from persistence (leave it in index)
Date dateDeletedFromDb = new Date();
searchDatabase.deleteMediaPackage(mediaPackage.getIdentifier().toString(), dateDeletedFromDb);
// Verify it is not marked as deleted
SearchQuery qDel = new SearchQuery();
qDel.withDeletedSince(dateDeletedFromDb);
assertEquals(0, service.getByQuery(qDel).size());
// Verify that it is still active in index
SearchQuery q = new SearchQuery();
q.includeEpisodes(true);
q.includeSeries(false);
q.withId(mediaPackage.getIdentifier().toString());
assertEquals(1, service.getByQuery(q).size());
// Try 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());
// Verify that it is now not active in the index
assertEquals(0, service.getByQuery(q).size());
// Verify that it is now marked as deleted in the index
q = new SearchQuery();
q.withDeletedSince(dateDeletedFromDb);
assertEquals(1, service.getByQuery(q).size());
}
use of org.opencastproject.search.api.SearchQuery in project opencast by opencast.
the class SearchServiceImplTest method testEmptySearchIndex.
/**
* Test whether an empty search index will work.
*/
@Test
public void testEmptySearchIndex() {
SearchResult result = service.getByQuery(new SearchQuery().withId("foo"));
assertEquals(0, result.size());
}
use of org.opencastproject.search.api.SearchQuery in project opencast by opencast.
the class SearchServiceImplTest method testAddSimpleMediaPackage.
/**
* Adds a simple media package that has a dublin core for the episode only.
*/
@Test
public void testAddSimpleMediaPackage() 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();
assertEquals("Job to add mediapckage did not finish", Job.Status.FINISHED, job.getStatus());
// Make sure it's properly indexed and returned
SearchQuery q = new SearchQuery();
q.includeEpisodes(true);
q.includeSeries(false);
q.withId("10.0000/1");
assertEquals(1, service.getByQuery(q).size());
q = new SearchQuery();
q.includeEpisodes(true);
q.includeSeries(false);
assertEquals(1, service.getByQuery(q).size());
// Test for various fields
q = new SearchQuery();
q.includeEpisodes(true);
q.includeSeries(false);
q.withId("10.0000/1");
SearchResult result = service.getByQuery(q);
assertEquals(1, result.getTotalSize());
SearchResultItem resultItem = result.getItems()[0];
assertNotNull(resultItem.getMediaPackage());
assertEquals(1, resultItem.getMediaPackage().getCatalogs().length);
}
Aggregations