Search in sources :

Example 1 with NotificationTaskTO

use of org.apache.syncope.common.lib.to.NotificationTaskTO in project syncope by apache.

the class NotificationTaskITCase method issueSYNCOPE86.

@Test
public void issueSYNCOPE86() {
    // 1. create notification task
    String sender = "syncope86@syncope.apache.org";
    Pair<String, String> created = createNotificationTask(true, true, TraceLevel.ALL, sender, "Test notification");
    // 2. get NotificationTaskTO for user just created
    NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
    assertNotNull(taskTO);
    assertNotNull(taskTO.getNotification());
    assertTrue(taskTO.getExecutions().isEmpty());
    try {
        // 3. execute the generated NotificationTask
        execNotificationTask(taskService, taskTO.getKey(), 50);
        // 4. verify
        taskTO = taskService.read(TaskType.NOTIFICATION, taskTO.getKey(), true);
        assertNotNull(taskTO);
        assertTrue(taskTO.isExecuted());
        assertEquals(1, taskTO.getExecutions().size());
    } finally {
        // Remove execution to make test re-runnable
        if (!taskTO.getExecutions().isEmpty()) {
            taskService.deleteExecution(taskTO.getExecutions().get(0).getKey());
        }
    }
}
Also used : NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO) Test(org.junit.jupiter.api.Test)

Example 2 with NotificationTaskTO

use of org.apache.syncope.common.lib.to.NotificationTaskTO in project syncope by apache.

the class NotificationTaskITCase method issueSYNCOPE81.

@Test
public void issueSYNCOPE81() {
    String sender = "syncope81@syncope.apache.org";
    Pair<String, String> created = createNotificationTask(true, true, TraceLevel.ALL, sender, "Test notification");
    NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
    assertNotNull(taskTO);
    assertNotNull(taskTO.getNotification());
    assertTrue(taskTO.getExecutions().isEmpty());
    // generate an execution in order to verify the deletion of a notification task with one or more executions
    execNotificationTask(taskService, taskTO.getKey(), 50);
    taskTO = taskService.read(TaskType.NOTIFICATION, taskTO.getKey(), true);
    assertTrue(taskTO.isExecuted());
    assertFalse(taskTO.getExecutions().isEmpty());
    taskService.delete(TaskType.NOTIFICATION, taskTO.getKey());
}
Also used : NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO) Test(org.junit.jupiter.api.Test)

Example 3 with NotificationTaskTO

use of org.apache.syncope.common.lib.to.NotificationTaskTO in project syncope by apache.

the class NotificationTaskITCase method issueSYNCOPE446.

@Test
public void issueSYNCOPE446() throws Exception {
    // 1. Create notification
    ImplementationTO recipientsProvider = new ImplementationTO();
    recipientsProvider.setKey(TestNotificationRecipientsProvider.class.getSimpleName());
    recipientsProvider.setEngine(ImplementationEngine.JAVA);
    recipientsProvider.setType(ImplementationType.RECIPIENTS_PROVIDER);
    recipientsProvider.setBody(TestNotificationRecipientsProvider.class.getName());
    Response response = implementationService.create(recipientsProvider);
    recipientsProvider = implementationService.read(recipientsProvider.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
    assertNotNull(recipientsProvider);
    NotificationTO notification = new NotificationTO();
    notification.setTraceLevel(TraceLevel.ALL);
    notification.getEvents().add("[LOGIC]:[GroupLogic]:[]:[create]:[SUCCESS]");
    String groupName = "group" + getUUIDString();
    notification.getAbouts().put(AnyTypeKind.GROUP.name(), SyncopeClient.getGroupSearchConditionBuilder().is("name").equalTo(groupName).query());
    notification.setRecipientsFIQL(SyncopeClient.getUserSearchConditionBuilder().inGroups("f779c0d4-633b-4be5-8f57-32eb478a3ca5").query());
    notification.setSelfAsRecipient(false);
    notification.setRecipientAttrName("email");
    notification.getStaticRecipients().add("notificationtest@syncope.apache.org");
    notification.setRecipientsProvider(recipientsProvider.getKey());
    String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
    notification.setSender(sender);
    String subject = "Test notification " + getUUIDString();
    notification.setSubject(subject);
    notification.setTemplate("optin");
    notification.setActive(true);
    response = notificationService.create(notification);
    notification = getObject(response.getLocation(), NotificationService.class, NotificationTO.class);
    assertNotNull(notification);
    assertEquals(recipientsProvider.getKey(), notification.getRecipientsProvider());
    // 2. create group
    GroupTO groupTO = new GroupTO();
    groupTO.setName(groupName);
    groupTO.setRealm("/even/two");
    groupTO = createGroup(groupTO).getEntity();
    assertNotNull(groupTO);
    // 3. verify
    NotificationTaskTO taskTO = findNotificationTask(notification.getKey(), 50);
    assertNotNull(taskTO);
    assertNotNull(taskTO.getNotification());
    assertTrue(taskTO.getRecipients().containsAll(new TestNotificationRecipientsProvider().provideRecipients(null)));
    NotificationTaskTO foundViaList = taskService.<NotificationTaskTO>search(new TaskQuery.Builder(TaskType.NOTIFICATION).notification(notification.getKey()).build()).getResult().get(0);
    assertEquals(taskTO, foundViaList);
    execNotificationTask(taskService, taskTO.getKey(), 50);
    assertTrue(verifyMail(sender, subject, "notificationtest@syncope.apache.org"));
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) NotificationTO(org.apache.syncope.common.lib.to.NotificationTO) TaskQuery(org.apache.syncope.common.rest.api.beans.TaskQuery) NotificationService(org.apache.syncope.common.rest.api.service.NotificationService) TestNotificationRecipientsProvider(org.apache.syncope.fit.core.reference.TestNotificationRecipientsProvider) GroupTO(org.apache.syncope.common.lib.to.GroupTO) NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO) Test(org.junit.jupiter.api.Test)

