Search in sources :

Example 11 with SystemException

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));
}
Also used : SystemException(org.mifos.framework.exceptions.SystemException) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) Test(org.junit.Test)

Example 12 with SystemException

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");
    }
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SystemException(org.mifos.framework.exceptions.SystemException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 13 with SystemException

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);
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SystemException(org.mifos.framework.exceptions.SystemException) Test(org.junit.Test)

Example 14 with SystemException

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;
}
Also used : SystemException(org.mifos.framework.exceptions.SystemException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Example 15 with SystemException

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);
    }
}
Also used : SystemException(org.mifos.framework.exceptions.SystemException) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException)

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