use of services.question.types.QuestionDefinitionBuilder in project civiform by seattle-uat.
the class QuestionTest method canSerializeAndDeserializeEnumeratorQuestion.
@Test
public void canSerializeAndDeserializeEnumeratorQuestion() throws UnsupportedQuestionTypeException {
LocalizedStrings entityType = LocalizedStrings.of(Locale.US, "entity");
QuestionDefinition definition = new QuestionDefinitionBuilder().setQuestionType(QuestionType.ENUMERATOR).setName("").setDescription("").setEnumeratorId(Optional.of(123L)).setQuestionText(LocalizedStrings.of()).setQuestionHelpText(LocalizedStrings.empty()).setEntityType(entityType).build();
Question question = new Question(definition);
question.save();
Question found = repo.lookupQuestion(question.id).toCompletableFuture().join().get();
assertThat(found.getQuestionDefinition().getQuestionType()).isEqualTo(QuestionType.ENUMERATOR);
EnumeratorQuestionDefinition enumerator = (EnumeratorQuestionDefinition) found.getQuestionDefinition();
assertThat(enumerator.getEntityType()).isEqualTo(entityType);
}
use of services.question.types.QuestionDefinitionBuilder in project civiform by seattle-uat.
the class QuestionTest method canSaveQuestion.
@Test
public void canSaveQuestion() throws UnsupportedQuestionTypeException {
QuestionDefinition definition = new TextQuestionDefinition("test", Optional.empty(), "", LocalizedStrings.of(), LocalizedStrings.empty());
Question question = new Question(definition);
question.save();
Question found = repo.lookupQuestion(question.id).toCompletableFuture().join().get();
QuestionDefinition expected = new QuestionDefinitionBuilder(definition).setId(question.id).build();
assertEquals(expected, found.getQuestionDefinition());
}
use of services.question.types.QuestionDefinitionBuilder in project civiform by seattle-uat.
the class QuestionTest method canSerializeAndDeserializeMultiOptionQuestion.
@Test
public void canSerializeAndDeserializeMultiOptionQuestion() throws UnsupportedQuestionTypeException {
QuestionDefinition definition = new QuestionDefinitionBuilder().setQuestionType(QuestionType.DROPDOWN).setName("").setDescription("").setEnumeratorId(Optional.of(123L)).setQuestionText(LocalizedStrings.of()).setQuestionHelpText(LocalizedStrings.empty()).setQuestionOptions(ImmutableList.of(QuestionOption.create(1L, LocalizedStrings.of(Locale.US, "option")))).build();
Question question = new Question(definition);
question.save();
Question found = repo.lookupQuestion(question.id).toCompletableFuture().join().get();
assertThat(found.getQuestionDefinition().getQuestionType().isMultiOptionType()).isTrue();
MultiOptionQuestionDefinition multiOption = (MultiOptionQuestionDefinition) found.getQuestionDefinition();
assertThat(multiOption.getOptions()).isEqualTo(ImmutableList.of(QuestionOption.create(1L, LocalizedStrings.of(Locale.US, "option"))));
assertThat(multiOption.getEnumeratorId()).hasValue(123L);
}
use of services.question.types.QuestionDefinitionBuilder in project civiform by seattle-uat.
the class NameQuestionFormTest method getBuilder_withQdConstructor_returnsCompleteBuilder.
@Test
public void getBuilder_withQdConstructor_returnsCompleteBuilder() throws Exception {
NameQuestionDefinition originalQd = new NameQuestionDefinition("name", Optional.empty(), "description", LocalizedStrings.of(Locale.US, "What is the question text?"), LocalizedStrings.empty());
NameQuestionForm form = new NameQuestionForm(originalQd);
QuestionDefinitionBuilder builder = form.getBuilder();
QuestionDefinition actual = builder.build();
assertThat(actual).isEqualTo(originalQd);
}
use of services.question.types.QuestionDefinitionBuilder in project civiform by seattle-uat.
the class NumberQuestionFormTest method getBuilder_returnsCompleteBuilder.
@Test
public void getBuilder_returnsCompleteBuilder() throws Exception {
NumberQuestionForm form = new NumberQuestionForm();
form.setQuestionName("name");
form.setQuestionDescription("description");
form.setQuestionText("What is the question text?");
form.setQuestionHelpText("");
form.setMin("2");
form.setMax("8");
QuestionDefinitionBuilder builder = form.getBuilder();
NumberQuestionDefinition expected = new NumberQuestionDefinition("name", Optional.empty(), "description", LocalizedStrings.of(Locale.US, "What is the question text?"), LocalizedStrings.empty(), NumberQuestionDefinition.NumberValidationPredicates.create(2, 8));
QuestionDefinition actual = builder.build();
assertThat(actual).isEqualTo(expected);
}
Aggregations