private void setPropertyAndAssertIt( Node node, Object value ) { node.setProperty( "key", value ); assertEquals( value, node.getProperty( "key" ) ); }
@Test public void testEmptyString() { Node node = getGraphDb().createNode(); node.setProperty( "1", 2 ); node.setProperty( "2", "" ); node.setProperty( "3", "" ); newTransaction(); assertEquals( 2, node.getProperty( "1" ) ); assertEquals( "", node.getProperty( "2" ) ); assertEquals( "", node.getProperty( "3" ) ); }
protected void assertPath( Path path, Node... nodes ) { int i = 0; for ( Node node : path.nodes() ) { assertEquals( "Wrong node " + i + " in " + getPathDef( path ), nodes[i++].getProperty( SimpleGraphBuilder.KEY_ID ), node.getProperty( SimpleGraphBuilder.KEY_ID ) ); } assertEquals( nodes.length, i ); }
@Test public void shouldNotFailSettingEmptyArrayAndOtherValuesIfEntityAlreadyHasAnEmptyArrayAsValue() throws Exception { // Given Node node = db.createNode(); node.setProperty( "arr", new String[]{} ); Map<String, Object> props = new HashMap<>(); props.put( "name", "bob" ); props.put( "arr", new ArrayList<String>( ) ); // When propSetter.setProperties( node, props ); // Then assertThat( node.getProperty( "name" ), is("bob")); assertThat( node.getProperty( "arr" ), is(new String[]{})); }
@Test public void testPropertyStoreReferencesOnRead() throws Throwable { // Given GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); // and Given the cache contains a LazyProperty long nId = ensurePropertyIsCachedLazyProperty( db, "some" ); // When restartNeoDataSource( db ); // Then reading the property is still possible try ( Transaction tx = db.beginTx() ) { db.getNodeById( nId ).getProperty( "some" ); tx.success(); } }
@Test public void shouldBeAbleToMakeRepeatedCallsToSetNodePropertyWithMultiplePropertiesPerBlock() throws Exception { File file = dbRule.databaseLayout().databaseDirectory(); BatchInserter inserter = BatchInserters.inserter( file, fileSystemRule.get() ); long nodeId = inserter.createNode( Collections.emptyMap() ); final Object finalValue1 = 87; final Object finalValue2 = 3.14; inserter.setNodeProperty( nodeId, "a", "some property value" ); inserter.setNodeProperty( nodeId, "a", 42 ); inserter.setNodeProperty( nodeId, "b", finalValue2 ); inserter.setNodeProperty( nodeId, "a", finalValue2 ); inserter.setNodeProperty( nodeId, "a", true ); inserter.setNodeProperty( nodeId, "a", finalValue1 ); inserter.shutdown(); GraphDatabaseService db = dbRule.getGraphDatabaseAPI(); try ( Transaction ignored = db.beginTx() ) { assertThat( db.getNodeById( nodeId ).getProperty( "a" ), equalTo( finalValue1 ) ); assertThat( db.getNodeById( nodeId ).getProperty( "b" ), equalTo( finalValue2 ) ); } finally { db.shutdown(); } }
@Test public void shouldSetSingleProperty() throws Exception { // Given Node node = db.createNode(); // When propSetter.setProperty( node, "name", "bob" ); // Then assertThat( node.getProperty( "name" ), is("bob")); }
private void assertOrder( Iterator<Node> itr, String... names ) { try ( Transaction tx = beginTx() ) { for ( String name : names ) { Node node = itr.next(); assertEquals( "expected " + name + ", was " + node.getProperty( "name" ), getNodeWithName( name ), node ); } assertFalse( itr.hasNext() ); tx.success(); } } }
@Graph( value = { "I know you" }, nodes = { @NODE( name = "I", properties = { @PROP( key = "name", value = "me" ) } ) } ) private void verifyIKnowYou( String type, String myName ) { try ( Transaction ignored = graphdb.beginTx() ) { Map<String, Node> graph = data.get(); assertEquals( "Wrong graph size.", 2, graph.size() ); Node iNode = graph.get( "I" ); assertNotNull( "The node 'I' was not defined", iNode ); Node you = graph.get( "you" ); assertNotNull( "The node 'you' was not defined", you ); assertEquals( "'I' has wrong 'name'.", myName, iNode.getProperty( "name" ) ); assertEquals( "'you' has wrong 'name'.", "you", you.getProperty( "name" ) ); Iterator<Relationship> rels = iNode.getRelationships().iterator(); assertTrue( "'I' has too few relationships", rels.hasNext() ); Relationship rel = rels.next(); assertEquals( "'I' is not related to 'you'", you, rel.getOtherNode( iNode ) ); assertEquals( "Wrong relationship type.", type, rel.getType().name() ); assertFalse( "'I' has too many relationships", rels.hasNext() ); rels = you.getRelationships().iterator(); assertTrue( "'you' has too few relationships", rels.hasNext() ); rel = rels.next(); assertEquals( "'you' is not related to 'i'", iNode, rel.getOtherNode( you ) ); assertEquals( "Wrong relationship type.", type, rel.getType().name() ); assertFalse( "'you' has too many relationships", rels.hasNext() ); assertEquals( "wrong direction", iNode, rel.getStartNode() ); } }
private static void nodesWithPersonLabelHaveUniqueName( GraphDatabaseService db ) { try ( Transaction tx = db.beginTx() ) { try ( ResourceIterator<Node> person = db.findNodes( label( "Person" ) ) ) { Set<Object> names = new HashSet<>(); while ( person.hasNext() ) { Object name = person.next().getProperty( "name", null ); if ( name != null ) { assertTrue( "non-unique name: " + name, names.add( name ) ); } } } tx.success(); } }
private void assertProperty( long node, String propertyKey, Object value ) { try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() ) { assertThat( graphDb.getNodeById( node ).getProperty( propertyKey ), equalTo( value ) ); } } }
@Test public void testSetWithSameValue() { Node node = getGraphDb().createNode(); node.setProperty( "rev_pos", "40000633e7ad67ff" ); assertEquals( "40000633e7ad67ff", node.getProperty( "rev_pos" ) ); newTransaction(); node.setProperty( "rev_pos", "40000633e7ad67ef" ); assertEquals( "40000633e7ad67ef", node.getProperty( "rev_pos" ) ); }
@Test public void shouldUseOriginalTypeWhenSettingEmptyArrayIfEntityAlreadyHasACollection() throws Exception { // Given Node node = db.createNode(); node.setProperty( "arr", new String[]{"a","b"} ); // When propSetter.setProperty( node, "arr", new ArrayList<>() ); // Then assertThat( node.getProperty( "arr" ), is(new String[]{})); }
protected void assertPathDef( Path path, String... names ) { int i = 0; for ( Node node : path.nodes() ) { assertEquals( "Wrong node " + i + " in " + getPathDef( path ), names[i++], node.getProperty( SimpleGraphBuilder.KEY_ID ) ); } assertEquals( names.length, i ); }
@Test public void testMaxDepthAndCustomPruneEvaluatorCombined() { Evaluator lessThanThreeRels = path -> count( path.endNode().getRelationships( Direction.OUTGOING ).iterator() ) < 3 ? Evaluation.INCLUDE_AND_PRUNE : Evaluation.INCLUDE_AND_CONTINUE; TraversalDescription description = getGraphDb().traversalDescription().evaluator( Evaluators.all() ) .evaluator( toDepth( 1 ) ).evaluator( lessThanThreeRels ); Set<String> expectedNodes = new HashSet<>( asList( "a", "b", "c", "d", "e" ) ); try ( Transaction tx = beginTx() ) { for ( Path position : description.traverse( node( "a" ) ) ) { String name = (String) position.endNode().getProperty( "name" ); assertTrue( name + " shouldn't have been returned", expectedNodes.remove( name ) ); } tx.success(); } assertTrue( expectedNodes.isEmpty() ); } }
@Test public void shouldBeAbleToMakeRepeatedCallsToSetNodeProperty() throws Exception { File file = dbRule.databaseLayout().databaseDirectory(); BatchInserter inserter = BatchInserters.inserter( file, fileSystemRule.get() ); long nodeId = inserter.createNode( Collections.emptyMap() ); final Object finalValue = 87; inserter.setNodeProperty( nodeId, "a", "some property value" ); inserter.setNodeProperty( nodeId, "a", 42 ); inserter.setNodeProperty( nodeId, "a", 3.14 ); inserter.setNodeProperty( nodeId, "a", true ); inserter.setNodeProperty( nodeId, "a", finalValue ); inserter.shutdown(); GraphDatabaseService db = dbRule.getGraphDatabaseAPI(); try ( Transaction ignored = db.beginTx() ) { assertThat( db.getNodeById( nodeId ).getProperty( "a" ), equalTo( finalValue ) ); } finally { db.shutdown(); } }
private void testDateTypeWithPrecedingInLinedLong( Value value ) { node1.setProperty( "l1", 255 ); // Setting these low bits was triggering a bug in some date types decision on formatting String key = "dt"; node1.setProperty( key, value ); newTransaction(); Object property = node1.getProperty( key ); assertEquals( value.asObjectCopy(), property ); }
private void assertNodeHasBeenUpdated( final Node commonNode ) throws Exception { final Collection<Exception> problems = new HashSet<>(); Thread thread = new Thread( () -> { try ( Transaction ignored = graphDatabaseService.beginTx() ) { assertThat( commonNode.getProperty( PROPERTY_NAME ), is( PROPERTY_VALUE ) ); } catch ( Throwable t ) { problems.add( new Exception( t ) ); } } ); thread.start(); thread.join(); if ( problems.size() > 0 ) { throw problems.iterator().next(); } } }
@Test public void testPointTypeWithTwoOtherProperties() { Point point = Values.pointValue( CoordinateReferenceSystem.Cartesian, 1, 1 ); String key = "location"; node1.setProperty( "prop1", 1 ); node1.setProperty( "prop2", 2 ); node1.setProperty( key, point ); newTransaction(); Object property = node1.getProperty( key ); assertEquals( point, property ); }
@Test public void shouldNotFailSettingEmptyArrayIfEntityAlreadyHasAnEmptyArrayAsValue() throws Exception { // Given Node node = db.createNode(); node.setProperty( "arr", new String[]{} ); // When propSetter.setProperty( node, "arr", new ArrayList<>() ); // Then assertThat( node.getProperty( "arr" ), is(new String[]{})); }