Search in sources :

Example 1 with AbstractSearchIndex

use of org.opencastproject.index.service.impl.index.AbstractSearchIndex in project opencast by opencast.

the class IndexServiceImplTest method testUpdateEventInputNoEventExpectsNotFound.

/**
 * Test Put Event
 */
@Test(expected = NotFoundException.class)
public void testUpdateEventInputNoEventExpectsNotFound() throws IOException, IllegalArgumentException, IndexServiceException, NotFoundException, UnauthorizedException, SearchIndexException, WorkflowDatabaseException {
    String username = "username";
    String org = "org1";
    String testResourceLocation = "/events/update-event.json";
    String eventId = "event-1";
    String metadataJson = IOUtils.toString(IndexServiceImplTest.class.getResourceAsStream(testResourceLocation));
    SearchQuery query = EasyMock.createMock(SearchQuery.class);
    EasyMock.expect(query.getLimit()).andReturn(100);
    EasyMock.expect(query.getOffset()).andReturn(0);
    EasyMock.replay(query);
    SearchResult<Event> result = new SearchResultImpl<>(query, 0, 0);
    AbstractSearchIndex abstractIndex = EasyMock.createMock(AbstractSearchIndex.class);
    EasyMock.expect(abstractIndex.getByQuery(EasyMock.anyObject(EventSearchQuery.class))).andReturn(result);
    EasyMock.replay(abstractIndex);
    SecurityService securityService = setupSecurityService(username, org);
    IndexServiceImpl indexService = new IndexServiceImpl();
    indexService.setSecurityService(securityService);
    indexService.updateAllEventMetadata(eventId, metadataJson, abstractIndex);
}
Also used : EventSearchQuery(org.opencastproject.index.service.impl.index.event.EventSearchQuery) SearchQuery(org.opencastproject.matterhorn.search.SearchQuery) AbstractSearchIndex(org.opencastproject.index.service.impl.index.AbstractSearchIndex) SearchResultImpl(org.opencastproject.matterhorn.search.impl.SearchResultImpl) EventSearchQuery(org.opencastproject.index.service.impl.index.event.EventSearchQuery) SecurityService(org.opencastproject.security.api.SecurityService) Event(org.opencastproject.index.service.impl.index.event.Event) Test(org.junit.Test)

Example 2 with AbstractSearchIndex

use of org.opencastproject.index.service.impl.index.AbstractSearchIndex in project opencast by opencast.

the class EventIndexUtilsTest method testUpdateSeriesNameInputSeriesEventuallyAddedToIndexExpectsSetsName.

@Test
@SuppressWarnings("unchecked")
public void testUpdateSeriesNameInputSeriesEventuallyAddedToIndexExpectsSetsName() throws SearchIndexException {
    // Input data
    String seriesId = "my_series";
    String eventId = "my_event";
    // Mocks
    Series series = EasyMock.createMock(Series.class);
    EasyMock.expect(series.getTitle()).andReturn(seriesId);
    SearchResultItem<Series> seriesResult = EasyMock.createMock(SearchResultItem.class);
    EasyMock.expect(seriesResult.getSource()).andReturn(series);
    ArrayList<SearchResultItem<Series>> seriesCollection = new ArrayList<SearchResultItem<Series>>();
    seriesCollection.add(seriesResult);
    SearchResult<Series> eventuallyResult = EasyMock.createMock(SearchResult.class);
    EasyMock.expect(eventuallyResult.getHitCount()).andReturn(0L);
    EasyMock.expect(eventuallyResult.getHitCount()).andReturn(0L);
    EasyMock.expect(eventuallyResult.getHitCount()).andReturn(1L);
    EasyMock.expect(eventuallyResult.getItems()).andReturn(seriesCollection.toArray(new SearchResultItem[1]));
    Event event = EasyMock.createMock(Event.class);
    EasyMock.expect(event.getSeriesId()).andReturn(seriesId).anyTimes();
    EasyMock.expect(event.getSeriesName()).andReturn(null).anyTimes();
    EasyMock.expect(event.getIdentifier()).andReturn(eventId).anyTimes();
    event.setSeriesName(seriesId);
    EasyMock.expectLastCall();
    AbstractSearchIndex searchIndex = EasyMock.createMock(AbstractSearchIndex.class);
    EasyMock.expect(searchIndex.getByQuery(EasyMock.anyObject(SeriesSearchQuery.class))).andReturn(eventuallyResult);
    EasyMock.expect(searchIndex.getByQuery(EasyMock.anyObject(SeriesSearchQuery.class))).andReturn(eventuallyResult);
    EasyMock.expect(searchIndex.getByQuery(EasyMock.anyObject(SeriesSearchQuery.class))).andReturn(eventuallyResult);
    EasyMock.replay(eventuallyResult, event, searchIndex, series, seriesResult);
    // Run test
    EventIndexUtils.updateSeriesName(event, defaultOrganization.getId(), user, searchIndex, 3, 50L);
}
Also used : AbstractSearchIndex(org.opencastproject.index.service.impl.index.AbstractSearchIndex) Series(org.opencastproject.index.service.impl.index.series.Series) SeriesSearchQuery(org.opencastproject.index.service.impl.index.series.SeriesSearchQuery) SearchResultItem(org.opencastproject.matterhorn.search.SearchResultItem) ArrayList(java.util.ArrayList) Event(org.opencastproject.index.service.impl.index.event.Event) Test(org.junit.Test)

