Search in sources :

Example 16 with SystemException

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

the class QuestionGroupController method getQuestionGroup.

@RequestMapping("/viewQuestionGroupDetail.ftl")
public String getQuestionGroup(ModelMap model, HttpServletRequest httpServletRequest) {
    String questionGroupId = httpServletRequest.getParameter("questionGroupId");
    try {
        if (isInvalidNumber(questionGroupId)) {
            model.addAttribute("error_message_code", QuestionnaireConstants.INVALID_QUESTION_GROUP_ID);
        } else {
            QuestionGroupDetail questionGroupDetail = questionnaireServiceFacade.getQuestionGroupDetail(Integer.valueOf(questionGroupId));
            QuestionGroupForm questionGroupForm = new QuestionGroupForm(questionGroupDetail);
            model.addAttribute("questionGroupDetail", questionGroupForm);
            model.addAttribute("eventSources", getAllQgEventSources());
        }
    } catch (SystemException e) {
        //TODO: move mifosLogManager to common after dependency resolution
        //MifosLogManager.getLogger(LoggerConstants.ROOTLOGGER).error(e.getMessage(), e);
        model.addAttribute("error_message_code", QuestionnaireConstants.QUESTION_GROUP_NOT_FOUND);
    }
    return "viewQuestionGroupDetail";
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SystemException(org.mifos.framework.exceptions.SystemException) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with SystemException

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

the class Upgrade method countRows.

@SuppressWarnings("PMD.CloseResource")
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = { "OBL_UNSATISFIED_OBLIGATION", "SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE" }, justification = "The statement is closed and the query cannot be static.")
private int countRows(Connection connection, String tableName) throws SQLException {
    int numFields = 0;
    Statement statement = connection.createStatement();
    try {
        ResultSet results = statement.executeQuery("select count(*) from " + tableName);
        if (!results.next()) {
            throw new SystemException(SystemException.DEFAULT_KEY, "Query failed on table: " + tableName);
        }
        numFields = results.getInt(1);
    } finally {
        statement.close();
    }
    return numFields;
}
Also used : SystemException(org.mifos.framework.exceptions.SystemException) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) ResultSet(java.sql.ResultSet)

Example 18 with SystemException

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

the class QuestionGroupControllerTest method testGetQuestionGroupWhenNotPresentInDb.

@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
@Test
public void testGetQuestionGroupWhenNotPresentInDb() throws SystemException {
    int questionGroupId = 1;
    when(questionnaireServiceFacade.getQuestionGroupDetail(questionGroupId)).thenThrow(new SystemException(QuestionnaireConstants.QUESTION_GROUP_NOT_FOUND));
    when(httpServletRequest.getParameter("questionGroupId")).thenReturn("1");
    String view = questionGroupController.getQuestionGroup(model, httpServletRequest);
    assertThat(view, Is.is("viewQuestionGroupDetail"));
    verify(questionnaireServiceFacade).getQuestionGroupDetail(questionGroupId);
    verify(httpServletRequest, times(1)).getParameter("questionGroupId");
    verify(model).addAttribute("error_message_code", QuestionnaireConstants.QUESTION_GROUP_NOT_FOUND);
}
Also used : SystemException(org.mifos.framework.exceptions.SystemException) Test(org.junit.Test)

Example 19 with SystemException

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

the class QuestionnaireServiceTest method shouldDefineQuestion.

@Test
public void shouldDefineQuestion() throws SystemException {
    QuestionDetail questionDefinition = new QuestionDetail(QUESTION_TITLE, QuestionType.FREETEXT);
    try {
        QuestionDetail questionDetail = questionnaireService.defineQuestion(questionDefinition);
        verify(questionDao, times(1)).saveOrUpdate(any(QuestionEntity.class));
        Assert.assertNotNull(questionDetail);
        Assert.assertEquals(QUESTION_TITLE, questionDetail.getText());
        Assert.assertEquals(QuestionType.FREETEXT, questionDetail.getType());
    } catch (SystemException e) {
        Assert.fail("Should not have thrown the validation exception");
    }
    verify(questionnaireValidator).validateForDefineQuestion(questionDefinition);
    verify(questionDao).saveOrUpdate(any(QuestionEntity.class));
}
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 20 with SystemException

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

the class QuestionControllerTest method testCreateQuestionFailure.

@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
@Test
public void testCreateQuestionFailure() throws Exception {
    QuestionForm questionForm = getQuestionForm(TITLE, "numeric");
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    Mockito.doThrow(new SystemException("db.write.failure")).when(questionnaireServiceFacade).createQuestions(Matchers.<List<QuestionDetail>>anyObject());
    String result = questionController.createQuestions(questionForm, requestContext);
    Assert.assertThat(result, is("failure"));
    Mockito.verify(questionnaireServiceFacade).createQuestions(Matchers.<List<QuestionDetail>>anyObject());
    Mockito.verify(requestContext).getMessageContext();
    Mockito.verify(messageContext).addMessage(argThat(new MessageMatcher("db.write.failure")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) SystemException(org.mifos.framework.exceptions.SystemException) QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) 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