use of org.opencastproject.security.api.User in project opencast by opencast.
the class MessageSignatureDto method toMessageSignature.
/**
* Returns the business object of this message signature
*
* @return the business object model of this message signature
*/
public MessageSignature toMessageSignature(UserDirectoryService userDirectoryService) {
final Option<EmailAddress> reply;
if (replyTo != null && replyToName != null) {
reply = some(new EmailAddress(replyTo, replyToName));
} else {
reply = none();
}
User user = userDirectoryService.loadUser(creator);
return new MessageSignature(id, name, user, new EmailAddress(sender, senderName), reply, signature, creationDate);
}
use of org.opencastproject.security.api.User in project opencast by opencast.
the class MailServiceTest method testCRUDMessageSignature.
@Test
public void testCRUDMessageSignature() {
User admin = new JaxbUser("george@test.com", null, "George", "george@test.com", "test", new DefaultOrganization(), new HashSet<JaxbRole>());
User help = new JaxbUser("frank@test.com", null, "Frank", "frank@test.com", "test", new DefaultOrganization(), new HashSet<JaxbRole>());
MessageSignature signatureAdmin = MessageSignature.messageSignature("Administrator", admin, EmailAddress.emailAddress("admin@test.com", "Dr. Admin"), "Sincerly");
MessageSignature signatureHelp = MessageSignature.messageSignature("Helpdesk", help, EmailAddress.emailAddress("help@test.com", "Mr. Help"), "Sincerly");
List<MessageSignature> signatures;
// Create
try {
signatureAdmin = mailService.updateMessageSignature(signatureAdmin);
signatureHelp = mailService.updateMessageSignature(signatureHelp);
} catch (MailServiceException e) {
fail("Not able to save a message signature entity: " + e.getMessage());
}
// Read
try {
signatures = mailService.getMessageSignatures();
assertEquals(2, signatures.size());
assertTrue(signatures.contains(signatureAdmin) && signatures.contains(signatureHelp));
} catch (MailServiceException e) {
fail("Not able to get the message signatures: " + e.getMessage());
}
// Update
try {
signatureHelp.setCreator(admin);
signatureHelp = mailService.updateMessageSignature(signatureHelp);
signatures = mailService.getMessageSignatures();
assertEquals(2, signatures.size());
assertTrue(signatures.contains(signatureHelp));
} catch (MailServiceException e) {
fail("Not able to update a message signature entity: " + e.getMessage());
}
// Delete
try {
mailService.deleteMessageSignature(signatureAdmin.getId());
signatures = mailService.getMessageSignatures();
assertEquals(1, signatures.size());
assertTrue(signatures.contains(signatureHelp));
} catch (MailServiceException e) {
fail("Not able to delete the message signature " + signatureAdmin.getName() + ": " + e.getMessage());
} catch (NotFoundException e) {
fail("Not able to get the message signatures: " + e.getMessage());
}
}
use of org.opencastproject.security.api.User in project opencast by opencast.
the class UserSettingsTest method toJsonInputSettingAndSignatureExpectedAllInJson.
@Test
public void toJsonInputSettingAndSignatureExpectedAllInJson() throws Exception {
InputStream stream = SeriesEndpointTest.class.getResourceAsStream("/user_settings_test_example.json");
InputStreamReader reader = new InputStreamReader(stream);
JSONObject expected = (JSONObject) new JSONParser().parse(reader);
User creator = EasyMock.createMock(User.class);
EasyMock.expect(creator.getName()).andReturn("Users Name").anyTimes();
EasyMock.expect(creator.getUsername()).andReturn("username12").anyTimes();
EasyMock.expect(creator.getEmail()).andReturn("adam@fake.com").anyTimes();
EasyMock.replay(creator);
EmailAddress sender = new EmailAddress("adam@fake.com", "Other Name");
Option<EmailAddress> replyTo = none();
DateTime dateTime = new DateTime(1401465634101L);
dateTime.toDateTime(DateTimeZone.UTC);
// MessageSignature messageSignature = new MessageSignature(10L, "Adam McKenzie", creator, sender, replyTo,
// "This is the signature", dateTime.toDate(), nil(Comment.class));
Collection<MessageSignature> signatures = new LinkedList<MessageSignature>();
// signatures.add(messageSignature);
UserSetting userSetting = new UserSetting(98, "Test Key", "Test Value");
UserSettings userSettings = new UserSettings();
userSettings.setTotal(1);
userSettings.addUserSetting(userSetting);
assertThat(expected.toJSONString(), SameJSONAs.sameJSONAs(userSettings.toJson().toJson()));
}
use of org.opencastproject.security.api.User in project opencast by opencast.
the class UserSettingsServiceTest method before.
@Before
public void before() {
User user = EasyMock.createNiceMock(User.class);
EasyMock.expect(user.getUsername()).andReturn(USER_NAME);
EasyMock.replay(user);
Organization organization = EasyMock.createNiceMock(Organization.class);
EasyMock.expect(organization.getId()).andReturn(ORG).anyTimes();
EasyMock.replay(organization);
securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
EasyMock.replay(securityService);
userDirectoryService = EasyMock.createNiceMock(UserDirectoryService.class);
EasyMock.expect(userDirectoryService.loadUser(USER_NAME)).andReturn(user).anyTimes();
EasyMock.replay(userDirectoryService);
}
use of org.opencastproject.security.api.User in project opencast by opencast.
the class DownloadDistributionServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
final File mediaPackageRoot = new File(getClass().getResource("/mediapackage.xml").toURI()).getParentFile();
mp = MediaPackageParser.getFromXml(IOUtils.toString(getClass().getResourceAsStream("/mediapackage.xml"), "UTF-8"));
distributionRoot = new File(mediaPackageRoot, "static");
service = new DownloadDistributionServiceImpl();
StatusLine statusLine = EasyMock.createNiceMock(StatusLine.class);
EasyMock.expect(statusLine.getStatusCode()).andReturn(HttpServletResponse.SC_OK).anyTimes();
EasyMock.replay(statusLine);
HttpResponse response = EasyMock.createNiceMock(HttpResponse.class);
EasyMock.expect(response.getStatusLine()).andReturn(statusLine).anyTimes();
EasyMock.replay(response);
final TrustedHttpClient httpClient = EasyMock.createNiceMock(TrustedHttpClient.class);
EasyMock.expect(httpClient.execute((HttpUriRequest) EasyMock.anyObject())).andReturn(response).anyTimes();
EasyMock.expect(httpClient.run((HttpUriRequest) EasyMock.anyObject())).andAnswer(new IAnswer<Function<Function<HttpResponse, Object>, Either<Exception, Object>>>() {
@Override
public Function<Function<HttpResponse, Object>, Either<Exception, Object>> answer() throws Throwable {
HttpUriRequest req = (HttpUriRequest) EasyMock.getCurrentArguments()[0];
return StandAloneTrustedHttpClientImpl.run(httpClient, req);
}
}).anyTimes();
EasyMock.replay(httpClient);
defaultOrganization = new DefaultOrganization();
User anonymous = new JaxbUser("anonymous", "test", defaultOrganization, new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, defaultOrganization));
UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(anonymous).anyTimes();
EasyMock.replay(userDirectoryService);
service.setUserDirectoryService(userDirectoryService);
Organization organization = new DefaultOrganization();
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
EasyMock.replay(organizationDirectoryService);
service.setOrganizationDirectoryService(organizationDirectoryService);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
EasyMock.replay(securityService);
service.setSecurityService(securityService);
serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
service.setServiceRegistry(serviceRegistry);
service.setTrustedHttpClient(httpClient);
final Workspace workspace = EasyMock.createNiceMock(Workspace.class);
service.setWorkspace(workspace);
EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andAnswer(new IAnswer<File>() {
@Override
public File answer() throws Throwable {
final URI uri = (URI) EasyMock.getCurrentArguments()[0];
final String[] pathElems = uri.getPath().split("/");
final String file = pathElems[pathElems.length - 1];
return new File(mediaPackageRoot, file);
}
}).anyTimes();
EasyMock.replay(workspace);
BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
EasyMock.expect(bc.getProperty("org.opencastproject.download.directory")).andReturn(distributionRoot.toString()).anyTimes();
EasyMock.expect(bc.getProperty("org.opencastproject.download.url")).andReturn(UrlSupport.DEFAULT_BASE_URL).anyTimes();
ComponentContext cc = EasyMock.createNiceMock(ComponentContext.class);
Dictionary<String, Object> p = new Hashtable<String, Object>();
p.put(DistributionService.CONFIG_KEY_STORE_TYPE, "download");
EasyMock.expect(cc.getProperties()).andReturn(p).anyTimes();
EasyMock.expect(cc.getBundleContext()).andReturn(bc).anyTimes();
EasyMock.replay(bc, cc);
service.activate(cc);
}
Aggregations