Search in sources :

Example 1 with TaskErrorDto

use of org.motechproject.tasks.dto.TaskErrorDto in project motech by motech.

the class TaskServiceImplTest method shouldFailValidationIfTriggerChannelIsNotRegistered.

@Test
public void shouldFailValidationIfTriggerChannelIsNotRegistered() {
    TaskTriggerInformation trigger = new TaskTriggerInformation("triggerDisplay", "triggerChannel", "triggerModule", "1.0", "subject", "triggerListenerSubject");
    TaskActionInformation action = new TaskActionInformation("actionDisplay", "actionChannel", "actionModule", "1.0", "subject");
    Task fooTask = new TaskBuilder().withName("foo").withTrigger(trigger).withTaskConfig(new TaskConfig()).addAction(action).build();
    fooTask.setEnabled(true);
    when(channelService.getChannel("foo-module")).thenReturn(null);
    when(channelService.getChannel("actionModule")).thenReturn(null);
    Set<TaskError> errors = new HashSet<>();
    errors.add(new TaskError("task.validation.error.triggerChannelNotRegistered"));
    when(triggerEventService.validateTrigger(trigger)).thenReturn(errors);
    expectedException.expect(ValidationException.class);
    expectedException.expect(new TypeSafeMatcher<ValidationException>() {

        @Override
        public void describeTo(Description description) {
        }

        @Override
        public boolean matchesSafely(ValidationException actualException) {
            final TaskErrorDto triggerChannelError = new TaskErrorDto("task.validation.error.triggerChannelNotRegistered");
            final TaskErrorDto actionChannelError = new TaskErrorDto("task.validation.error.actionChannelNotRegistered");
            Set<TaskErrorDto> taskErrors = actualException.getTaskErrors();
            return taskErrors.contains(triggerChannelError) && taskErrors.contains(actionChannelError);
        }
    });
    taskService.save(fooTask);
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) ValidationException(org.motechproject.tasks.exception.ValidationException) Description(org.hamcrest.Description) FilterSet(org.motechproject.tasks.domain.mds.task.FilterSet) Set(java.util.Set) HashSet(java.util.HashSet) TaskErrorDto(org.motechproject.tasks.dto.TaskErrorDto) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with TaskErrorDto

use of org.motechproject.tasks.dto.TaskErrorDto in project motech by motech.

the class ValidationException method getMessage.

/**
 * Generates message based on the given errors and type of the object.
 *
 * @return  the message
 */
@Override
public String getMessage() {
    ResourceBundle rb = ResourceBundle.getBundle("webapp/messages.messages");
    StringBuilder sb = new StringBuilder();
    sb.append("There were validation errors during saving ").append(objectType).append(":\n");
    for (TaskErrorDto taskError : taskErrors) {
        sb.append(" - ").append(MessageFormat.format(rb.getString(taskError.getMessage()), taskError.getArgs().toArray())).append("\n");
    }
    return sb.toString();
}
Also used : TaskErrorDto(org.motechproject.tasks.dto.TaskErrorDto) ResourceBundle(java.util.ResourceBundle)

Aggregations

TaskErrorDto (org.motechproject.tasks.dto.TaskErrorDto)2 HashSet (java.util.HashSet)1 ResourceBundle (java.util.ResourceBundle)1 Set (java.util.Set)1 Description (org.hamcrest.Description)1 Test (org.junit.Test)1 FilterSet (org.motechproject.tasks.domain.mds.task.FilterSet)1 Task (org.motechproject.tasks.domain.mds.task.Task)1 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)1 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)1 TaskError (org.motechproject.tasks.domain.mds.task.TaskError)1 TaskTriggerInformation (org.motechproject.tasks.domain.mds.task.TaskTriggerInformation)1 TaskBuilder (org.motechproject.tasks.domain.mds.task.builder.TaskBuilder)1 ValidationException (org.motechproject.tasks.exception.ValidationException)1