use of com.google.api.services.gmail.model.Label in project data-transfer-project by google.
the class GoogleMailService method getMigratedLabelId.
private String getMigratedLabelId() throws IOException {
ListLabelsResponse response = gmail.users().labels().list(USER).execute();
for (Label label : response.getLabels()) {
if (label.getName().equals(LABEL)) {
return label.getId();
}
}
Label newLabel = new Label().setName(LABEL).setLabelListVisibility("labelShow").setMessageListVisibility("show");
return gmail.users().labels().create(USER, newLabel).execute().getId();
}
use of com.google.api.services.gmail.model.Label in project wildfly-camel by wildfly-extras.
the class GoogleMailIntegrationTest method testGoogleMailLabels.
@Test
public void testGoogleMailLabels() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
GoogleMailComponent gMailComponent = camelctx.getComponent("google-mail", GoogleMailComponent.class);
GoogleApiEnv.configure(gMailComponent.getConfiguration(), getClass(), LOG);
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
final String pathPrefix = "labels";
// test route for create
from("direct://CREATE").to("google-mail://" + pathPrefix + "/create");
// test route for delete
from("direct://DELETE").to("google-mail://" + pathPrefix + "/delete");
// test route for get
from("direct://GET").to("google-mail://" + pathPrefix + "/get");
// test route for list
from("direct://LIST").to("google-mail://" + pathPrefix + "/list?inBody=userId");
// test route for patch
from("direct://PATCH").to("google-mail://" + pathPrefix + "/patch");
// test route for update
from("direct://UPDATE").to("google-mail://" + pathPrefix + "/update");
}
});
try {
camelctx.start();
ProducerTemplate template = camelctx.createProducerTemplate();
// using String message body for single parameter "userId"
ListLabelsResponse labels = template.requestBody("direct://LIST", CURRENT_USERID, ListLabelsResponse.class);
final String testLabel = getClass().getSimpleName() + ".labels " + UUID.randomUUID().toString();
String labelId;
if (findLabel(labels, testLabel) == null) {
Map<String, Object> headers = new HashMap<>();
// parameter type is String
headers.put("CamelGoogleMail.userId", CURRENT_USERID);
Label label = new Label().setName(testLabel).setMessageListVisibility("show").setLabelListVisibility("labelShow");
// parameter type is com.google.api.services.gmail.model.Label
headers.put("CamelGoogleMail.content", label);
Label result = template.requestBodyAndHeaders("direct://CREATE", null, headers, Label.class);
Assert.assertNotNull("create result", result);
labelId = result.getId();
} else {
labelId = findLabel(labels, testLabel).getId();
}
// using String message body for single parameter "userId"
labels = template.requestBody("direct://LIST", CURRENT_USERID, ListLabelsResponse.class);
Assert.assertTrue(findLabel(labels, testLabel) != null);
Map<String, Object> headers = new HashMap<>();
// parameter type is String
headers.put("CamelGoogleMail.userId", CURRENT_USERID);
// parameter type is String
headers.put("CamelGoogleMail.id", labelId);
template.requestBodyAndHeaders("direct://DELETE", null, headers);
// using String message body for single parameter "userId"
labels = template.requestBody("direct://LIST", CURRENT_USERID, ListLabelsResponse.class);
Assert.assertTrue(findLabel(labels, testLabel) == null);
} finally {
camelctx.stop();
}
}
use of com.google.api.services.gmail.model.Label in project data-transfer-project by google.
the class GoogleMailImporterTest method setUp.
@Before
public void setUp() throws IOException {
Label label = new Label();
label.setId(LABEL1);
label.setName(LABEL1);
labelsListResponse = new ListLabelsResponse().setLabels(Collections.singletonList(label));
Monitor monitor = new Monitor() {
};
googleMailImporter = new GoogleMailImporter(googleCredentialFactory, gmail, monitor);
executor = new FakeIdempotentImportExecutor();
when(gmail.users()).thenReturn(users);
when(users.messages()).thenReturn(messages);
when(messages.insert(anyString(), any(Message.class))).thenReturn(insert);
when(insert.execute()).thenReturn(new Message().setId("fooBar"));
when(users.labels()).thenReturn(labels);
when(labels.list(anyString())).thenReturn(labelsList);
when(labelsList.execute()).thenReturn(labelsListResponse);
when(labels.create(anyString(), any(Label.class))).thenReturn(labelsCreate);
when(labelsCreate.execute()).thenReturn(label);
verifyNoInteractions(googleCredentialFactory);
}
use of com.google.api.services.gmail.model.Label in project camel by apache.
the class GmailUsersLabelsIntegrationTest method testLabels.
@Test
public void testLabels() throws Exception {
// using String message body for single parameter "userId"
com.google.api.services.gmail.model.ListLabelsResponse labels = requestBody("direct://LIST", CURRENT_USERID);
String labelId = null;
if (getTestLabel(labels) == null) {
Map<String, Object> headers = new HashMap<String, Object>();
// parameter type is String
headers.put("CamelGoogleMail.userId", CURRENT_USERID);
Label label = new Label().setName(CAMEL_TEST_LABEL).setMessageListVisibility("show").setLabelListVisibility("labelShow");
// parameter type is com.google.api.services.gmail.model.Label
headers.put("CamelGoogleMail.content", label);
com.google.api.services.gmail.model.Label result = requestBodyAndHeaders("direct://CREATE", null, headers);
assertNotNull("create result", result);
labelId = result.getId();
} else {
labelId = getTestLabel(labels).getId();
}
// using String message body for single parameter "userId"
labels = requestBody("direct://LIST", CURRENT_USERID);
assertTrue(getTestLabel(labels) != null);
Map<String, Object> headers = new HashMap<String, Object>();
// parameter type is String
headers.put("CamelGoogleMail.userId", CURRENT_USERID);
// parameter type is String
headers.put("CamelGoogleMail.id", labelId);
requestBodyAndHeaders("direct://DELETE", null, headers);
// using String message body for single parameter "userId"
labels = requestBody("direct://LIST", CURRENT_USERID);
assertTrue(getTestLabel(labels) == null);
}
Aggregations