Search in sources :

Example 21 with SystemException

use of org.mifos.framework.exceptions.SystemException in project head by mifos.

the class QuestionnaireValidatorIntegrationTest method shouldCheckForInValidEventSource.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldCheckForInValidEventSource() {
    EventSourceDto eventSourceDto = new EventSourceDto("Disburse", "Client", "Disburse Client");
    try {
        questionnaireValidator.validateForEventSource(eventSourceDto);
        fail("Should have raised a validation error for invalid event");
    } catch (SystemException e) {
        assertThat(e.getKey(), is(QuestionnaireConstants.INVALID_EVENT_SOURCE));
    }
}
Also used : SystemException(org.mifos.framework.exceptions.SystemException) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with SystemException

use of org.mifos.framework.exceptions.SystemException in project head by mifos.

the class QuestionnaireValidatorIntegrationTest method shouldCheckForValidEventSource.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldCheckForValidEventSource() {
    EventSourceDto eventSourceDto = new EventSourceDto("Create", "Client", "Create Client");
    try {
        questionnaireValidator.validateForEventSource(eventSourceDto);
        eventSourceDto = new EventSourceDto("View", "Client", "View Client");
        questionnaireValidator.validateForEventSource(eventSourceDto);
        eventSourceDto = new EventSourceDto("Create", "Loan", "Create Loan");
        questionnaireValidator.validateForEventSource(eventSourceDto);
    } catch (SystemException e) {
        fail("Should not have raised a validation error for this event");
    }
}
Also used : SystemException(org.mifos.framework.exceptions.SystemException) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with SystemException

use of org.mifos.framework.exceptions.SystemException in project head by mifos.

the class QuestionnaireValidatorTest method shouldThrowExceptionWhenEventSourceIsNotProvided.

@Test
public void shouldThrowExceptionWhenEventSourceIsNotProvided() {
    try {
        questionnaireValidator.validateForDefineQuestionGroup(new QuestionGroupDetail(0, "Title", null, asList(getSection("S1")), false));
        fail("Should have thrown the validation exception");
    } catch (SystemException e) {
        assertEquals(INVALID_EVENT_SOURCE, e.getKey());
    }
    verify(eventSourceDao, never()).retrieveCountByEventAndSource(anyString(), anyString());
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SystemException(org.mifos.framework.exceptions.SystemException) Test(org.junit.Test)

Example 24 with SystemException

use of org.mifos.framework.exceptions.SystemException in project head by mifos.

the class QuestionnaireValidatorTest method shouldNotThrowExceptionForNumericQuestionTypeWhenOnlyMaxBoundGiven.

@Test
public void shouldNotThrowExceptionForNumericQuestionTypeWhenOnlyMaxBoundGiven() {
    try {
        QuestionDetail questionDetail = new QuestionDetail("Title", QuestionType.NUMERIC);
        questionDetail.setNumericMax(-100);
        questionnaireValidator.validateForDefineQuestion(questionDetail);
    } catch (SystemException e) {
        fail("Should not have thrown the exception");
    }
}
Also used : SystemException(org.mifos.framework.exceptions.SystemException) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) Test(org.junit.Test)

Example 25 with SystemException

use of org.mifos.framework.exceptions.SystemException in project head by mifos.

the class QuestionGroupControllerTest method testCreateQuestionGroupFailure.

@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
@Test
public void testCreateQuestionGroupFailure() throws Exception {
    QuestionGroupForm questionGroupForm = getQuestionGroupForm(TITLE, "Create.Client", "S1", "S2");
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    doThrow(new SystemException("questionnaire.error.duplicate.question.found.in.section")).when(questionnaireServiceFacade).createActiveQuestionGroup(Matchers.<QuestionGroupDetail>anyObject());
    String result = questionGroupController.defineQuestionGroup(questionGroupForm, requestContext, true);
    assertThat(result, Is.is("failure"));
    verify(questionnaireServiceFacade).createActiveQuestionGroup(Matchers.<QuestionGroupDetail>anyObject());
    verify(requestContext).getMessageContext();
    verify(messageContext).addMessage(argThat(new MessageMatcher("questionnaire.error.duplicate.question.found.in.section")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) SystemException(org.mifos.framework.exceptions.SystemException) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) Test(org.junit.Test)

Aggregations

SystemException (org.mifos.framework.exceptions.SystemException)53 Test (org.junit.Test)21 ApplicationException (org.mifos.framework.exceptions.ApplicationException)13 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)11 PersistenceException (org.mifos.framework.exceptions.PersistenceException)10 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)10 HibernateException (org.hibernate.HibernateException)7 Session (org.hibernate.Session)7 MifosRuntimeException (org.mifos.core.MifosRuntimeException)7 HibernateProcessException (org.mifos.framework.exceptions.HibernateProcessException)7 ReportException (org.mifos.reports.exceptions.ReportException)7 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)4 BusinessRuleException (org.mifos.service.BusinessRuleException)4 IOException (java.io.IOException)3 ResultSet (java.sql.ResultSet)3 Statement (java.sql.Statement)3 ArrayList (java.util.ArrayList)3 MessageMatcher (org.mifos.platform.matchers.MessageMatcher)3 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)3 PreparedStatement (java.sql.PreparedStatement)2