Example 3 with AbstractSearchIndex

use of org.opencastproject.index.service.impl.index.AbstractSearchIndex in project opencast by opencast.

the class EventIndexUtilsTest method testUpdateSeriesNameInputSeriesNotAddedToIndexExpectsGivesUp.

@Test
public void testUpdateSeriesNameInputSeriesNotAddedToIndexExpectsGivesUp() throws SearchIndexException {
    // Input data
    String seriesId = "my_series";
    String eventId = "my_event";
    // Mocks
    @SuppressWarnings("unchecked") SearchResult<Series> emptyResult = EasyMock.createMock(SearchResult.class);
    EasyMock.expect(emptyResult.getHitCount()).andReturn(0L).anyTimes();
    Event event = EasyMock.createMock(Event.class);
    EasyMock.expect(event.getSeriesId()).andReturn(seriesId).anyTimes();
    EasyMock.expect(event.getSeriesName()).andReturn(null).anyTimes();
    EasyMock.expect(event.getIdentifier()).andReturn(eventId).anyTimes();
    AbstractSearchIndex searchIndex = EasyMock.createMock(AbstractSearchIndex.class);
    EasyMock.expect(searchIndex.getByQuery(EasyMock.anyObject(SeriesSearchQuery.class))).andReturn(emptyResult);
    EasyMock.expect(searchIndex.getByQuery(EasyMock.anyObject(SeriesSearchQuery.class))).andReturn(emptyResult);
    EasyMock.expect(searchIndex.getByQuery(EasyMock.anyObject(SeriesSearchQuery.class))).andReturn(emptyResult);
    EasyMock.replay(emptyResult, event, searchIndex);
    // Run test
    EventIndexUtils.updateSeriesName(event, defaultOrganization.getId(), user, searchIndex, 3, 50L);
}
Also used : AbstractSearchIndex(org.opencastproject.index.service.impl.index.AbstractSearchIndex) Series(org.opencastproject.index.service.impl.index.series.Series) SeriesSearchQuery(org.opencastproject.index.service.impl.index.series.SeriesSearchQuery) Event(org.opencastproject.index.service.impl.index.event.Event) Test(org.junit.Test)

Example 4 with AbstractSearchIndex

use of org.opencastproject.index.service.impl.index.AbstractSearchIndex in project opencast by opencast.

the class IndexServiceImplTest method testUpdateMediaPackageMetadata.

