Search in sources :

Example 1 with QuestionDefinitionBuilder

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);
}
Also used : EnumeratorQuestionDefinition(services.question.types.EnumeratorQuestionDefinition) QuestionDefinition(services.question.types.QuestionDefinition) AddressQuestionDefinition(services.question.types.AddressQuestionDefinition) TextQuestionDefinition(services.question.types.TextQuestionDefinition) MultiOptionQuestionDefinition(services.question.types.MultiOptionQuestionDefinition) QuestionDefinitionBuilder(services.question.types.QuestionDefinitionBuilder) EnumeratorQuestionDefinition(services.question.types.EnumeratorQuestionDefinition) LocalizedStrings(services.LocalizedStrings) Test(org.junit.Test)

Example 2 with QuestionDefinitionBuilder

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());
}
Also used : TextQuestionDefinition(services.question.types.TextQuestionDefinition) EnumeratorQuestionDefinition(services.question.types.EnumeratorQuestionDefinition) QuestionDefinition(services.question.types.QuestionDefinition) AddressQuestionDefinition(services.question.types.AddressQuestionDefinition) TextQuestionDefinition(services.question.types.TextQuestionDefinition) MultiOptionQuestionDefinition(services.question.types.MultiOptionQuestionDefinition) QuestionDefinitionBuilder(services.question.types.QuestionDefinitionBuilder) Test(org.junit.Test)

Example 3 with QuestionDefinitionBuilder

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);
}
Also used : EnumeratorQuestionDefinition(services.question.types.EnumeratorQuestionDefinition) QuestionDefinition(services.question.types.QuestionDefinition) AddressQuestionDefinition(services.question.types.AddressQuestionDefinition) TextQuestionDefinition(services.question.types.TextQuestionDefinition) MultiOptionQuestionDefinition(services.question.types.MultiOptionQuestionDefinition) QuestionDefinitionBuilder(services.question.types.QuestionDefinitionBuilder) MultiOptionQuestionDefinition(services.question.types.MultiOptionQuestionDefinition) Test(org.junit.Test)

Example 4 with QuestionDefinitionBuilder

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);
}
Also used : QuestionDefinition(services.question.types.QuestionDefinition) NameQuestionDefinition(services.question.types.NameQuestionDefinition) NameQuestionDefinition(services.question.types.NameQuestionDefinition) QuestionDefinitionBuilder(services.question.types.QuestionDefinitionBuilder) Test(org.junit.Test)

Example 5 with QuestionDefinitionBuilder

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);
}
Also used : NumberQuestionDefinition(services.question.types.NumberQuestionDefinition) QuestionDefinition(services.question.types.QuestionDefinition) QuestionDefinitionBuilder(services.question.types.QuestionDefinitionBuilder) NumberQuestionDefinition(services.question.types.NumberQuestionDefinition) Test(org.junit.Test)

Aggregations

QuestionDefinitionBuilder (services.question.types.QuestionDefinitionBuilder)56 Test (org.junit.Test)49 QuestionDefinition (services.question.types.QuestionDefinition)44 TextQuestionDefinition (services.question.types.TextQuestionDefinition)17 EnumeratorQuestionDefinition (services.question.types.EnumeratorQuestionDefinition)10 Question (models.Question)9 MultiOptionQuestionDefinition (services.question.types.MultiOptionQuestionDefinition)9 AddressQuestionDefinition (services.question.types.AddressQuestionDefinition)7 LocalizedStrings (services.LocalizedStrings)5 CheckboxQuestionDefinition (services.question.types.CheckboxQuestionDefinition)4 NameQuestionDefinition (services.question.types.NameQuestionDefinition)4 ImmutableList (com.google.common.collect.ImmutableList)3 CiviFormError (services.CiviFormError)3 BlockDefinition (services.program.BlockDefinition)3 ProgramDefinition (services.program.ProgramDefinition)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Optional (java.util.Optional)2 PostLoad (javax.persistence.PostLoad)2 PostPersist (javax.persistence.PostPersist)2