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));
}
Aggregations