use of org.alfresco.rest.api.tests.client.data.QuickShareLinkEmailRequest in project alfresco-remote-api by Alfresco.
the class SharedLinkApiTest method testEmailSharedLink.
/**
* Tests emailing shared links.
* <p>POST:</p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/shared-links/<sharedId>/email}
*/
@Test
public void testEmailSharedLink() throws Exception {
setRequestContext(user1);
// Create plain text document
String myFolderNodeId = getMyNodeId();
String contentText = "The quick brown fox jumps over the lazy dog.";
String fileName = "file-" + RUNID + ".txt";
Document doc = createTextFile(myFolderNodeId, fileName, contentText);
String docId = doc.getId();
// Create shared link to document
Map<String, String> body = Collections.singletonMap("nodeId", docId);
HttpResponse response = post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 201);
QuickShareLink resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class);
String sharedId = resp.getId();
assertNotNull(sharedId);
assertEquals(fileName, resp.getName());
// Email request with minimal properties
QuickShareLinkEmailRequest request = new QuickShareLinkEmailRequest();
request.setClient("share");
List<String> recipients = new ArrayList<>(2);
recipients.add(user2 + "@acme.test");
recipients.add(user2 + "@ping.test");
request.setRecipientEmails(recipients);
post(getEmailSharedLinkUrl(sharedId), RestApiUtil.toJsonAsString(request), 202);
// Email request with all the properties
request = new QuickShareLinkEmailRequest();
request.setClient("share");
request.setMessage("My custom message!");
request.setLocale(Locale.UK.toString());
recipients = Collections.singletonList(user2 + "@acme.test");
request.setRecipientEmails(recipients);
post(getEmailSharedLinkUrl(sharedId), RestApiUtil.toJsonAsString(request), 202);
// -ve tests
// sharedId path parameter does not exist
post(getEmailSharedLinkUrl(sharedId + System.currentTimeMillis()), RestApiUtil.toJsonAsString(request), 404);
// Unregistered client
request = new QuickShareLinkEmailRequest();
request.setClient("VeryCoolClient" + System.currentTimeMillis());
List<String> user2Email = Collections.singletonList(user2 + "@acme.test");
request.setRecipientEmails(user2Email);
post(getEmailSharedLinkUrl(sharedId), RestApiUtil.toJsonAsString(request), 404);
// client is mandatory
request.setClient(null);
post(getEmailSharedLinkUrl(sharedId), RestApiUtil.toJsonAsString(request), 400);
// recipientEmails is mandatory
request.setClient("share");
request.setRecipientEmails(null);
post(getEmailSharedLinkUrl(sharedId), RestApiUtil.toJsonAsString(request), 400);
// TODO if and when these tests are optionally runnable via remote env then we could skip this part of the test
// (else need to verify test mechanism for enterprise admin via jmx ... etc)
QuickShareLinksImpl quickShareLinks = applicationContext.getBean("quickShareLinks", QuickShareLinksImpl.class);
try {
quickShareLinks.setEnabled(false);
request = new QuickShareLinkEmailRequest();
request.setClient("share");
request.setRecipientEmails(user2Email);
post(getEmailSharedLinkUrl(sharedId), RestApiUtil.toJsonAsString(request), 501);
} finally {
quickShareLinks.setEnabled(true);
}
}
Aggregations