Search in sources :

Example 1 with Event

use of org.opencastproject.index.service.impl.index.event.Event 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 Event

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

the class EventTest method testHasRecordingStarted.

@Test
public void testHasRecordingStarted() {
    Event event = new Event(id, defaultOrganization);
    assertTrue(event.hasRecordingStarted());
    Date now = new Date();
    event.setSchedulingStatus(SchedulingStatus.READY_FOR_RECORDING.toString());
    event.setTechnicalStartTime(DateTimeSupport.toUTC(now.getTime() - (3 * 60 * 1000)));
    assertTrue(event.hasRecordingStarted());
    event.setSchedulingStatus(SchedulingStatus.OPTED_OUT.toString());
    event.setTechnicalStartTime(DateTimeSupport.toUTC(now.getTime() + (3 * 60 * 1000)));
    assertFalse(event.hasRecordingStarted());
}
Also used : Event(org.opencastproject.index.service.impl.index.event.Event) Date(java.util.Date) Test(org.junit.Test)

Example 3 with Event

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

the class EventTest method testValueOfJson.

@Ignore
@Test
public void testValueOfJson() throws ParseException, IOException, JSONException, XMLStreamException, JAXBException {
    Event event = Event.valueOfJson(IOUtils.toInputStream(eventJson));
    assertEquals(id, event.getIdentifier());
    assertEquals(title, event.getTitle());
    assertEquals(presenter1, event.getPresenters().get(0));
    assertEquals(presenter2, event.getPresenters().get(1));
    assertEquals(presenter3, event.getPresenters().get(2));
    assertEquals(contributor1, event.getContributors().get(0));
    assertEquals(contributor2, event.getContributors().get(1));
    assertEquals(contributor3, event.getContributors().get(2));
}
Also used : Event(org.opencastproject.index.service.impl.index.event.Event) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with Event

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

the class EventTest method testToJson.

@Test
public void testToJson() throws ParseException, IOException {
    Event event = new Event(id, defaultOrganization);
    event.setTitle(title);
    event.setDescription(description);
    event.setSubject(subject);
    event.setLocation(location);
    event.setPresenters(presenters);
    event.setContributors(contributors);
    event.setAgentConfiguration(agentConfiguration);
    logger.info(event.toJSON());
    JSONObject parse = (JSONObject) new JSONParser().parse(event.toJSON());
    if (parse.get(EVENT_JSON_KEY) == null || !(parse.get(EVENT_JSON_KEY) instanceof JSONObject)) {
        fail("There must be an event object returned.");
    }
    JSONObject eventJsonObject = (JSONObject) parse.get(EVENT_JSON_KEY);
    assertEquals(id, eventJsonObject.get(IDENTIFIER_JSON_KEY));
    assertEquals(defaultOrganization, eventJsonObject.get(ORGANIZATION_JSON_KEY));
    assertEquals(title, eventJsonObject.get(TITLE_JSON_KEY));
    assertEquals(description, eventJsonObject.get(DESCRIPTION_JSON_KEY));
    assertEquals(subject, eventJsonObject.get(SUBJECT_JSON_KEY));
    assertEquals(location, eventJsonObject.get(LOCATION_JSON_KEY));
    JSONArray presentersArray = (JSONArray) ((JSONObject) eventJsonObject.get(PRESENTERS_JSON_KEY)).get(PRESENTER_JSON_KEY);
    // Ordering not important, just a convenient shorthand.
    assertEquals(presenter1, presentersArray.get(0));
    assertEquals(presenter2, presentersArray.get(1));
    assertEquals(presenter3, presentersArray.get(2));
    JSONArray contributorsArray = (JSONArray) ((JSONObject) eventJsonObject.get(CONTRIBUTORS_JSON_KEY)).get(CONTRIBUTOR_JSON_KEY);
    // Ordering not important, just a convenient shorthand.
    assertEquals(contributor1, contributorsArray.get(0));
    assertEquals(contributor2, contributorsArray.get(1));
    assertEquals(contributor3, contributorsArray.get(2));
    JSONObject agentConfigurationObject = (JSONObject) eventJsonObject.get(AGENT_CONFIGURATION_KEY);
    JSONArray entryArray = (JSONArray) agentConfigurationObject.get(ENTRY_KEY);
    // Ordering not important
    assertThat(eventCAConfigJson, SameJSONAs.sameJSONAs(entryArray.toJSONString()).allowingAnyArrayOrdering());
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) Event(org.opencastproject.index.service.impl.index.event.Event) JSONParser(org.json.simple.parser.JSONParser) Test(org.junit.Test)

Example 5 with Event

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

the class AssetManagerMessageReceiverImplTest method testUpdateCreator.

@Test
public void testUpdateCreator() throws Exception {
    MediaPackage mediaPackage = new MediaPackageBuilderImpl().loadFromXml(getClass().getResourceAsStream("/jobs_mediapackage1.xml"));
    TakeSnapshot takeSnapshot = AssetManagerItem.add(workspace, mediaPackage, new AccessControlList(), 0, new Date());
    // Test initial set of creator
    assetManager.execute(takeSnapshot);
    Event event = index.getEventResult();
    assertNotNull(event);
    assertEquals("Current user is expected to be creator as no other creator has been set explicitly", "Creator", event.getCreator());
    // Test updating creator
    event.setCreator("Hans");
    index.setInitialEvent(event);
    assetManager.execute(takeSnapshot);
    event = index.getEventResult();
    assertNotNull(event);
    assertEquals("Creator has been updated", "Hans", event.getCreator());
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) TakeSnapshot(org.opencastproject.message.broker.api.assetmanager.AssetManagerItem.TakeSnapshot) MediaPackageBuilderImpl(org.opencastproject.mediapackage.MediaPackageBuilderImpl) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Event(org.opencastproject.index.service.impl.index.event.Event) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Event (org.opencastproject.index.service.impl.index.event.Event)67 Path (javax.ws.rs.Path)35 RestQuery (org.opencastproject.util.doc.rest.RestQuery)34 NotFoundException (org.opencastproject.util.NotFoundException)26 WebApplicationException (javax.ws.rs.WebApplicationException)24 SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)22 Produces (javax.ws.rs.Produces)21 IndexServiceException (org.opencastproject.index.service.exception.IndexServiceException)19 MediaPackage (org.opencastproject.mediapackage.MediaPackage)19 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)19 ParseException (java.text.ParseException)17 JSONException (org.codehaus.jettison.json.JSONException)17 UrlSigningException (org.opencastproject.security.urlsigning.exception.UrlSigningException)17 GET (javax.ws.rs.GET)16 AclServiceException (org.opencastproject.authorization.xacml.manager.api.AclServiceException)16 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)16 EventCommentException (org.opencastproject.event.comment.EventCommentException)15 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)15 JobEndpointException (org.opencastproject.adminui.exception.JobEndpointException)14 WorkflowStateException (org.opencastproject.workflow.api.WorkflowStateException)14