use of org.apache.syncope.common.lib.to.MailTemplateTO in project syncope by apache.
the class MailTemplateITCase method read.
@Test
public void read() {
MailTemplateTO mailTemplateTO = mailTemplateService.read("optin");
assertNotNull(mailTemplateTO);
}
use of org.apache.syncope.common.lib.to.MailTemplateTO in project syncope by apache.
the class MailTemplateITCase method list.
@Test
public void list() {
List<MailTemplateTO> mailTemplateTOs = mailTemplateService.list();
assertNotNull(mailTemplateTOs);
assertFalse(mailTemplateTOs.isEmpty());
for (MailTemplateTO instance : mailTemplateTOs) {
assertNotNull(instance);
}
}
use of org.apache.syncope.common.lib.to.MailTemplateTO in project syncope by apache.
the class ResourceExplorerTopComponent method addMailTemplates.
private void addMailTemplates() {
List<MailTemplateTO> mailTemplateList = mailTemplateManagerService.list();
for (MailTemplateTO mailTemplate : mailTemplateList) {
this.mailTemplates.add(new DefaultMutableTreeNode(mailTemplate.getKey()));
}
treeModel.reload();
}
use of org.apache.syncope.common.lib.to.MailTemplateTO in project syncope by apache.
the class MailTemplateITCase method crud.
@Test
public void crud() throws IOException {
final String key = getUUIDString();
// 1. create (empty) mail template
MailTemplateTO mailTemplateTO = new MailTemplateTO();
mailTemplateTO.setKey(key);
Response response = mailTemplateService.create(mailTemplateTO);
assertEquals(201, response.getStatus());
// 2. attempt to read HTML and TEXT -> fail
try {
mailTemplateService.getFormat(key, MailTemplateFormat.HTML);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
}
try {
mailTemplateService.getFormat(key, MailTemplateFormat.TEXT);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
}
// 3. set TEXT
String textTemplate = "Hi there, I am ${username}.";
mailTemplateService.setFormat(key, MailTemplateFormat.TEXT, IOUtils.toInputStream(textTemplate, StandardCharsets.UTF_8));
response = mailTemplateService.getFormat(key, MailTemplateFormat.TEXT);
assertEquals(200, response.getStatus());
assertTrue(response.getMediaType().toString().startsWith(MediaType.TEXT_PLAIN));
assertTrue(response.getEntity() instanceof InputStream);
assertEquals(textTemplate, IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8));
// 3. set HTML
String htmlTemplate = "<html><body>Hi there, I am ${username}.</body></html>";
mailTemplateService.setFormat(key, MailTemplateFormat.HTML, IOUtils.toInputStream(htmlTemplate, StandardCharsets.UTF_8));
response = mailTemplateService.getFormat(key, MailTemplateFormat.HTML);
assertEquals(200, response.getStatus());
assertTrue(response.getMediaType().toString().startsWith(MediaType.TEXT_HTML));
assertTrue(response.getEntity() instanceof InputStream);
assertEquals(htmlTemplate, IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8));
// 4. remove HTML
mailTemplateService.removeFormat(key, MailTemplateFormat.HTML);
try {
mailTemplateService.getFormat(key, MailTemplateFormat.HTML);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
}
response = mailTemplateService.getFormat(key, MailTemplateFormat.TEXT);
assertEquals(200, response.getStatus());
assertTrue(response.getMediaType().toString().startsWith(MediaType.TEXT_PLAIN));
assertTrue(response.getEntity() instanceof InputStream);
assertEquals(textTemplate, IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8));
// 5. remove mail template
mailTemplateService.delete(key);
try {
mailTemplateService.read(key);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
}
try {
mailTemplateService.getFormat(key, MailTemplateFormat.HTML);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
}
try {
mailTemplateService.getFormat(key, MailTemplateFormat.TEXT);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
}
}
use of org.apache.syncope.common.lib.to.MailTemplateTO in project syncope by apache.
the class MailTemplateITCase method issueSYNCOPE866.
@Test
public void issueSYNCOPE866() {
MailTemplateTO mailTemplateTO = new MailTemplateTO();
mailTemplateTO.setKey("optin");
try {
mailTemplateService.create(mailTemplateTO);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.EntityExists, e.getType());
}
}
Aggregations