private void createNode() { try ( Transaction tx = db.beginTx() ) { db.createNode(); tx.success(); } }
private WorkerCommand<Void,Void> nodeCreator() { return state -> { try ( Transaction tx = db.beginTx() ) { createRoundOfNodes(); tx.success(); } return null; }; }
private void verifyLabels( long nodeId, int startLabelIndex, int count ) { try ( Transaction tx = dbRule.beginTx() ) { Node node = dbRule.getNodeById( nodeId ); Set<String> labelNames = Iterables.asList( node.getLabels() ) .stream() .map( Label::name ) .sorted() .collect( toSet() ); assertEquals( count, labelNames.size() ); int endLabelIndex = startLabelIndex + count; for ( int i = startLabelIndex; i < endLabelIndex; i++ ) { assertTrue( labelNames.contains( labelName( i ) ) ); } tx.success(); } }
private void addLabels( long nodeId, int startLabelIndex, int count ) { try ( Transaction tx = dbRule.beginTx() ) { Node node = dbRule.getNodeById( nodeId ); int endLabelIndex = startLabelIndex + count; for ( int i = startLabelIndex; i < endLabelIndex; i++ ) { node.addLabel( labelWithIndex( i ) ); } tx.success(); } }
private void removeLabels( long nodeId, int startLabelIndex, int count ) { try ( Transaction tx = dbRule.beginTx() ) { Node node = dbRule.getNodeById( nodeId ); int endLabelIndex = startLabelIndex + count; for ( int i = startLabelIndex; i < endLabelIndex; i++ ) { node.removeLabel( labelWithIndex( i ) ); } tx.success(); } }
@Test public void shouldBeAbleToCreateRelationshipsInEmptyDenseNode() { // GIVEN Node node; try ( Transaction tx = databaseRule.beginTx() ) { node = databaseRule.createNode(); createRelationshipsBetweenNodes( node, databaseRule.createNode(), denseNodeThreshold( databaseRule ) + 1 ); tx.success(); } try ( Transaction tx = databaseRule.beginTx() ) { node.getRelationships().forEach( Relationship::delete ); tx.success(); } // WHEN Relationship rel; try ( Transaction tx = databaseRule.beginTx() ) { rel = node.createRelationshipTo( databaseRule.createNode(), MyRelTypes.TEST ); tx.success(); } try ( Transaction tx = databaseRule.beginTx() ) { // THEN assertEquals( rel, single( node.getRelationships() ) ); tx.success(); } }
@Before public void setup() { for ( int i = 0; i < 100; i++ ) { try ( Transaction tx = db.beginTx() ) { for ( int j = 0; j < 100; j++ ) { Node node = db.createNode( label( "L" ) ); node.setProperty( "prop", i + j ); } tx.success(); } } }
@Before public void setup() { for ( int i = 0; i < 100; i++ ) { try ( Transaction tx = db.beginTx() ) { Node prev = null; for ( int j = 0; j < 100; j++ ) { Node node = db.createNode( label( "L" ) ); if ( prev != null ) { Relationship rel = prev.createRelationshipTo( node, RelationshipType.withName( "T" ) ); rel.setProperty( "prop", i + j ); } prev = node; } tx.success(); } } }
@Before public void startTransaction() { tx = graphDb.beginTx(); }
@Test public void noExtraCreatedNodes() { try (Transaction tx = graphDb.beginTx()) { assertEquals(size(graphDb.getAllNodes()), 2); tx.success(); } }
@Test public void schemaOnMultipleLabelsAndMultipleSingleProperties() { Neo4jConfiguration configuration = new Neo4jConfiguration(); configuration.setLocation(graphPath.getRoot().getAbsolutePath()); Set<String> property = new HashSet<String>(); property.add("property11"); property.add("property12"); Map<String, Set<String>> schemaIndexes = new HashMap<String, Set<String>>(); schemaIndexes.put("label", property); Set<String> property2 = new HashSet<String>(); property2.add("property21"); property2.add("property22"); schemaIndexes.put("label2", property2); configuration.setSchemaIndexes(schemaIndexes); Neo4jModule.setupSchemaIndexes(graphDb, configuration); try (Transaction tx = graphDb.beginTx()) { assertThat(size(graphDb.schema().getIndexes()), is(4)); tx.success(); tx.close(); } } }
@Test public void schemaOnMultipleProperties() { Neo4jConfiguration configuration = new Neo4jConfiguration(); configuration.setLocation(graphPath.getRoot().getAbsolutePath()); Set<String> property = new HashSet<String>(); property.add("property"); property.add("property2"); Map<String, Set<String>> schemaIndexes = new HashMap<String, Set<String>>(); schemaIndexes.put("label", property); configuration.setSchemaIndexes(schemaIndexes); Neo4jModule.setupSchemaIndexes(graphDb, configuration); try (Transaction tx = graphDb.beginTx()) { assertThat(size(graphDb.schema().getIndexes()), is(2)); tx.success(); tx.close(); } }
@Test public void schemaOnSingleProperty() { Neo4jConfiguration configuration = new Neo4jConfiguration(); configuration.setLocation(graphPath.getRoot().getAbsolutePath()); Set<String> property = new HashSet<String>(); property.add("property"); Map<String, Set<String>> schemaIndexes = new HashMap<String, Set<String>>(); schemaIndexes.put("label", property); configuration.setSchemaIndexes(schemaIndexes); Neo4jModule.setupSchemaIndexes(graphDb, configuration); try (Transaction tx = graphDb.beginTx()) { assertThat(size(graphDb.schema().getIndexes()), is(1)); tx.success(); tx.close(); } }
@Test public void supportEmptySchemaDefinition() { Neo4jConfiguration configuration = new Neo4jConfiguration(); configuration.setLocation(graphPath.getRoot().getAbsolutePath()); Neo4jModule.setupSchemaIndexes(graphDb, configuration); try (Transaction tx = graphDb.beginTx()) { assertThat(graphDb.schema().getIndexes().iterator().hasNext(), is(false)); tx.success(); tx.close(); } }
@Before public void setup() { graphDb.beginTx(); node = graphDb.createNode(); node.setProperty("foo", "bar"); node.setProperty("fizz", 1); }
@Before public void setup() throws Exception { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); String uri = Resources.getResource("ontologies/cases/TestEquivalentToInverse.owl").toURI().toString(); IRI iri = IRI.create(uri); manager.loadOntologyFromOntologyDocument(iri); OWLOntologyWalker walker = new OWLOntologyWalker(manager.getOntologies()); MappedProperty mappedProperty = new MappedProperty(NodeProperties.LABEL); List<String> properties = new ArrayList<String>(); properties.add("http://www.w3.org/2000/01/rdf-schema#label"); properties.add("http://www.w3.org/2004/02/skos/core#prefLabel"); mappedProperty.setProperties(properties); ArrayList<MappedProperty> mappedPropertyList = new ArrayList<MappedProperty>(); mappedPropertyList.add(mappedProperty); GraphOwlVisitor visitor = new GraphOwlVisitor(walker, graph, mappedPropertyList); walker.walkStructure(visitor); Map<String, String> categories = new HashMap<>(); try (Transaction tx = graphDb.beginTx()) { OwlPostprocessor postprocessor = new OwlPostprocessor(graphDb, categories); postprocessor.processCategories(categories); postprocessor.processSomeValuesFrom(); tx.success(); } }
@Test public void noEquivalentPropertyEdge() { try (Transaction tx = graphDb.beginTx()) { for (Node n : graphDb.getAllNodes()) { assertFalse(n.hasRelationship(RelationshipType.withName("equivalentProperty"))); } tx.success(); } }