Search in sources :

Example 1 with ActionType

use of org.motechproject.admin.messages.ActionType in project motech by motech.

the class NotificationRulesDataServiceBundleIT method shouldPerformCrudOperations.

@Test
public void shouldPerformCrudOperations() {
    NotificationRule notificationRule = new NotificationRule("recip", ActionType.EMAIL, Level.CRITICAL, "admin");
    NotificationRule notificationRule2 = new NotificationRule("recip2", ActionType.SMS, Level.INFO, "tasks");
    dataService.create(notificationRule);
    dataService.create(notificationRule2);
    List<NotificationRule> notificationRules = dataService.retrieveAll();
    List<String> actual = extract(notificationRules, on(NotificationRule.class).getRecipient());
    assertThat(actual, hasItems("recip", "recip2"));
    List<ActionType> actualActions = extract(notificationRules, on(NotificationRule.class).getActionType());
    assertThat(actualActions, hasItems(ActionType.EMAIL, ActionType.SMS));
    actual = extract(notificationRules, on(NotificationRule.class).getModuleName());
    assertThat(actual, hasItems("admin", "tasks"));
    List<Level> actualLevels = extract(notificationRules, on(NotificationRule.class).getLevel());
    assertThat(actualLevels, hasItems(Level.CRITICAL, Level.INFO));
    notificationRule.setRecipient("recip3");
    dataService.update(notificationRule);
    notificationRules = dataService.retrieveAll();
    actual = extract(notificationRules, on(NotificationRule.class).getRecipient());
    assertThat(actual, hasItems("recip3", "recip2"));
    actualActions = extract(notificationRules, on(NotificationRule.class).getActionType());
    assertThat(actualActions, hasItems(ActionType.EMAIL, ActionType.SMS));
    dataService.delete(notificationRule);
    notificationRules = dataService.retrieveAll();
    assertEquals(asList("recip2"), extract(notificationRules, on(NotificationRule.class).getRecipient()));
    assertEquals(asList(ActionType.SMS), extract(notificationRules, on(NotificationRule.class).getActionType()));
    assertEquals(asList("tasks"), extract(notificationRules, on(NotificationRule.class).getModuleName()));
    assertEquals(asList(Level.INFO), extract(notificationRules, on(NotificationRule.class).getLevel()));
}
Also used : ActionType(org.motechproject.admin.messages.ActionType) NotificationRule(org.motechproject.admin.domain.NotificationRule) Level(org.motechproject.admin.messages.Level) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 NotificationRule (org.motechproject.admin.domain.NotificationRule)1 ActionType (org.motechproject.admin.messages.ActionType)1 Level (org.motechproject.admin.messages.Level)1