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";
}
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;
}
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);
}
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));
}
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")));
}
Aggregations