use of org.mifos.framework.exceptions.SystemException in project head by mifos.
the class QuestionnaireServiceTest method shouldDefineQuestionWithAnswerChoicesAndTags.
@Test
public void shouldDefineQuestionWithAnswerChoicesAndTags() throws SystemException {
ChoiceDto choice1 = new ChoiceDto("choice1");
choice1.setTags(asList("Tag1", "Tag2"));
ChoiceDto choice2 = new ChoiceDto("choice2");
choice2.setTags(asList("Tag3"));
List<ChoiceDto> answerChoices = asList(choice1, choice2);
QuestionDetail questionDefinition = new QuestionDetail(QUESTION_TITLE, QuestionType.MULTI_SELECT);
questionDefinition.setAnswerChoices(answerChoices);
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.MULTI_SELECT, questionDetail.getType());
Assert.assertEquals(choice1.getValue(), questionDetail.getAnswerChoices().get(0).getValue());
Assert.assertEquals(choice1.getTags().get(0), questionDetail.getAnswerChoices().get(0).getTags().get(0));
Assert.assertEquals(choice1.getTags().get(1), questionDetail.getAnswerChoices().get(0).getTags().get(1));
Assert.assertEquals(choice2.getValue(), questionDetail.getAnswerChoices().get(1).getValue());
Assert.assertEquals(choice2.getTags().get(0), questionDetail.getAnswerChoices().get(1).getTags().get(0));
} 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 QuestionnaireServiceTest method shouldDefineQuestionGroup.
@Test
@Ignore
public void shouldDefineQuestionGroup() throws SystemException {
QuestionGroupDetail questionGroupDefinition = getQuestionGroupDetail(EVENT_CREATE, SOURCE_CLIENT, "S1", "S2");
setUpEventSourceExpectations(EVENT_CREATE, SOURCE_CLIENT);
when(questionDao.getDetails(anyInt())).thenReturn(getQuestion(11), getQuestion(12), getQuestion(11), getQuestion(12));
try {
QuestionGroupDetail questionGroupDetail = questionnaireService.defineQuestionGroup(questionGroupDefinition);
assertQuestionGroupDetail(questionGroupDetail);
verify(questionnaireValidator).validateForDefineQuestionGroup(questionGroupDefinition);
verify(questionGroupDao, times(1)).create(any(QuestionGroup.class));
verify(eventSourceDao, times(1)).retrieveByEventAndSource(anyString(), anyString());
verify(questionDao, times(4)).getDetails(anyInt());
} catch (SystemException e) {
Assert.fail("Should not have thrown the validation exception");
}
}
use of org.mifos.framework.exceptions.SystemException in project head by mifos.
the class QuestionnaireServiceTest method shouldThrowValidationExceptionWhenQuestionGroupTitleIsNull.
@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
@Test(expected = SystemException.class)
public void shouldThrowValidationExceptionWhenQuestionGroupTitleIsNull() throws SystemException {
QuestionGroupDetail questionGroupDetail = new QuestionGroupDetail(0, null, null, asList(getSectionDefinition("S1")), false);
doThrow(new SystemException(QuestionnaireConstants.QUESTION_GROUP_TITLE_NOT_PROVIDED)).when(questionnaireValidator).validateForDefineQuestionGroup(questionGroupDetail);
questionnaireService.defineQuestionGroup(questionGroupDetail);
verify(questionnaireValidator).validateForDefineQuestionGroup(questionGroupDetail);
}
use of org.mifos.framework.exceptions.SystemException in project head by mifos.
the class PasswordHashing method getHashedPassword.
/**
* This function will return the hashed password out of the passed string
* password
*
* @param password
* password passed by the user
* @param randomBytes
* random bytes
*/
public byte[] getHashedPassword(String password, byte[] randomBytes) {
byte[] hashedPassword = null;
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(randomBytes);
messageDigest.update(password.getBytes("UTF-8"));
hashedPassword = messageDigest.digest();
} catch (NoSuchAlgorithmException e) {
throw new SystemException(e);
} catch (UnsupportedEncodingException e) {
throw new SystemException(e);
}
return hashedPassword;
}
use of org.mifos.framework.exceptions.SystemException in project head by mifos.
the class PPISurveyLocatorImpl method getPPIUploadFileForCountry.
@Override
public String getPPIUploadFileForCountry(String country) {
try {
String fileName = getPPIXmlFileName(country);
Resource resource = this.resourceLoader.getResource(resolvePath());
return getPPIFilePath(fileName, resource.getFile());
} catch (IOException e) {
throw new SystemException(FETCH_PPI_COUNTRY_XML_FAILED, e);
}
}
Aggregations