Search in sources :

Example 1 with EnumeratorQuestionDefinition

use of services.question.types.EnumeratorQuestionDefinition in project civiform by seattle-uat.

the class JsonPathPredicateGeneratorTest method fromLeafNode_predicateBasedOnSiblingRepeatedQuestion_generatesCorrectPath.

@Test
public void fromLeafNode_predicateBasedOnSiblingRepeatedQuestion_generatesCorrectPath() throws Exception {
    ApplicantData applicantData = new ApplicantData();
    EnumeratorQuestionDefinition enumerator = (EnumeratorQuestionDefinition) questionBank.applicantHouseholdMembers().getQuestionDefinition();
    QuestionDefinition siblingQuestion = new QuestionDefinitionBuilder(questionBank.applicantHouseholdMemberName().getQuestionDefinition()).setEnumeratorId(Optional.of(enumerator.getId())).build();
    // Put an entity at the enumerator path so we can generate repeated contexts.
    ApplicantQuestion applicantEnumerator = new ApplicantQuestion(enumerator, applicantData, Optional.empty());
    applicantData.putRepeatedEntities(applicantEnumerator.getContextualizedPath(), ImmutableList.of("Bernard", "Alice"));
    // Just use a repeated entity for the first (index 0) entity.
    ImmutableList<RepeatedEntity> repeatedEntities = RepeatedEntity.createRepeatedEntities(enumerator, Optional.empty(), applicantData);
    Optional<RepeatedEntity> repeatedEntity = repeatedEntities.stream().findFirst();
    generator = new JsonPathPredicateGenerator(ImmutableList.of(enumerator, siblingQuestion), repeatedEntity);
    LeafOperationExpressionNode node = LeafOperationExpressionNode.create(// The predicate is based on the sibling "name" question.
    siblingQuestion.getId(), Scalar.FIRST_NAME, Operator.EQUAL_TO, PredicateValue.of("Bernard"));
    assertThat(generator.fromLeafNode(node)).isEqualTo(JsonPathPredicate.create("$.applicant.applicant_household_members[0].household_members_name" + "[?(@.first_name == \"Bernard\")]"));
}
Also used : RepeatedEntity(services.applicant.RepeatedEntity) EnumeratorQuestionDefinition(services.question.types.EnumeratorQuestionDefinition) QuestionDefinition(services.question.types.QuestionDefinition) QuestionDefinitionBuilder(services.question.types.QuestionDefinitionBuilder) EnumeratorQuestionDefinition(services.question.types.EnumeratorQuestionDefinition) ApplicantData(services.applicant.ApplicantData) LeafOperationExpressionNode(services.program.predicate.LeafOperationExpressionNode) ApplicantQuestion(services.applicant.question.ApplicantQuestion) Test(org.junit.Test)

Example 2 with EnumeratorQuestionDefinition

use of services.question.types.EnumeratorQuestionDefinition in project civiform by seattle-uat.

the class ApplicantQuestionTest method questionTextAndHelpText_areContextualizedByRepeatedEntity.

@Test
public void questionTextAndHelpText_areContextualizedByRepeatedEntity() {
    ApplicantData applicantData = new ApplicantData();
    Path householdMembersPath = ApplicantData.APPLICANT_PATH.join(testQuestionBank.applicantHouseholdMembers().getQuestionDefinition().getQuestionPathSegment());
    QuestionAnswerer.answerEnumeratorQuestion(applicantData, householdMembersPath, ImmutableList.of("Jonathan"));
    Path householdMembersJobsPath = householdMembersPath.atIndex(0).join(testQuestionBank.applicantHouseholdMemberJobs().getQuestionDefinition().getQuestionPathSegment());
    QuestionAnswerer.answerEnumeratorQuestion(applicantData, householdMembersJobsPath, ImmutableList.of("JonCo"));
    RepeatedEntity jonathan = RepeatedEntity.createRepeatedEntities((EnumeratorQuestionDefinition) testQuestionBank.applicantHouseholdMembers().getQuestionDefinition(), Optional.empty(), applicantData).get(0);
    RepeatedEntity jonCo = jonathan.createNestedRepeatedEntities((EnumeratorQuestionDefinition) testQuestionBank.applicantHouseholdMemberJobs().getQuestionDefinition(), Optional.empty(), applicantData).get(0);
    ApplicantQuestion applicantQuestion = new ApplicantQuestion(testQuestionBank.applicantHouseholdMemberDaysWorked().getQuestionDefinition(), applicantData, Optional.of(jonCo));
    assertThat(applicantQuestion.getQuestionText()).isEqualTo("How many days has Jonathan worked at JonCo?");
    assertThat(applicantQuestion.getQuestionHelpText()).isEqualTo("How many days has Jonathan worked at JonCo?");
}
Also used : Path(services.Path) RepeatedEntity(services.applicant.RepeatedEntity) EnumeratorQuestionDefinition(services.question.types.EnumeratorQuestionDefinition) ApplicantData(services.applicant.ApplicantData) Test(org.junit.Test)

