use of org.opencastproject.security.api.SecurityService in project opencast by opencast.
the class PublishEngageWorkflowOperationHandlerTest method testDefaultPlayerPath.
@Test
public void testDefaultPlayerPath() throws URISyntaxException {
URI engageURI = new URI("http://engage.org");
String mpId = "mp-id";
MediaPackage mp = EasyMock.createNiceMock(MediaPackage.class);
Id id = new IdImpl(mpId);
EasyMock.expect(mp.getIdentifier()).andStubReturn(id);
MediaPackageElement element = EasyMock.createNiceMock(MediaPackageElement.class);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getOrganization()).andReturn(getOrgWithoutPlayerPath()).once();
EasyMock.replay(element, mp, securityService);
// Test default player path
PublishEngageWorkflowOperationHandler publishEngagePublish = new PublishEngageWorkflowOperationHandler();
publishEngagePublish.setSecurityService(securityService);
URI result = publishEngagePublish.createEngageUri(engageURI, mp);
assertEquals(engageURI.toString() + PublishEngageWorkflowOperationHandler.DEFAULT_PLAYER_PATH + "?id=" + mpId, result.toString());
}
use of org.opencastproject.security.api.SecurityService in project opencast by opencast.
the class PublishEngageWorkflowOperationHandlerTest method testPlayerUrl.
@Test
public void testPlayerUrl() throws WorkflowOperationException, URISyntaxException {
URI engageURI = new URI("http://engage.org");
String mpId = "mp-id";
MediaPackage mp = EasyMock.createNiceMock(MediaPackage.class);
Id id = new IdImpl(mpId);
EasyMock.expect(mp.getIdentifier()).andStubReturn(id);
MediaPackageElement element = EasyMock.createNiceMock(MediaPackageElement.class);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getOrganization()).andReturn(getOrgWithPlayerPath()).once();
EasyMock.replay(element, mp, securityService);
// Test configured organization player path
PublishEngageWorkflowOperationHandler publishEngagePublish = new PublishEngageWorkflowOperationHandler();
publishEngagePublish.setSecurityService(securityService);
URI result = publishEngagePublish.createEngageUri(engageURI, mp);
assertEquals(engageURI.toString() + examplePlayer + "?id=" + mpId, result.toString());
}
use of org.opencastproject.security.api.SecurityService in project opencast by opencast.
the class ConfigurablePublishWorkflowOperationHandlerTest method testTemplateReplacement.
@Test
public void testTemplateReplacement() throws WorkflowOperationException, URISyntaxException {
URI elementUri = new URI("http://element.com/path/to/element/element.mp4");
String mpId = "mp-id";
String pubUUID = "test-uuid";
String seriesId = "series-id";
MediaPackage mp = EasyMock.createNiceMock(MediaPackage.class);
Id id = new IdImpl(mpId);
EasyMock.expect(mp.getIdentifier()).andStubReturn(id);
MediaPackageElement element = EasyMock.createNiceMock(MediaPackageElement.class);
EasyMock.expect(element.getURI()).andStubReturn(elementUri);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getOrganization()).andStubReturn(org);
EasyMock.replay(element, mp, securityService);
// Test player path and mediapackage id
ConfigurablePublishWorkflowOperationHandler configurePublish = new ConfigurablePublishWorkflowOperationHandler();
configurePublish.setSecurityService(securityService);
URI result = configurePublish.populateUrlWithVariables("${player_path}${event_id}", mp, pubUUID);
assertEquals(examplePlayer + "mp-id", result.toString());
// Test without series
configurePublish = new ConfigurablePublishWorkflowOperationHandler();
configurePublish.setSecurityService(securityService);
result = configurePublish.populateUrlWithVariables("${series_id}/${event_id}", mp, pubUUID);
assertEquals("/mp-id", result.toString());
// Test with series
mp = EasyMock.createNiceMock(MediaPackage.class);
EasyMock.expect(mp.getIdentifier()).andStubReturn(id);
EasyMock.expect(mp.getSeries()).andStubReturn(seriesId);
EasyMock.replay(mp);
configurePublish = new ConfigurablePublishWorkflowOperationHandler();
configurePublish.setSecurityService(securityService);
result = configurePublish.populateUrlWithVariables("${series_id}/${event_id}", mp, pubUUID);
assertEquals("series-id/mp-id", result.toString());
// Test publication uuid
configurePublish = new ConfigurablePublishWorkflowOperationHandler();
configurePublish.setSecurityService(securityService);
result = configurePublish.populateUrlWithVariables("${publication_id}", mp, pubUUID);
assertEquals(pubUUID, result.toString());
}
use of org.opencastproject.security.api.SecurityService in project opencast by opencast.
the class CommentWorkflowOperationHandlerTest method testDuplicateComments.
@Test
public void testDuplicateComments() throws WorkflowOperationException, EventCommentException {
// Testing that a duplicate comment won't be created but a different one will still be created.
Long workflowId = 10L;
String mediaPackageId = "abc-def";
String action = "create";
String reason = "Waiting for Trim";
String description = "The comment description";
Organization org = createNiceMock(Organization.class);
expect(org.getId()).andStubReturn("demo");
replay(org);
SecurityService secSrv = createNiceMock(SecurityService.class);
expect(secSrv.getOrganization()).andStubReturn(org);
replay(secSrv);
// Setup WorkflowOperation Instance
WorkflowOperationInstance workflowOperationInstance = EasyMock.createMock(WorkflowOperationInstance.class);
EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn(action).anyTimes();
EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.REASON)).andReturn(reason).anyTimes();
EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.DESCRIPTION)).andReturn(description).anyTimes();
// Setup mediaPackage
MediaPackage mediaPackage = EasyMock.createMock(MediaPackage.class);
EasyMock.expect(mediaPackage.getIdentifier()).andReturn(new IdImpl(mediaPackageId)).anyTimes();
// Setup user
User creator = EasyMock.createMock(User.class);
// Setup WorkflowInstance
WorkflowInstance workflowInstance = EasyMock.createMock(WorkflowInstance.class);
EasyMock.expect(workflowInstance.getId()).andReturn(workflowId).anyTimes();
EasyMock.expect(workflowInstance.getCurrentOperation()).andReturn(workflowOperationInstance).anyTimes();
EasyMock.expect(workflowInstance.getMediaPackage()).andReturn(mediaPackage).anyTimes();
EasyMock.expect(workflowInstance.getCreator()).andReturn(creator).anyTimes();
// Test no previous comments
EventCommentService eventCommentService = EasyMock.createMock(EventCommentService.class);
EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(new ArrayList<EventComment>());
Capture<EventComment> comment = EasyMock.newCapture();
EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(15L), mediaPackageId, org.getId(), description, creator));
EasyMock.replay(creator, eventCommentService, mediaPackage, workflowInstance, workflowOperationInstance);
CommentWorkflowOperationHandler commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
commentWorkflowOperationHandler.setSecurityService(secSrv);
commentWorkflowOperationHandler.start(workflowInstance, null);
assertTrue(comment.hasCaptured());
assertEquals(creator, comment.getValue().getAuthor());
assertEquals(description, comment.getValue().getText());
assertEquals(reason, comment.getValue().getReason());
// Test previous comment with same reason and description
List<EventComment> comments = new ArrayList<EventComment>();
comments.add(EventComment.create(Option.option(13L), mediaPackageId, org.getId(), description, creator, reason, true));
eventCommentService = EasyMock.createMock(EventCommentService.class);
EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(comments);
EasyMock.replay(eventCommentService);
commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
commentWorkflowOperationHandler.start(workflowInstance, null);
assertTrue(comment.hasCaptured());
assertEquals(creator, comment.getValue().getAuthor());
assertEquals(description, comment.getValue().getText());
assertEquals(reason, comment.getValue().getReason());
// Test previous comment with different reasons and descriptions
comments = new ArrayList<EventComment>();
comments.add(EventComment.create(Option.option(15L), mediaPackageId, org.getId(), "Different description", creator, reason, true));
comments.add(EventComment.create(Option.option(15L), mediaPackageId, org.getId(), description, creator, "Different reason", true));
eventCommentService = EasyMock.createMock(EventCommentService.class);
EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(comments);
comment = EasyMock.newCapture();
EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(15L), mediaPackageId, org.getId(), description, creator));
EasyMock.replay(eventCommentService);
commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
commentWorkflowOperationHandler.setSecurityService(secSrv);
commentWorkflowOperationHandler.start(workflowInstance, null);
assertTrue(comment.hasCaptured());
assertEquals(creator, comment.getValue().getAuthor());
assertEquals(description, comment.getValue().getText());
assertEquals(reason, comment.getValue().getReason());
}
use of org.opencastproject.security.api.SecurityService in project opencast by opencast.
the class CaptureAgentStateServiceImplTest method setupService.
private void setupService() throws Exception {
service = new CaptureAgentStateServiceImpl();
service.setEntityManagerFactory(newTestEntityManagerFactory(CaptureAgentStateServiceImpl.PERSISTENCE_UNIT));
DefaultOrganization organization = new DefaultOrganization();
HashSet<JaxbRole> roles = new HashSet<>();
roles.add(new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ADMIN, organization, ""));
User user = new JaxbUser("testuser", "test", organization, roles);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
EasyMock.replay(securityService);
service.setSecurityService(securityService);
setupCC();
service.activate(cc);
service.setupAgentCache(1, TimeUnit.HOURS);
}
Aggregations