Search in sources :

Example 1 with QuestionForm

use of org.mifos.platform.questionnaire.ui.model.QuestionForm in project head by mifos.

the class QuestionFormTest method testAddCurrentMultiSelectQuestion.

@Test
public void testAddCurrentMultiSelectQuestion() {
    QuestionForm questionForm = getQuestionForm("title", "multiSelect", "choice2");
    List<Question> questionList = questionForm.getQuestions();
    assertThat(questionList.size(), is(1));
    String text = questionList.get(0).getText();
    String type = questionList.get(0).getType();
    List<ChoiceDto> choices = questionList.get(0).getChoices();
    assertNotSame(type, questionForm.getCurrentQuestion().getType());
    assertNotSame(text, questionForm.getCurrentQuestion().getText());
    assertThat(type, is("multiSelect"));
    assertThat(text, is("title"));
    assertThat(choices.get(0).getValue(), is("choice2"));
}
Also used : QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Question(org.mifos.platform.questionnaire.ui.model.Question) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) Test(org.junit.Test)

Example 2 with QuestionForm

use of org.mifos.platform.questionnaire.ui.model.QuestionForm in project head by mifos.

the class QuestionControllerTest method testAddQuestionForFailureWhenQuestionTitleIsDuplicateInDB.

@Test
public void testAddQuestionForFailureWhenQuestionTitleIsDuplicateInDB() throws Exception {
    QuestionForm questionForm = new QuestionForm();
    questionForm.getCurrentQuestion().setText(TITLE);
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    when(questionnaireServiceFacade.isDuplicateQuestion(TITLE)).thenReturn(true);
    String result = questionController.addQuestion(questionForm, requestContext, true);
    Assert.assertThat(questionForm.getQuestions().size(), is(0));
    Assert.assertThat(result, is("failure"));
    Mockito.verify(requestContext).getMessageContext();
    Mockito.verify(messageContext).addMessage(argThat(new MessageMatcher("questionnaire.error.question.duplicate")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Test(org.junit.Test)

Example 3 with QuestionForm

use of org.mifos.platform.questionnaire.ui.model.QuestionForm 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)

Example 4 with QuestionForm

use of org.mifos.platform.questionnaire.ui.model.QuestionForm in project head by mifos.

the class QuestionControllerTest method testAddQuestionForFailureWhenLessThanTwoChoicesAreGivenForMultiSelect.

@Test
public void testAddQuestionForFailureWhenLessThanTwoChoicesAreGivenForMultiSelect() throws Exception {
    QuestionForm questionForm = new QuestionForm();
    questionForm.getCurrentQuestion().setText("  " + TITLE + "    ");
    questionForm.getCurrentQuestion().setType("multiSelect");
    questionForm.getCurrentQuestion().setCurrentChoice("C1");
    questionForm.getCurrentQuestion().addAnswerChoice();
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    String result = questionController.addQuestion(questionForm, requestContext, true);
    Assert.assertThat(result, is(notNullValue()));
    Assert.assertThat(result, is("failure"));
    Mockito.verify(requestContext).getMessageContext();
    Mockito.verify(messageContext).addMessage(argThat(new MessageMatcher("questionnaire.error.question.choices")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Test(org.junit.Test)

Example 5 with QuestionForm

use of org.mifos.platform.questionnaire.ui.model.QuestionForm in project head by mifos.

the class QuestionControllerTest method testAddQuestionForFailureWhenInvalidNumericBoundsGiven.

@Test
public void testAddQuestionForFailureWhenInvalidNumericBoundsGiven() throws Exception {
    QuestionForm questionForm = getQuestionForm(TITLE, "number");
    questionForm.getCurrentQuestion().setNumericMin(100);
    questionForm.getCurrentQuestion().setNumericMax(10);
    questionForm.setValidator(validator);
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    when(messageContext.hasErrorMessages()).thenReturn(false);
    String result = questionController.addQuestion(questionForm, requestContext, true);
    Assert.assertThat(questionForm.getQuestions().size(), is(0));
    Assert.assertThat(result, is("failure"));
    Mockito.verify(requestContext).getMessageContext();
    Mockito.verify(messageContext).addMessage(argThat(new MessageMatcher(QuestionnaireConstants.INVALID_NUMERIC_BOUNDS)));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Test(org.junit.Test)

Aggregations

QuestionForm (org.mifos.platform.questionnaire.ui.model.QuestionForm)20 Test (org.junit.Test)18 Question (org.mifos.platform.questionnaire.ui.model.Question)8 MessageMatcher (org.mifos.platform.matchers.MessageMatcher)7 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)5 ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)4 ArrayList (java.util.ArrayList)1 SystemException (org.mifos.framework.exceptions.SystemException)1