@Test public void tooLongSender() throws Exception { Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID); Map<String, Object> fields = new HashMap<String, Object>(); fields.put(ContactConstants.A_firstName, Strings.repeat("F", 129)); Contact contact = mbox.createContact(null, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null); DbConnection conn = DbPool.getConnection(mbox); Assert.assertEquals( Strings.repeat("F", 128), DbUtil.executeQuery( conn, "SELECT sender FROM mboxgroup1.mail_item WHERE mailbox_id = ? AND id = ?", mbox.getId(), contact.getId()) .getString(1)); fields.put(ContactConstants.A_firstName, null); fields.put(ContactConstants.A_lastName, Strings.repeat("L", 129)); mbox.modifyContact(null, contact.getId(), new ParsedContact(fields)); Assert.assertEquals( Strings.repeat("L", 128), DbUtil.executeQuery( conn, "SELECT sender FROM mboxgroup1.mail_item WHERE mailbox_id = ? AND id = ?", mbox.getId(), contact.getId()) .getString(1)); conn.closeQuietly(); }
/** Confirms that locator is not set for contacts. */ @Test public void locator() throws Exception { // Create contact. Map<String, String> attrs = Maps.newHashMap(); attrs.put(ContactConstants.A_fullName, "Volume Id"); Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID); mbox.createContact(null, new ParsedContact(attrs), Mailbox.ID_FOLDER_CONTACTS, null); // Check volume id in database. String sql = String.format( "SELECT COUNT(*) FROM %s WHERE type = %d AND blob_digest IS NULL AND locator IS NOT NULL", DbMailItem.getMailItemTableName(mbox), MailItem.Type.CONTACT.toByte()); DbResults results = DbUtil.executeQuery(sql); Assert.assertEquals("Found non-null locator values for contacts", 0, results.getInt(1)); }