Search in sources :

Example 11 with QuestionForm

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

the class QuestionControllerTest method testAddQuestionForSuccessWhenTwoChoicesAreGivenForSigleSelect.

@Test
public void testAddQuestionForSuccessWhenTwoChoicesAreGivenForSigleSelect() throws Exception {
    QuestionForm questionForm = new QuestionForm();
    questionForm.getCurrentQuestion().setText("  " + TITLE + "    ");
    questionForm.getCurrentQuestion().setType("singleSelect");
    questionForm.getCurrentQuestion().setCurrentChoice("C1");
    questionForm.getCurrentQuestion().addAnswerChoice();
    questionForm.getCurrentQuestion().setCurrentChoice("C2");
    questionForm.getCurrentQuestion().addAnswerChoice();
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    String result = questionController.addQuestion(questionForm, requestContext, true);
    Assert.assertThat(result, is(notNullValue()));
    Assert.assertThat(result, is("success"));
    Assert.assertThat(questionForm.getQuestions().size(), is(1));
}
Also used : QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Test(org.junit.Test)

Example 12 with QuestionForm

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

the class QuestionControllerTest method testRemoveQuestion.

@Test
public void testRemoveQuestion() {
    QuestionForm questionForm = new QuestionForm();
    ArrayList<Question> questions = new ArrayList<Question>();
    questionForm.setQuestions(questions);
    String title = "title";
    questions.add(getQuestion("1", title, "freeText"));
    questionController.removeQuestion(questionForm, "");
    questionController.removeQuestion(questionForm, "junk");
    Assert.assertThat(questionForm.getQuestions().size(), is(1));
    questionController.removeQuestion(questionForm, title);
    Assert.assertThat(questionForm.getQuestions().size(), is(0));
}
Also used : QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) ArrayList(java.util.ArrayList) Question(org.mifos.platform.questionnaire.ui.model.Question) Test(org.junit.Test)

Example 13 with QuestionForm

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

the class QuestionControllerTest method testAddQuestionForFailureWhenQuestionTitleProvidedWithAllBlanks.

@Test
public void testAddQuestionForFailureWhenQuestionTitleProvidedWithAllBlanks() throws Exception {
    QuestionForm qform = new QuestionForm();
    qform.setValidator(validator);
    qform.getCurrentQuestion().setText("   ");
    qform.getCurrentQuestion().setType("freeText");
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    when(messageContext.hasErrorMessages()).thenReturn(true);
    String result = questionController.addQuestion(qform, requestContext, true);
    Assert.assertThat(qform.getQuestions().size(), is(0));
    Assert.assertThat(result, is(notNullValue()));
    Assert.assertThat(result, is("failure"));
    Mockito.verify(requestContext).getMessageContext();
    // TODO: Assert for message code content
    Mockito.verify(messageContext).addMessage(argThat(new MessageMatcher("Pattern.QuestionForm.currentQuestion.text")));
//verify(messageContext).addMessage(argThat(new MessageMatcher("NotNull.QuestionForm.currentQuestion.type")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Test(org.junit.Test)

Example 14 with QuestionForm

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

the class QuestionControllerTest method testAddQuestionWhenTitleIsEdited.

@Test
public void testAddQuestionWhenTitleIsEdited() throws Exception {
    Question currentQuestion = new Question();
    QuestionDetail questionDetail = new QuestionDetail();
    questionDetail.setText(TITLE);
    questionDetail.setType(QuestionType.SINGLE_SELECT);
    questionDetail.setAnswerChoices(new ArrayList<ChoiceDto>(Arrays.asList(new ChoiceDto("choice1"), new ChoiceDto("choice2"))));
    currentQuestion.setQuestionDetail(questionDetail);
    currentQuestion.setCurrentChoice("choice3");
    currentQuestion.addAnswerChoice();
    QuestionForm questionForm = new QuestionForm();
    questionForm.setCurrentQuestion(currentQuestion);
    questionForm.getCurrentQuestion().setText(TITLE + 1);
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    when(questionnaireServiceFacade.isDuplicateQuestion(TITLE + 1)).thenReturn(false);
    String result = questionController.addQuestion(questionForm, requestContext, false);
    Assert.assertThat(questionForm.getQuestions().size(), is(1));
    Assert.assertThat(questionForm.getQuestions().get(0).getInitialNumberOfChoices(), is(2));
    Assert.assertThat(questionForm.getQuestions().get(0).getChoices().size(), is(3));
    Assert.assertThat(result, is("success"));
}
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) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) Test(org.junit.Test)

Example 15 with QuestionForm

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

the class QuestionControllerTest method getQuestionForm.

private QuestionForm getQuestionForm(String title, String type) {
    QuestionForm questionForm = new QuestionForm();
    questionForm.getCurrentQuestion().setText(title);
    questionForm.getCurrentQuestion().setType(type);
    return questionForm;
}
Also used : QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm)

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