Example 4 with NotificationTaskTO

use of org.apache.syncope.common.lib.to.NotificationTaskTO in project syncope by apache.

the class NotificationTaskITCase method notifyByMail.

@Test
public void notifyByMail() throws Exception {
    String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
    String subject = "Test notification " + getUUIDString();
    Pair<String, String> created = createNotificationTask(true, true, TraceLevel.ALL, sender, subject);
    NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
    assertNotNull(taskTO);
    assertNotNull(taskTO.getNotification());
    assertTrue(taskTO.getExecutions().isEmpty());
    execNotificationTask(taskService, taskTO.getKey(), 50);
    assertTrue(verifyMail(sender, subject, created.getRight()));
    // verify message body
    taskTO = taskService.read(TaskType.NOTIFICATION, taskTO.getKey(), true);
    assertNotNull(taskTO);
    assertTrue(taskTO.isExecuted());
    assertNotNull(taskTO.getTextBody());
    assertTrue(taskTO.getTextBody().contains("Your email address is " + created.getRight() + "."));
    assertTrue(taskTO.getTextBody().contains("Your email address inside a link: " + "http://localhost/?email=" + created.getRight().replaceAll("@", "%40")));
}
Also used : NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO) Test(org.junit.jupiter.api.Test)

Example 5 with NotificationTaskTO

use of org.apache.syncope.common.lib.to.NotificationTaskTO in project syncope by apache.

the class NotificationTaskITCase method issueSYNCOPE445.

@Test
public void issueSYNCOPE445() throws Exception {
    String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
    String subject = "Test notification " + getUUIDString();
    Pair<String, String> created = createNotificationTask(true, true, TraceLevel.ALL, sender, subject, "syncope445@syncope.apache.org");
    NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
    assertNotNull(taskTO);
    assertNotNull(taskTO.getNotification());
    assertTrue(taskTO.getExecutions().isEmpty());
    execNotificationTask(taskService, taskTO.getKey(), 50);
    assertTrue(verifyMail(sender, subject, created.getRight()));
    // verify task
    taskTO = taskService.read(TaskType.NOTIFICATION, taskTO.getKey(), true);
    assertTrue(taskTO.isExecuted());
    assertNotNull(taskTO);
    assertTrue(taskTO.getRecipients().contains("syncope445@syncope.apache.org"));
}
Also used : NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO) Test(org.junit.jupiter.api.Test)

Aggregations

NotificationTaskTO (org.apache.syncope.common.lib.to.NotificationTaskTO)13 Test (org.junit.jupiter.api.Test)9 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)3 PushTaskTO (org.apache.syncope.common.lib.to.PushTaskTO)3 Response (javax.ws.rs.core.Response)2 ExecTO (org.apache.syncope.common.lib.to.ExecTO)2 NotificationTO (org.apache.syncope.common.lib.to.NotificationTO)2 PropagationTaskTO (org.apache.syncope.common.lib.to.PropagationTaskTO)2 PullTaskTO (org.apache.syncope.common.lib.to.PullTaskTO)2 SchedTaskTO (org.apache.syncope.common.lib.to.SchedTaskTO)2 TaskTO (org.apache.syncope.common.lib.to.TaskTO)2 TaskType (org.apache.syncope.common.lib.types.TaskType)2 TaskQuery (org.apache.syncope.common.rest.api.beans.TaskQuery)2 NotificationService (org.apache.syncope.common.rest.api.service.NotificationService)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1