Search in sources :

Example 16 with QuestionForm

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

the class QuestionControllerTest method testAddQuestionForSuccess.

@Test
public void testAddQuestionForSuccess() throws Exception {
    QuestionForm questionForm = getQuestionForm(TITLE, "numeric");
    when(questionnaireServiceFacade.isDuplicateQuestion(TITLE)).thenReturn(false);
    when(messageContext.getAllMessages()).thenReturn(new Message[] {});
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    String result = questionController.addQuestion(questionForm, requestContext, true);
    List<Question> questions = questionForm.getQuestions();
    Mockito.verify(questionnaireServiceFacade).isDuplicateQuestion(TITLE);
    Assert.assertThat(questions, is(notNullValue()));
    Assert.assertThat(questions.size(), is(1));
    Assert.assertThat(result, is("success"));
}
Also used : QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Question(org.mifos.platform.questionnaire.ui.model.Question) Test(org.junit.Test)

Example 17 with QuestionForm

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

the class QuestionControllerTest method testAddQuestionForFailureWhenQuestionTitleNotProvided.

@Test
public void testAddQuestionForFailureWhenQuestionTitleNotProvided() throws Exception {
    QuestionForm questionForm = new QuestionForm();
    questionForm.setValidator(validator);
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    when(messageContext.hasErrorMessages()).thenReturn(true);
    String result = questionController.addQuestion(questionForm, requestContext, true);
    Assert.assertThat(questionForm.getQuestions().size(), is(0));
    Assert.assertThat(result, is(notNullValue()));
    Assert.assertThat(result, is("failure"));
    Mockito.verify(requestContext).getMessageContext();
    Mockito.verify(messageContext).addMessage(argThat(new MessageMatcher("NotNull.QuestionForm.currentQuestion.text")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Test(org.junit.Test)

Example 18 with QuestionForm

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

the class QuestionControllerTest method testAddQuestionForFailureWhenQuestionTitleIsDuplicateInForm.

@Test
public void testAddQuestionForFailureWhenQuestionTitleIsDuplicateInForm() throws Exception {
    QuestionForm questionForm = new QuestionForm();
    questionForm.getCurrentQuestion().setText("  " + TITLE + "    ");
    questionForm.setQuestions(Arrays.asList(getQuestion("0", TITLE, "number")));
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    String result = questionController.addQuestion(questionForm, requestContext, true);
    Assert.assertThat(questionForm.getQuestions().size(), is(1));
    Assert.assertThat(result, is(notNullValue()));
    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 19 with QuestionForm

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

the class QuestionControllerTest method testCreateQuestionSuccess.

@Test
public void testCreateQuestionSuccess() throws Exception {
    QuestionForm questionForm = getQuestionForm(TITLE, "date");
    String result = questionController.createQuestions(questionForm, requestContext);
    Assert.assertThat(result, is("success"));
    Mockito.verify(questionnaireServiceFacade).createQuestions(anyListOf(QuestionDetail.class));
}
Also used : QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) Test(org.junit.Test)

Example 20 with QuestionForm

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

the class QuestionControllerTest method testAddQuestionDuringEditOperationWhereTitleIsUnchanged.

@Test
public void testAddQuestionDuringEditOperationWhereTitleIsUnchanged() throws Exception {
    Question currentQuestion = new Question();
    QuestionDetail questionDetail = new QuestionDetail();
    questionDetail.setText(TITLE);
    currentQuestion.setQuestionDetail(questionDetail);
    QuestionForm questionForm = new QuestionForm();
    questionForm.setCurrentQuestion(currentQuestion);
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    when(questionnaireServiceFacade.isDuplicateQuestion(TITLE)).thenReturn(true);
    String result = questionController.addQuestion(questionForm, requestContext, false);
    Assert.assertThat(questionForm.getQuestions().size(), is(1));
    Assert.assertThat(result, is("success"));
}
Also used : QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Question(org.mifos.platform.questionnaire.ui.model.Question) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) 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