Search in sources :

Example 1 with TestNotificationRecipientsProvider

use of org.apache.syncope.fit.core.reference.TestNotificationRecipientsProvider 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)

Aggregations

Response (javax.ws.rs.core.Response)1 GroupTO (org.apache.syncope.common.lib.to.GroupTO)1 ImplementationTO (org.apache.syncope.common.lib.to.ImplementationTO)1 NotificationTO (org.apache.syncope.common.lib.to.NotificationTO)1 NotificationTaskTO (org.apache.syncope.common.lib.to.NotificationTaskTO)1 TaskQuery (org.apache.syncope.common.rest.api.beans.TaskQuery)1 NotificationService (org.apache.syncope.common.rest.api.service.NotificationService)1 TestNotificationRecipientsProvider (org.apache.syncope.fit.core.reference.TestNotificationRecipientsProvider)1 Test (org.junit.jupiter.api.Test)1