use of org.mifos.platform.questionnaire.service.QuestionDetail in project head by mifos.
the class QuestionnaireValidatorTest method shouldThrowExceptionWhenQuestionTitleIsProvided.
@Test
public void shouldThrowExceptionWhenQuestionTitleIsProvided() {
try {
questionnaireValidator.validateForDefineQuestion(new QuestionDetail(null, QuestionType.FREETEXT));
fail("Should have thrown the validation exception");
} catch (SystemException e) {
assertEquals(QUESTION_TEXT_NOT_PROVIDED, e.getKey());
}
}
use of org.mifos.platform.questionnaire.service.QuestionDetail in project head by mifos.
the class QuestionnaireValidatorTest method shouldNotThrowExceptionForNumericQuestionTypeWhenOnlyMinBoundGiven.
@Test
public void shouldNotThrowExceptionForNumericQuestionTypeWhenOnlyMinBoundGiven() {
try {
QuestionDetail questionDetail = new QuestionDetail("Title", QuestionType.NUMERIC);
questionDetail.setNumericMin(10);
questionnaireValidator.validateForDefineQuestion(questionDetail);
} catch (SystemException e) {
fail("Should not have thrown the exception");
}
}
use of org.mifos.platform.questionnaire.service.QuestionDetail in project head by mifos.
the class QuestionnaireValidatorTest method shouldThrowExceptionWhenANumericQuestionHasAnswerLessThanMin.
@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" })
@Test
public void shouldThrowExceptionWhenANumericQuestionHasAnswerLessThanMin() {
QuestionDetail questionDetail = getNumericQuestionDetail("Numeric Question", 10, null);
SectionDetail sectionWithOneQuestion = getSectionWithOneQuestion("Sec1", questionDetail, "9");
QuestionGroupDetail questionGroupDetail = getQuestionGroupDetail(0, "Title", "Create", "Client", asList(sectionWithOneQuestion));
try {
questionnaireValidator.validateForQuestionGroupResponses(asList(questionGroupDetail));
fail("Should have thrown the validation exception");
} catch (ValidationException e) {
assertEquals(GENERIC_VALIDATION, e.getKey());
assertEquals(true, e.hasChildExceptions());
assertEquals(1, e.getChildExceptions().size());
ValidationException childException = e.getChildExceptions().get(0);
assertTrue(childException instanceof BadNumericResponseException);
assertEquals("Numeric Question", childException.getIdentifier());
assertEquals(Integer.valueOf(10), ((BadNumericResponseException) childException).getAllowedMinValue());
assertNull(((BadNumericResponseException) childException).getAllowedMaxValue());
}
}
use of org.mifos.platform.questionnaire.service.QuestionDetail in project head by mifos.
the class QuestionTest method testRemoveAnswerChoice.
@Test
public void testRemoveAnswerChoice() {
Question question = new Question(new QuestionDetail());
question.setCurrentChoice("choice1");
question.addAnswerChoice();
question.setCurrentChoice("choice2");
question.addAnswerChoice();
question.setCurrentChoice("choice1");
question.addAnswerChoice();
assertEquals("choice1", question.getChoices().get(0).getValue());
assertEquals("choice2", question.getChoices().get(1).getValue());
assertEquals("choice1", question.getChoices().get(2).getValue());
question.removeChoice(0);
assertEquals("choice2", question.getChoices().get(0).getValue());
assertEquals("choice1", question.getChoices().get(1).getValue());
question.removeChoice(1);
assertEquals("choice2", question.getChoices().get(0).getValue());
}
use of org.mifos.platform.questionnaire.service.QuestionDetail in project head by mifos.
the class QuestionTest method testAddSmartChoice.
@Test
public void testAddSmartChoice() {
Question question = new Question(new QuestionDetail());
question.setCurrentSmartChoice("Choice1");
question.addAnswerSmartChoice();
assertThat(question.getCurrentSmartChoice(), is(nullValue()));
assertThat(question.getCurrentSmartChoiceTags().size(), is(1));
assertThat(question.getCurrentSmartChoiceTags().get(0), is(""));
question.setCurrentSmartChoice("Choice2");
question.addAnswerSmartChoice();
assertThat(question.getCurrentSmartChoice(), is(nullValue()));
assertThat(question.getCurrentSmartChoiceTags().size(), is(2));
assertThat(question.getCurrentSmartChoiceTags().get(0), is(""));
assertThat(question.getCurrentSmartChoiceTags().get(1), is(""));
}
Aggregations