@Test
public void testUpdateMediaPackageMetadata() throws Exception {
    // mock/initialize dependencies
    String username = "user1";
    String org = "mh_default_org";
    String testResourceLocation = "/events/update-event.json";
    String metadataJson = IOUtils.toString(getClass().getResourceAsStream(testResourceLocation));
    MetadataCollection metadataCollection = new DublinCoreMetadataCollection();
    metadataCollection.addField(MetadataField.createTextMetadataField("title", Opt.some("title"), "EVENTS.EVENTS.DETAILS.METADATA.TITLE", false, true, Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none()));
    metadataCollection.addField(MetadataField.createTextLongMetadataField("creator", Opt.some("creator"), "EVENTS.EVENTS.DETAILS.METADATA.PRESENTERS", false, false, Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none()));
    metadataCollection.addField(MetadataField.createTextMetadataField("isPartOf", Opt.some("isPartOf"), "EVENTS.EVENTS.DETAILS.METADATA.SERIES", false, false, Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none()));
    MetadataList metadataList = new MetadataList(metadataCollection, metadataJson);
    String eventId = "event-1";
    Event event = new Event(eventId, org);
    event.setTitle("Test Event 1");
    SearchQuery query = EasyMock.createMock(SearchQuery.class);
    EasyMock.expect(query.getLimit()).andReturn(100);
    EasyMock.expect(query.getOffset()).andReturn(0);
    EasyMock.replay(query);
    SearchResultItemImpl<Event> searchResultItem = new SearchResultItemImpl<>(1.0, event);
    SearchResultImpl<Event> searchResult = new SearchResultImpl<>(query, 0, 0);
    searchResult.addResultItem(searchResultItem);
    SecurityService securityService = setupSecurityService(username, org);
    AbstractSearchIndex index = EasyMock.createMock(AbstractSearchIndex.class);
    MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(getClass().getResourceAsStream("/events/update-event-mp.xml"));
    EasyMock.expect(index.getByQuery(EasyMock.anyObject(EventSearchQuery.class))).andReturn(searchResult);
    EasyMock.replay(index);
    Workspace workspace = EasyMock.createMock(Workspace.class);
    EasyMock.expect(workspace.put(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyObject())).andReturn(getClass().getResource("/dublincore.xml").toURI()).anyTimes();
    EasyMock.expect(workspace.read(EasyMock.anyObject())).andAnswer(() -> getClass().getResourceAsStream("/dublincore.xml")).anyTimes();
    EasyMock.replay(workspace);
    CommonEventCatalogUIAdapter commonEventCatalogUIAdapter = setupCommonCatalogUIAdapter(workspace).getA();
    // Using scheduler as the source of the media package here.
    SchedulerService schedulerService = EasyMock.createMock(SchedulerService.class);
    EasyMock.expect(schedulerService.getMediaPackage(EasyMock.anyString())).andReturn(mp);
    Capture<Opt<MediaPackage>> mpCapture = new Capture<>();
    schedulerService.updateEvent(EasyMock.anyString(), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.capture(mpCapture), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyString());
    EasyMock.expectLastCall();
    EasyMock.replay(schedulerService);
    SeriesService seriesService = EasyMock.createMock(SeriesService.class);
    DublinCoreCatalog seriesDC = DublinCores.read(getClass().getResourceAsStream("/events/update-event-series.xml"));
    EasyMock.expect(seriesService.getSeries(EasyMock.anyString())).andReturn(seriesDC);
    EasyMock.expect(seriesService.getSeriesAccessControl(EasyMock.anyString())).andReturn(null);
    EasyMock.expect(seriesService.getSeriesElements(EasyMock.anyString())).andReturn(Opt.none());
    EasyMock.replay(seriesService);
    // create service
    IndexServiceImpl indexService = new IndexServiceImpl();
    indexService.setSecurityService(securityService);
    indexService.setSchedulerService(schedulerService);
    indexService.setCommonEventCatalogUIAdapter(commonEventCatalogUIAdapter);
    indexService.addCatalogUIAdapter(commonEventCatalogUIAdapter);
    indexService.setSeriesService(seriesService);
    indexService.setWorkspace(workspace);
    MetadataList updateEventMetadata = indexService.updateEventMetadata(org, metadataList, index);
    Assert.assertTrue(mpCapture.hasCaptured());
    Assert.assertEquals("series-1", mp.getSeries());
    Assert.assertEquals(1, mp.getCatalogs(MediaPackageElements.SERIES).length);
}
Also used : DublinCoreMetadataCollection(org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataCollection) EventSearchQuery(org.opencastproject.index.service.impl.index.event.EventSearchQuery) SearchQuery(org.opencastproject.matterhorn.search.SearchQuery) SearchResultItemImpl(org.opencastproject.matterhorn.search.impl.SearchResultItemImpl) SchedulerService(org.opencastproject.scheduler.api.SchedulerService) EventSearchQuery(org.opencastproject.index.service.impl.index.event.EventSearchQuery) Capture(org.easymock.Capture) MetadataList(org.opencastproject.index.service.catalog.adapter.MetadataList) AbstractSearchIndex(org.opencastproject.index.service.impl.index.AbstractSearchIndex) Opt(com.entwinemedia.fn.data.Opt) SearchResultImpl(org.opencastproject.matterhorn.search.impl.SearchResultImpl) SeriesService(org.opencastproject.series.api.SeriesService) SecurityService(org.opencastproject.security.api.SecurityService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Event(org.opencastproject.index.service.impl.index.event.Event) CommonEventCatalogUIAdapter(org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter) DublinCoreMetadataCollection(org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataCollection) MetadataCollection(org.opencastproject.metadata.dublincore.MetadataCollection) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Workspace(org.opencastproject.workspace.api.Workspace) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 AbstractSearchIndex (org.opencastproject.index.service.impl.index.AbstractSearchIndex)4 Event (org.opencastproject.index.service.impl.index.event.Event)4 EventSearchQuery (org.opencastproject.index.service.impl.index.event.EventSearchQuery)2 Series (org.opencastproject.index.service.impl.index.series.Series)2 SeriesSearchQuery (org.opencastproject.index.service.impl.index.series.SeriesSearchQuery)2 SearchQuery (org.opencastproject.matterhorn.search.SearchQuery)2 SearchResultImpl (org.opencastproject.matterhorn.search.impl.SearchResultImpl)2 SecurityService (org.opencastproject.security.api.SecurityService)2 Opt (com.entwinemedia.fn.data.Opt)1 ArrayList (java.util.ArrayList)1 Capture (org.easymock.Capture)1 DublinCoreMetadataCollection (org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataCollection)1 MetadataList (org.opencastproject.index.service.catalog.adapter.MetadataList)1 CommonEventCatalogUIAdapter (org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter)1 SearchResultItem (org.opencastproject.matterhorn.search.SearchResultItem)1 SearchResultItemImpl (org.opencastproject.matterhorn.search.impl.SearchResultItemImpl)1 MediaPackage (org.opencastproject.mediapackage.MediaPackage)1 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)1 MetadataCollection (org.opencastproject.metadata.dublincore.MetadataCollection)1