private Node createNode( Label... labels ) { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode( labels ); tx.success(); return node; } }
@Test( expected = PropertyValueException.class ) public void shouldThrowPropertyErrorWhenSettingEmptyArrayOnEntityWithNoPreExistingProperty() throws Exception { // Given Node node = db.createNode(); // When propSetter.setProperty( node, "arr", new ArrayList<>() ); }
@Test public void indexCreationConfigRaceCondition() throws Exception try ( Transaction tx = db.beginTx() ) Node node = db.createNode(); index.add( node, "name", "Name" ); tx.success();
@Test public void shouldWarnOnLargeLabelScansWithLoadCVSMatch() { for ( int i = 0; i < 11; i++ ) { try ( Transaction tx = db().beginTx() ) { db().createNode().addLabel( label( "A" ) ); tx.success(); } } Stream.of( "CYPHER 3.1", "CYPHER 3.5" ).forEach( version -> assertNotifications( version + "EXPLAIN LOAD CSV FROM 'file:///ignore/ignore.csv' AS line MATCH (a:A) RETURN *", containsNoItem( largeLabelCSVWarning ) ) ); }
@Test( expected = PropertyValueException.class ) public void shouldThrowPropertyErrorWhenSettingEmptyArrayOnEntityWithNoPreExistingEmptyArray() throws Exception { // Given Node node = db.createNode(); node.setProperty( "arr", "hello" ); // When propSetter.setProperty( node, "arr", new ArrayList<>() ); }
private Node createLabeledNode() { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode( LABEL ); tx.success(); return node; } }
@Test public void shouldNotWarnOnSmallLabelScansWithLoadCVS() { try ( Transaction tx = db().beginTx() ) { db().createNode().addLabel( label( "A" ) ); tx.success(); } Stream.of( "CYPHER 3.1", "CYPHER 3.5" ).forEach( version -> { shouldNotNotifyInStream( version, "EXPLAIN LOAD CSV FROM 'file:///ignore/ignore.csv' AS line MATCH (a:A) RETURN *" ); shouldNotNotifyInStream( version, "EXPLAIN LOAD CSV FROM 'file:///ignore/ignore.csv' AS line MERGE (a:A) RETURN *" ); } ); }
@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 createNode( GraphDatabaseAPI db, String name ) { try ( Transaction tx = db.beginTx() ) { db.createNode( LABEL ).setProperty( KEY, name ); tx.success(); } }
@Test public void getAllNodesIteratorShouldPickUpHigherIdsThanHighIdWhenStarted() throws Exception { // GIVEN { Transaction tx = db.beginTx(); db.createNode(); db.createNode(); tx.success(); tx.close(); } // WHEN iterator is started Transaction transaction = db.beginTx(); Iterator<Node> allNodes = db.getAllNodes().iterator(); allNodes.next(); // and WHEN another node is then added Thread thread = new Thread( () -> { Transaction newTx = db.beginTx(); assertThat( newTx, not( instanceOf( PlaceboTransaction.class ) ) ); db.createNode(); newTx.success(); newTx.close(); } ); thread.start(); thread.join(); // THEN the new node is picked up by the iterator assertThat( addToCollection( allNodes, new ArrayList<>() ).size(), is( 2 ) ); transaction.close(); }
@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[]{})); }
private Node createNodeWithProperty( String key, String value, Label... labels ) { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode( labels ); node.setProperty( key, value ); tx.success(); return node; } }
@Test public void shouldWarnOnLargeLabelScansWithLoadCVSMerge() { for ( int i = 0; i < 11; i++ ) { try ( Transaction tx = db().beginTx() ) { db().createNode().addLabel( label( "A" ) ); tx.success(); } } Stream.of( "CYPHER 3.1", "CYPHER 3.5" ).forEach( version -> assertNotifications( version + "EXPLAIN LOAD CSV FROM 'file:///ignore/ignore.csv' AS line MERGE (a:A) RETURN *", containsNoItem( largeLabelCSVWarning ) ) ); }
@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[]{})); }
private static void generateRandomData( GraphDatabaseAPI database, Label label, String nameProperty ) { for ( int i = 0; i < 1000; i++ ) { try ( Transaction transaction = database.beginTx() ) { Node node = database.createNode( label ); node.setProperty( nameProperty, "PlanetExpress" + i ); transaction.success(); } } }
@Test public void shouldWarnOnMisspelledLabel() { try ( Transaction tx = db().beginTx() ) { db().createNode().addLabel( label( "Person" ) ); tx.success(); } Stream.of( "CYPHER 2.3", "CYPHER 3.1", "CYPHER 3.5" ).forEach( version -> { assertNotifications(version + "EXPLAIN MATCH (n:Preson) RETURN *", containsItem( unknownLabelWarning ) ); shouldNotNotifyInStream( version, "EXPLAIN MATCH (n:Person) RETURN *" ); }); }
@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[]{})); }
private Node createUnLabeledNodeWithProperty() { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode(); node.setProperty( PROPERTY_KEY, PROPERTY_VALUE ); tx.success(); return node; } }
@Test public void queryResultsMustIncludeNodesWithPropertiesAddedToBeIndexed() { db = createDatabase(); try ( Transaction tx = db.beginTx() ) { createSimpleNodesIndex(); tx.success(); } long nodeId; try ( Transaction tx = db.beginTx() ) { awaitIndexesOnline(); nodeId = db.createNode( LABEL ).getId(); tx.success(); } try ( Transaction tx = db.beginTx() ) { db.getNodeById( nodeId ).setProperty( PROP, "value" ); assertQueryFindsIds( db, true, "nodes", "prop:value", nodeId ); tx.success(); } }
@Test public void shouldSetMultipleProperties() throws Exception { // Given Node node = db.createNode(); List<String> anArray = new ArrayList<>(); anArray.add( "hello" ); anArray.add( "Iamanarray" ); Map<String, Object> props = new HashMap<>(); props.put( "name", "bob" ); props.put( "age", 12 ); props.put( "anArray", anArray ); // When propSetter.setProperties( node, props ); // Then assertThat( node.getProperty( "name" ), is("bob")); assertThat( node.getProperty( "age" ), is(12)); assertThat( node.getProperty( "anArray" ), is(new String[]{"hello","Iamanarray"})); }