Search in sources :

Example 1 with Education

use of org.neo4j.ogm.domain.convertible.enums.Education in project neo4j-ogm by neo4j.

the class ConvertibleIntegrationTest method shouldSaveAndRetrieveEnums.

// DATAGRAPH-550
@Test
public void shouldSaveAndRetrieveEnums() {
    List<Education> completed = new ArrayList<>();
    completed.add(Education.HIGHSCHOOL);
    completed.add(Education.BACHELORS);
    Person person = new Person();
    person.setName("luanne");
    person.setInProgressEducation(new Education[] { Education.MASTERS, Education.PHD });
    person.setCompletedEducation(completed);
    person.setGender(Gender.FEMALE);
    session.save(person);
    Person luanne = session.loadAll(Person.class, new Filter("name", ComparisonOperator.EQUALS, "luanne")).iterator().next();
    assertThat(luanne.getGender()).isEqualTo(Gender.FEMALE);
    assertThat(luanne.getCompletedEducation().contains(Education.HIGHSCHOOL)).isTrue();
    assertThat(luanne.getCompletedEducation().contains(Education.BACHELORS)).isTrue();
    assertThat(luanne.getInProgressEducation().length).isEqualTo(2);
    assertThat(luanne.getInProgressEducation()[0].equals(Education.MASTERS) || luanne.getInProgressEducation()[1].equals(Education.MASTERS)).isTrue();
    assertThat(luanne.getInProgressEducation()[0].equals(Education.PHD) || luanne.getInProgressEducation()[1].equals(Education.PHD)).isTrue();
}
Also used : Education(org.neo4j.ogm.domain.convertible.enums.Education) Filter(org.neo4j.ogm.cypher.Filter) Person(org.neo4j.ogm.domain.convertible.enums.Person) Test(org.junit.Test)

Example 2 with Education

use of org.neo4j.ogm.domain.convertible.enums.Education in project neo4j-ogm by neo4j.

the class ConvertibleIntegrationTest method shouldSaveAndRetrieveEnumsAsResult.

@Test
public void shouldSaveAndRetrieveEnumsAsResult() {
    List<Education> completed = new ArrayList<>();
    completed.add(Education.HIGHSCHOOL);
    completed.add(Education.BACHELORS);
    Person person = new Person();
    person.setName("luanne");
    person.setInProgressEducation(new Education[] { Education.MASTERS, Education.PHD });
    person.setCompletedEducation(completed);
    person.setGender(Gender.FEMALE);
    session.save(person);
    session.clear();
    Result res = session.query("MATCH (p:Person{name:'luanne'}) return p", Collections.EMPTY_MAP);
    Person luanne = (Person) res.queryResults().iterator().next().get("p");
    assertThat(luanne.getGender()).isEqualTo(Gender.FEMALE);
    assertThat(luanne.getCompletedEducation().contains(Education.HIGHSCHOOL)).isTrue();
    assertThat(luanne.getCompletedEducation().contains(Education.BACHELORS)).isTrue();
    assertThat(luanne.getInProgressEducation().length).isEqualTo(2);
    assertThat(luanne.getInProgressEducation()[0].equals(Education.MASTERS) || luanne.getInProgressEducation()[1].equals(Education.MASTERS)).isTrue();
    assertThat(luanne.getInProgressEducation()[0].equals(Education.PHD) || luanne.getInProgressEducation()[1].equals(Education.PHD)).isTrue();
}
Also used : Education(org.neo4j.ogm.domain.convertible.enums.Education) Person(org.neo4j.ogm.domain.convertible.enums.Person) Result(org.neo4j.ogm.model.Result) Test(org.junit.Test)

Example 3 with Education

use of org.neo4j.ogm.domain.convertible.enums.Education in project neo4j-ogm by neo4j.

the class EnumConversionTest method testEducationCollectionFieldWithAutoDetectedConverter.

/**
 * @see DATAGRAPH-550
 */
@Test
public void testEducationCollectionFieldWithAutoDetectedConverter() {
    List<Education> completedEducation = new ArrayList<>();
    completedEducation.add(Education.HIGHSCHOOL);
    completedEducation.add(Education.BACHELORS);
    Person bob = new Person();
    bob.setCompletedEducation(completedEducation);
    FieldInfo fieldInfo = personInfo.propertyField("completedEducation");
    assertThat(fieldInfo.hasPropertyConverter()).isTrue();
    String[] converted = (String[]) fieldInfo.getPropertyConverter().toGraphProperty(bob.getCompletedEducation());
    assertThat("HIGHSCHOOL".equals(converted[0]) || "HIGHSCHOOL".equals(converted[1])).isTrue();
    assertThat("BACHELORS".equals(converted[0]) || "BACHELORS".equals(converted[1])).isTrue();
}
Also used : Education(org.neo4j.ogm.domain.convertible.enums.Education) ArrayList(java.util.ArrayList) Person(org.neo4j.ogm.domain.convertible.enums.Person) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) Test(org.junit.Test)

Example 4 with Education

use of org.neo4j.ogm.domain.convertible.enums.Education in project neo4j-ogm by neo4j.

the class EnumConversionTest method testEducationArrayFieldWithAutoDetectedConverter.

/**
 * @see DATAGRAPH-550
 */
@Test
public void testEducationArrayFieldWithAutoDetectedConverter() {
    Person bob = new Person();
    bob.setGender(Gender.MALE);
    Education[] inProgress = new Education[] { Education.MASTERS, Education.PHD };
    bob.setInProgressEducation(inProgress);
    FieldInfo fieldInfo = personInfo.propertyField("inProgressEducation");
    assertThat(fieldInfo.hasPropertyConverter()).isTrue();
    String[] converted = (String[]) fieldInfo.getPropertyConverter().toGraphProperty(bob.getInProgressEducation());
    assertThat("MASTERS".equals(converted[0]) || "MASTERS".equals(converted[1])).isTrue();
    assertThat("PHD".equals(converted[0]) || "PHD".equals(converted[1])).isTrue();
}
Also used : Education(org.neo4j.ogm.domain.convertible.enums.Education) Person(org.neo4j.ogm.domain.convertible.enums.Person) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 Education (org.neo4j.ogm.domain.convertible.enums.Education)4 Person (org.neo4j.ogm.domain.convertible.enums.Person)4 FieldInfo (org.neo4j.ogm.metadata.FieldInfo)2 ArrayList (java.util.ArrayList)1 Filter (org.neo4j.ogm.cypher.Filter)1 Result (org.neo4j.ogm.model.Result)1