use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class JaxbUtil method jaxbToNamedElement.
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Element jaxbToNamedElement(String name, String namespace, Object o, Element.ElementFactory factory) throws ServiceException {
if (Element.JSONElement.mFactory.equals(factory)) {
return JacksonUtil.jaxbToJSONElement(o, org.dom4j.QName.get(name, namespace));
}
try {
Marshaller marshaller = createMarshaller(o.getClass());
// marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
DocumentResult dr = new DocumentResult();
marshaller.marshal(new JAXBElement(new QName(namespace, name), o.getClass(), o), dr);
Document theDoc = dr.getDocument();
org.dom4j.Element rootElem = theDoc.getRootElement();
return Element.convertDOM(rootElem, factory);
} catch (Exception e) {
throw ServiceException.FAILURE("Unable to convert " + o.getClass().getName() + " to Element", e);
}
}
use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class ExtShareInfoTest method testGenNotifyBody.
@Test
public void testGenNotifyBody() {
Locale locale = new Locale("en", "US");
String notes = "none";
ShareInfoData sid = new ShareInfoData();
sid.setGranteeDisplayName("Demo User Three");
sid.setGranteeId(testAcct.getId());
sid.setGranteeName(testAcct.getName());
sid.setGranteeType(ACL.GRANTEE_GUEST);
sid.setPath("/Inbox/Test");
sid.setFolderDefaultView(MailItem.Type.MESSAGE);
sid.setItemUuid("9badf685-3420-458b-9ce5-826b0bec638f");
sid.setItemId(257);
sid.setOwnerAcctId(ownerAcct.getId());
sid.setOwnerAcctEmail(ownerAcct.getName());
sid.setOwnerAcctDisplayName("Demo User Two");
try {
sid.setRights(ACL.stringToRights("rwidxap"));
MimeMultipart mmp = ShareInfo.NotificationSender.genNotifBody(sid, notes, locale, null, null);
Assert.assertNotNull(mmp);
String body = (String) mmp.getBodyPart(0).getDataHandler().getContent();
int index = body.indexOf("http");
int endIndex = body.indexOf(".", index);
String authUrl = body.substring(index, endIndex);
index = authUrl.indexOf("p=");
String authToken = authUrl.substring(index + 2);
try {
ZimbraAuthToken.getAuthToken(authToken);
fail("Authtoken should fail");
} catch (AuthTokenException e) {
assertTrue(e.getMessage().contains("hmac failure"));
}
// Commenting for now, need to figure out why it fails on hudson
// try {
// ExternalUserProvServlet.validatePrelimToken(authToken);
// } catch (Exception e) {
// fail("Should not throw Exception" + e.getMessage());
// }
} catch (ServiceException | MessagingException | IOException e) {
fail("Exception should not be thrown: " + e.getMessage());
}
}
use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class ShareInfoTest method testGenNotifyBody.
@Test
public void testGenNotifyBody() {
Locale locale = new Locale("en", "US");
String notes = "none";
ShareInfoData sid = new ShareInfoData();
sid.setGranteeDisplayName("Demo User Three");
sid.setGranteeId("46031e4c-deb4-4724-b5bb-8f854d0c518a");
sid.setGranteeName("Demo User Three");
sid.setGranteeType(ACL.GRANTEE_USER);
sid.setPath("/Calendar/Cal1");
sid.setFolderDefaultView(MailItem.Type.APPOINTMENT);
sid.setItemUuid("9badf685-3420-458b-9ce5-826b0bec638f");
sid.setItemId(257);
sid.setOwnerAcctId("bbf152ca-e7cd-477e-9f72-70fef715c5f9");
sid.setOwnerAcctEmail("test@zimbra.com");
sid.setOwnerAcctDisplayName("Demo User Two");
try {
sid.setRights(ACL.stringToRights("rwidxap"));
MimeMultipart mmp = ShareInfo.NotificationSender.genNotifBody(sid, notes, locale, null, null);
Assert.assertNotNull(mmp);
String body = (String) mmp.getBodyPart(0).getDataHandler().getContent();
assertTrue(body.indexOf("Role: Admin") != -1);
} catch (ServiceException | MessagingException | IOException e) {
fail("Exception should not be thrown: " + e.getMessage());
}
}
use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class ZimbraQueryTest method checkSortCompatibility.
@Test
public void checkSortCompatibility() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
SearchParams params = new SearchParams();
params.setQueryString("in:inbox content:test");
params.setSortBy(SortBy.RCPT_ASC);
try {
new ZimbraQuery(new OperationContext(mbox), SoapProtocol.Soap12, mbox, params);
Assert.fail();
} catch (ServiceException e) {
Assert.assertEquals(ServiceException.INVALID_REQUEST, e.getCode());
}
params.setSortBy(SortBy.ATTACHMENT_ASC);
try {
new ZimbraQuery(new OperationContext(mbox), SoapProtocol.Soap12, mbox, params);
} catch (ServiceException e) {
Assert.fail("Sorting by whether has attachments should be supported");
}
params.setSortBy(SortBy.FLAG_ASC);
try {
new ZimbraQuery(new OperationContext(mbox), SoapProtocol.Soap12, mbox, params);
} catch (ServiceException e) {
Assert.fail("Sorting by flagged should be supported");
}
params.setSortBy(SortBy.PRIORITY_ASC);
try {
new ZimbraQuery(new OperationContext(mbox), SoapProtocol.Soap12, mbox, params);
} catch (ServiceException e) {
Assert.fail("Sorting by priority should be supported");
}
}
use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class DocumentTest method checkName.
private static void checkName(Mailbox mbox, String name, boolean valid) throws Exception {
Document doc = null;
ParsedDocument pd = new ParsedDocument(new ByteArrayInputStream("test".getBytes()), name, "text/plain", System.currentTimeMillis(), null, null);
try {
doc = mbox.createDocument(null, Mailbox.ID_FOLDER_BRIEFCASE, pd, MailItem.Type.DOCUMENT, 0);
if (!valid) {
Assert.fail("should not have been allowed to create document: [" + name + "]");
}
} catch (ServiceException e) {
Assert.assertEquals("unexpected error code", MailServiceException.INVALID_NAME, e.getCode());
if (valid) {
Assert.fail("should have been allowed to create document: [" + name + "]");
}
}
// clean up after ourselves
if (doc != null) {
mbox.delete(null, doc.getId(), MailItem.Type.DOCUMENT);
}
}
Aggregations