Search in sources :

Example 1 with MailTemplateTO

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);
}
Also used : MailTemplateTO(org.apache.syncope.common.lib.to.MailTemplateTO) Test(org.junit.jupiter.api.Test)

Example 2 with 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);
    }
}
Also used : MailTemplateTO(org.apache.syncope.common.lib.to.MailTemplateTO) Test(org.junit.jupiter.api.Test)

Example 3 with MailTemplateTO

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();
}
Also used : MailTemplateTO(org.apache.syncope.common.lib.to.MailTemplateTO) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 4 with MailTemplateTO

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());
    }
}
Also used : Response(javax.ws.rs.core.Response) MailTemplateTO(org.apache.syncope.common.lib.to.MailTemplateTO) InputStream(java.io.InputStream) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

Example 5 with MailTemplateTO

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());
    }
}
Also used : MailTemplateTO(org.apache.syncope.common.lib.to.MailTemplateTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

Aggregations

MailTemplateTO (org.apache.syncope.common.lib.to.MailTemplateTO)10 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)4 Test (org.junit.jupiter.api.Test)4 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 ReportTemplateTO (org.apache.syncope.common.lib.to.ReportTemplateTO)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1 Response (javax.ws.rs.core.Response)1 MailTemplateService (org.apache.syncope.common.rest.api.service.MailTemplateService)1 ReportTemplateService (org.apache.syncope.common.rest.api.service.ReportTemplateService)1 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)1 Entity (org.apache.syncope.core.persistence.api.entity.Entity)1 MailTemplate (org.apache.syncope.core.persistence.api.entity.MailTemplate)1 Notification (org.apache.syncope.core.persistence.api.entity.Notification)1 AddTemplateDialog (org.apache.syncope.ide.eclipse.plugin.dialogs.AddTemplateDialog)1