Search in sources :

Example 1 with Individual

use of org.neo4j.ogm.domain.social.Individual in project neo4j-ogm by neo4j.

the class EntityGraphMapperTest method shouldGenerateCypherToPersistByteArray.

@Test
public void shouldGenerateCypherToPersistByteArray() {
    sessionFactory = new SessionFactory(getDriver(), "org.neo4j.ogm.domain.social");
    session = sessionFactory.openSession();
    Individual individual = new Individual();
    individual.setAge(41);
    individual.setBankBalance(1000.50f);
    individual.setPrimitiveByteArray(new byte[] { 1, 2, 3, 4, 5 });
    session.save(individual);
    session.query("CREATE (:Individual {age:41, bankBalance: 1000.50, code:0, primitiveByteArray:'AQIDBAU='})", emptyMap());
    session.clear();
    Iterable<Map<String, Object>> executionResult = session.query("MATCH (i:Individual) RETURN i.primitiveByteArray AS bytes", emptyMap()).queryResults();
    Map<String, Object> result = executionResult.iterator().next();
    assertThat(result.get("bytes")).as("The array wasn't persisted as the correct type").isEqualTo(// Byte arrays are converted to Base64 Strings
    "AQIDBAU=");
}
Also used : SessionFactory(org.neo4j.ogm.session.SessionFactory) Individual(org.neo4j.ogm.domain.social.Individual) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with Individual

use of org.neo4j.ogm.domain.social.Individual in project neo4j-ogm by neo4j.

the class EntityGraphMapperTest method shouldGenerateCypherToPersistCollectionOfBoxedPrimitivesToArrayOfPrimitives.

@Test
public void shouldGenerateCypherToPersistCollectionOfBoxedPrimitivesToArrayOfPrimitives() {
    sessionFactory = new SessionFactory(getDriver(), "org.neo4j.ogm.domain.social");
    session = sessionFactory.openSession();
    Individual individual = new Individual();
    individual.setName("Gary");
    individual.setAge(36);
    individual.setBankBalance(99.25f);
    individual.setFavouriteRadioStations(new Vector<>(Arrays.asList(97.4, 105.4, 98.2)));
    session.save(individual);
    session.clear();
    assertThat(session.query("MATCH (a:Individual " + "{name:'Gary', age:36, bankBalance:99.25, code:0, favouriteRadioStations:[97.4, 105.4, 98.2]}) " + "return a", emptyMap()).queryResults()).hasSize(1);
}
Also used : SessionFactory(org.neo4j.ogm.session.SessionFactory) Individual(org.neo4j.ogm.domain.social.Individual) Test(org.junit.Test)

Example 3 with Individual

use of org.neo4j.ogm.domain.social.Individual in project neo4j-ogm by neo4j.

the class EntityGraphMapperTest method shouldGenerateCypherToPersistArraysOfPrimitives.

@Test
public void shouldGenerateCypherToPersistArraysOfPrimitives() {
    sessionFactory = new SessionFactory(getDriver(), "org.neo4j.ogm.domain.social");
    session = sessionFactory.openSession();
    Individual individual = new Individual();
    individual.setName("Jeff");
    individual.setAge(41);
    individual.setBankBalance(1000.50f);
    individual.setPrimitiveIntArray(new int[] { 1, 6, 4, 7, 2 });
    session.save(individual);
    session.clear();
    Individual loadedIndividual = session.load(Individual.class, individual.getId());
    assertThat(loadedIndividual.getPrimitiveIntArray()).isEqualTo(individual.getPrimitiveIntArray());
}
Also used : SessionFactory(org.neo4j.ogm.session.SessionFactory) Individual(org.neo4j.ogm.domain.social.Individual) Test(org.junit.Test)

Example 4 with Individual

use of org.neo4j.ogm.domain.social.Individual in project neo4j-ogm by neo4j.

the class SocialIntegrationTest method shouldFetchFriendsInBothDirections.

/**
 * @see DATAGRAPH-594
 */
@Test
public void shouldFetchFriendsInBothDirections() {
    session.query("create (p1:Individual {name:'A'}) create (p2:Individual {name:'B'}) create (p3:Individual {name:'C'})" + " create (p4:Individual {name:'D'}) create (p1)-[:FRIENDS]->(p2) create (p1)-[:FRIENDS]->(p3) create (p4)-[:FRIENDS]->(p1)", Collections.EMPTY_MAP);
    Individual individualA = session.loadAll(Individual.class, new Filter("name", ComparisonOperator.EQUALS, "A")).iterator().next();
    assertThat(individualA).isNotNull();
    assertThat(individualA.getFriends()).hasSize(2);
}
Also used : Filter(org.neo4j.ogm.cypher.Filter) Individual(org.neo4j.ogm.domain.social.Individual) Test(org.junit.Test)

Example 5 with Individual

use of org.neo4j.ogm.domain.social.Individual in project neo4j-ogm by neo4j.

the class ArraysMappingTest method shouldGenerateCypherToPersistArraysOfPrimitives.

@Test
public void shouldGenerateCypherToPersistArraysOfPrimitives() {
    Individual individual = new Individual();
    individual.setName("Jeff");
    individual.setAge(41);
    individual.setBankBalance(1000.50f);
    individual.setPrimitiveIntArray(new int[] { 1, 6, 4, 7, 2 });
    session.save(individual);
    session.clear();
    assertThat(session.query("MATCH (i:Individual {name:'Jeff', age:41, bankBalance: 1000.50, code:0, primitiveIntArray:[1,6,4,7,2]}) " + "return i", emptyMap()).queryResults()).hasSize(1);
    session.clear();
    Individual loadedIndividual = session.load(Individual.class, individual.getId());
    assertThat(loadedIndividual.getPrimitiveIntArray()).isEqualTo(individual.getPrimitiveIntArray());
}
Also used : Individual(org.neo4j.ogm.domain.social.Individual) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 Individual (org.neo4j.ogm.domain.social.Individual)16 Map (java.util.Map)3 SessionFactory (org.neo4j.ogm.session.SessionFactory)3 HashMap (java.util.HashMap)2 NodeModel (org.neo4j.ogm.response.model.NodeModel)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Filter (org.neo4j.ogm.cypher.Filter)1 Statement (org.neo4j.ogm.request.Statement)1 Session (org.neo4j.ogm.session.Session)1