Example 3 with EnumeratorQuestionDefinition

use of services.question.types.EnumeratorQuestionDefinition 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 4 with EnumeratorQuestionDefinition

use of services.question.types.EnumeratorQuestionDefinition in project civiform by seattle-uat.

the class EnumeratorQuestionTranslationFormTest method buildsQuestion_newLocale_savesUpdates.

@Test
public void buildsQuestion_newLocale_savesUpdates() throws Exception {
    QuestionDefinition question = new EnumeratorQuestionDefinition("test", Optional.empty(), "desc", LocalizedStrings.withDefaultValue("existing"), LocalizedStrings.withDefaultValue("existing"), LocalizedStrings.withDefaultValue("existing"));
    EnumeratorQuestionTranslationForm form = new EnumeratorQuestionTranslationForm();
    form.setQuestionText("Canadian question text");
    form.setEntityType("Canadian English");
    EnumeratorQuestionDefinition updated = (EnumeratorQuestionDefinition) form.builderWithUpdates(question, Locale.CANADA).build();
    assertThat(updated.getEntityType()).isEqualTo(LocalizedStrings.of(Locale.US, "existing", Locale.CANADA, "Canadian English"));
    assertThat(updated.getQuestionText()).isEqualTo(LocalizedStrings.of(Locale.US, "existing", Locale.CANADA, "Canadian question text"));
}
Also used : EnumeratorQuestionDefinition(services.question.types.EnumeratorQuestionDefinition) QuestionDefinition(services.question.types.QuestionDefinition) EnumeratorQuestionDefinition(services.question.types.EnumeratorQuestionDefinition) Test(org.junit.Test)

Example 5 with EnumeratorQuestionDefinition

use of services.question.types.EnumeratorQuestionDefinition in project civiform by seattle-uat.

the class EnumeratorQuestionFormTest method getBuilder_returnsCompleteBuilder.

@Test
public void getBuilder_returnsCompleteBuilder() throws Exception {
    EnumeratorQuestionForm form = new EnumeratorQuestionForm();
    form.setQuestionName("name");
    form.setQuestionDescription("description");
    form.setQuestionText("What is the question text?");
    form.setQuestionHelpText("");
    QuestionDefinitionBuilder builder = form.getBuilder();
    EnumeratorQuestionDefinition expected = new EnumeratorQuestionDefinition("name", Optional.empty(), "description", LocalizedStrings.of(Locale.US, "What is the question text?"), LocalizedStrings.empty(), LocalizedStrings.empty());
    QuestionDefinition actual = builder.build();
    assertThat(actual).isEqualTo(expected);
}
Also used : EnumeratorQuestionDefinition(services.question.types.EnumeratorQuestionDefinition) QuestionDefinition(services.question.types.QuestionDefinition) QuestionDefinitionBuilder(services.question.types.QuestionDefinitionBuilder) EnumeratorQuestionDefinition(services.question.types.EnumeratorQuestionDefinition) Test(org.junit.Test)

Aggregations

EnumeratorQuestionDefinition (services.question.types.EnumeratorQuestionDefinition)16 QuestionDefinition (services.question.types.QuestionDefinition)12 Test (org.junit.Test)11 ApplicantData (services.applicant.ApplicantData)6 QuestionDefinitionBuilder (services.question.types.QuestionDefinitionBuilder)6 RepeatedEntity (services.applicant.RepeatedEntity)5 ApplicantQuestion (services.applicant.question.ApplicantQuestion)5 LeafOperationExpressionNode (services.program.predicate.LeafOperationExpressionNode)4 Path (services.Path)3 MultiOptionQuestionDefinition (services.question.types.MultiOptionQuestionDefinition)3 Secure (org.pac4j.play.java.Secure)2 LocalizedStrings (services.LocalizedStrings)2 AddressQuestionDefinition (services.question.types.AddressQuestionDefinition)2 TextQuestionDefinition (services.question.types.TextQuestionDefinition)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 EnumeratorQuestionForm (forms.EnumeratorQuestionForm)1 MultiOptionQuestionForm (forms.MultiOptionQuestionForm)1