use of org.neo4j.ogm.domain.social.Individual in project neo4j-ogm by neo4j.
the class ArraysMappingTest method shouldGenerateCypherToPersistByteArray.
@Test
public void shouldGenerateCypherToPersistByteArray() {
Individual individual = new Individual();
individual.setAge(41);
individual.setBankBalance(1000.50f);
individual.setPrimitiveByteArray(new byte[] { 1, 2, 3, 4, 5 });
session.save(individual);
session.clear();
assertThat(session.query("MATCH (i:Individual {age:41, bankBalance: 1000.50, code:0, primitiveByteArray:'AQIDBAU='}) return i", emptyMap()).queryResults()).hasSize(1);
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=");
}
use of org.neo4j.ogm.domain.social.Individual in project neo4j-ogm by neo4j.
the class NumericConversionTest method shouldSaveAndRetrieveNumbers.
/**
* @see DATAGRAPH-600
*/
@Test
public void shouldSaveAndRetrieveNumbers() {
Individual individual = new Individual();
individual.setName("Gary");
individual.setAge(36);
individual.setBankBalance(99.99f);
individual.setCode((byte) 10);
individual.setNumberOfPets(301);
individual.setNumberOfShoes((byte) 101);
individual.setDistanceFromZoo(215.50f);
individual.setFavouriteRadioStations(new Vector<Double>(Arrays.asList(97.4, 105.4, 98.2)));
individual.primitiveFloatArray = new float[] { 5.5f, 6.6f };
individual.setPrimitiveByteArray(new byte[] { 1, 2, 3, 4, 5 });
individual.floatArray = new Float[] { Float.valueOf(1.1f), Float.valueOf(2.2f) };
individual.integerArray = new Integer[] { Integer.valueOf(1000), Integer.valueOf(2000), Integer.valueOf(3000) };
individual.integerCollection = Arrays.asList(Integer.valueOf(100), Integer.valueOf(200));
individual.setFloatCollection(Arrays.asList(Float.valueOf(10.5f), Float.valueOf(20.5f), Float.valueOf(30.5f)));
individual.setByteCollection(Arrays.asList(Byte.valueOf("1"), Byte.valueOf("2")));
session.save(individual);
session.clear();
individual = session.load(Individual.class, individual.getId());
assertThat(individual.getName()).isEqualTo("Gary");
assertThat(individual.getAge()).isEqualTo(36);
assertThat(individual.getBankBalance()).isEqualTo(99.99f, within(0f));
assertThat(individual.getCode()).isEqualTo((byte) 10);
assertThat(individual.getNumberOfPets()).isEqualTo(Integer.valueOf(301));
assertThat(individual.getNumberOfShoes()).isEqualTo(Byte.valueOf((byte) 101));
assertThat(individual.getDistanceFromZoo()).isEqualTo(Float.valueOf(215.50f));
assertThat(individual.getFavouriteRadioStations()).hasSize(3);
assertThat(individual.getFavouriteRadioStations()).contains(97.4, 98.2, 105.4);
assertThat(individual.primitiveFloatArray).hasSize(2);
assertThat(individual.getPrimitiveByteArray()).hasSize(5);
assertThat(individual.floatArray).hasSize(2);
assertThat(individual.integerArray).hasSize(3);
assertThat(individual.integerCollection).hasSize(2);
assertThat(individual.getFloatCollection()).hasSize(3);
assertThat(individual.getByteCollection()).hasSize(2);
}
use of org.neo4j.ogm.domain.social.Individual in project neo4j-ogm by neo4j.
the class NumericConversionTest method shouldLoadDoubleWhenDecimalIsMissing.
// DATAGRAPH-658
@Test
public void shouldLoadDoubleWhenDecimalIsMissing() {
session.query("CREATE (i:Individual {name: 'Gary', maxTemp: 31})", Collections.EMPTY_MAP);
Individual i = session.loadAll(Individual.class).iterator().next();
assertThat(i.getMaxTemp()).isEqualTo(new Double(31));
}
use of org.neo4j.ogm.domain.social.Individual in project neo4j-ogm by neo4j.
the class NumericConversionTest method shouldConvertToLongInsteadOfCasting.
/**
* @see
*/
// DATAGRAPH-840
@Test
public void shouldConvertToLongInsteadOfCasting() {
Individual individual = new Individual();
individual.setLongCollection(Arrays.<Long>asList(1L, 2L, 3L));
session.save(individual);
session.clear();
individual = session.load(Individual.class, individual.getId());
for (Number number : individual.getLongCollection()) {
assertThat(number instanceof Long).isTrue();
}
}
use of org.neo4j.ogm.domain.social.Individual in project neo4j-ogm by neo4j.
the class CompilerTest method createOutgoingRelationWhenUnmarkedRelationIsSpecified.
// DATAGRAPH-594
@Test
public void createOutgoingRelationWhenUnmarkedRelationIsSpecified() {
Individual adam = new Individual();
adam.setName("Adam");
Individual vince = new Individual();
vince.setName("Vince");
adam.setFriends(Collections.singletonList(vince));
Compiler compiler = mapAndCompile(adam, -1);
List<Statement> statements = compiler.createNodesStatements();
assertThat(statements).extracting(Statement::getStatement).containsOnly("UNWIND $rows as row CREATE (n:`Individual`) SET n=row.props RETURN row.nodeRef as ref, ID(n) as id, $type as type");
for (Statement statement : statements) {
List rows = (List) statement.getParameters().get("rows");
assertThat(rows).hasSize(2);
}
statements = compiler.createRelationshipsStatements();
assertThat(statements).extracting(Statement::getStatement).containsOnly("UNWIND $rows as row MATCH (startNode) WHERE ID(startNode) = row.startNodeId WITH row,startNode MATCH (endNode) WHERE ID(endNode) = row.endNodeId MERGE (startNode)-[rel:`FRIENDS`]->(endNode) RETURN row.relRef as ref, ID(rel) as id, $type as type");
List rows = (List) statements.get(0).getParameters().get("rows");
assertThat(rows).hasSize(1);
Map row = (Map) rows.get(0);
assertThat(row.get("startNodeId")).isEqualTo(mappingContext.nativeId(adam));
assertThat(row.get("endNodeId")).isEqualTo(mappingContext.nativeId(vince));
}
Aggregations