Search in sources :

Example 1 with ListMessagesResponse

use of com.google.api.services.gmail.model.ListMessagesResponse in project camel by apache.

the class GmailUsersMessagesIntegrationTest method testMessages.

@Test
public void testMessages() throws Exception {
    // ==== Send test email ====
    Message testEmail = createTestEmail();
    Map<String, Object> headers = new HashMap<String, Object>();
    // parameter type is String
    headers.put("CamelGoogleMail.userId", CURRENT_USERID);
    // parameter type is com.google.api.services.gmail.model.Message
    headers.put("CamelGoogleMail.content", testEmail);
    com.google.api.services.gmail.model.Message result = requestBodyAndHeaders("direct://SEND", null, headers);
    assertNotNull("send result", result);
    String testEmailId = result.getId();
    // ==== Search for message we just sent ====
    headers = new HashMap<String, Object>();
    headers.put("CamelGoogleMail.q", "subject:\"Hello from camel-google-mail\"");
    // using String message body for single parameter "userId"
    ListMessagesResponse listOfMessages = requestBody("direct://LIST", CURRENT_USERID);
    assertTrue(idInList(testEmailId, listOfMessages));
    // ===== trash it ====
    headers = new HashMap<String, Object>();
    // parameter type is String
    headers.put("CamelGoogleMail.userId", CURRENT_USERID);
    // parameter type is String
    headers.put("CamelGoogleMail.id", testEmailId);
    requestBodyAndHeaders("direct://TRASH", null, headers);
    // ==== Search for message we just trashed ====
    headers = new HashMap<String, Object>();
    headers.put("CamelGoogleMail.q", "subject:\"Hello from camel-google-mail\"");
    // using String message body for single parameter "userId"
    listOfMessages = requestBody("direct://LIST", CURRENT_USERID);
    assertFalse(idInList(testEmailId, listOfMessages));
    // ===== untrash it ====
    headers = new HashMap<String, Object>();
    // parameter type is String
    headers.put("CamelGoogleMail.userId", CURRENT_USERID);
    // parameter type is String
    headers.put("CamelGoogleMail.id", testEmailId);
    requestBodyAndHeaders("direct://UNTRASH", null, headers);
    // ==== Search for message we just trashed ====
    headers = new HashMap<String, Object>();
    headers.put("CamelGoogleMail.q", "subject:\"Hello from camel-google-mail\"");
    // using String message body for single parameter "userId"
    listOfMessages = requestBody("direct://LIST", CURRENT_USERID);
    assertTrue(idInList(testEmailId, listOfMessages));
    // ===== permanently delete it ====
    headers = new HashMap<String, Object>();
    // parameter type is String
    headers.put("CamelGoogleMail.userId", CURRENT_USERID);
    // parameter type is String
    headers.put("CamelGoogleMail.id", testEmailId);
    requestBodyAndHeaders("direct://DELETE", null, headers);
    // ==== Search for message we just deleted ====
    headers = new HashMap<String, Object>();
    headers.put("CamelGoogleMail.q", "subject:\"Hello from camel-google-mail\"");
    // using String message body for single parameter "userId"
    listOfMessages = requestBody("direct://LIST", CURRENT_USERID);
    assertFalse(idInList(testEmailId, listOfMessages));
}
Also used : ListMessagesResponse(com.google.api.services.gmail.model.ListMessagesResponse) MimeMessage(javax.mail.internet.MimeMessage) Message(com.google.api.services.gmail.model.Message) HashMap(java.util.HashMap) Message(com.google.api.services.gmail.model.Message) Test(org.junit.Test)

Aggregations

ListMessagesResponse (com.google.api.services.gmail.model.ListMessagesResponse)1 Message (com.google.api.services.gmail.model.Message)1 HashMap (java.util.HashMap)1 MimeMessage (javax.mail.internet.MimeMessage)1 Test (org.junit.Test)1