From a9a4e094789a3983e39814ece522179393a8fc0b Mon Sep 17 00:00:00 2001 From: Chris Vest Date: Tue, 31 Jul 2018 17:30:34 +0200 Subject: [PATCH] Simplify the FacadeMethod tests and extend the transaction check to more facade methods. --- .../neo4j/graphdb/NodeIndexFacadeMethods.java | 96 +------ .../RelationshipIndexFacadeMethods.java | 132 +-------- .../ConstraintCreatorFacadeMethods.java | 21 +- .../ConstraintDefinitionFacadeMethods.java | 54 +--- .../GraphDatabaseServiceFacadeMethods.java | 160 ++--------- .../graphdb/IndexCreatorFacadeMethods.java | 21 +- .../graphdb/IndexDefinitionFacadeMethods.java | 48 +--- .../graphdb/IndexManagerFacadeMethods.java | 93 +------ .../org/neo4j/graphdb/NodeFacadeMethods.java | 257 ++---------------- .../graphdb/RelationshipFacadeMethods.java | 153 ++--------- .../neo4j/graphdb/SchemaFacadeMethods.java | 108 +------- .../impl/coreapi/schema/SchemaImplTest.java | 5 +- .../kernel/impl/core/RelationshipProxy.java | 3 + .../impl/coreapi/schema/SchemaImpl.java | 3 - .../impl/factory/GraphDatabaseFacade.java | 1 + .../java/org/neo4j/graphdb/FacadeMethod.java | 30 +- 16 files changed, 148 insertions(+), 1037 deletions(-) diff --git a/community/community-it/index-it/src/test/java/org/neo4j/graphdb/NodeIndexFacadeMethods.java b/community/community-it/index-it/src/test/java/org/neo4j/graphdb/NodeIndexFacadeMethods.java index d52f16f1f262..3daa158c21a4 100644 --- a/community/community-it/index-it/src/test/java/org/neo4j/graphdb/NodeIndexFacadeMethods.java +++ b/community/community-it/index-it/src/test/java/org/neo4j/graphdb/NodeIndexFacadeMethods.java @@ -26,93 +26,15 @@ public class NodeIndexFacadeMethods { - private static final FacadeMethod> GET = new FacadeMethod>( "IndexHits get( String " + - "key, Object value )" ) - { - @Override - public void call( Index self ) - { - self.get( "foo", "bar" ); - } - }; - - private static final FacadeMethod> QUERY_BY_KEY = new FacadeMethod>( "IndexHits query(" + - " String key, Object queryOrQueryObject )" ) - { - @Override - public void call( Index self ) - { - self.query( "foo", "bar" ); - } - }; - - private static final FacadeMethod> QUERY = new FacadeMethod>( "IndexHits query( Object" + - " queryOrQueryObject )" ) - { - @Override - public void call( Index self ) - { - self.query( "foo" ); - } - }; - - private static final FacadeMethod> ADD = new FacadeMethod>( "void add( T entity, " + - "String key, Object value )" ) - { - @Override - public void call( Index self ) - { - self.add( null, "foo", 42 ); - } - }; - - private static final FacadeMethod> REMOVE_BY_KEY_AND_VALUE = new FacadeMethod>( "void " + - "remove( T entity, String key, Object value )" ) - { - @Override - public void call( Index self ) - { - self.remove( null, "foo", 42 ); - } - }; - - private static final FacadeMethod> REMOVE_BY_KEY = new FacadeMethod>( "void remove( T " + - "entity, String key )" ) - { - @Override - public void call( Index self ) - { - self.remove( null, "foo" ); - } - }; - - private static final FacadeMethod> REMOVE = new FacadeMethod>( "void remove( T entity )" ) - { - @Override - public void call( Index self ) - { - self.remove( null ); - } - }; - - private static final FacadeMethod> DELETE = new FacadeMethod>( "void delete()" ) - { - @Override - public void call( Index self ) - { - self.delete(); - } - }; - - private static final FacadeMethod> PUT_IF_ABSENT = new FacadeMethod>( "T putIfAbsent( T " + - "entity, String key, Object value )" ) - { - @Override - public void call( Index self ) - { - self.putIfAbsent( null, "foo", 42 ); - } - }; + private static final FacadeMethod> GET = new FacadeMethod<>( "IndexHits get( String key, Object value )", self -> self.get( "foo", "bar" ) ); + private static final FacadeMethod> QUERY_BY_KEY = new FacadeMethod<>( "IndexHits query( String key, Object queryOrQueryObject )", self -> self.query( "foo", "bar" ) ); + private static final FacadeMethod> QUERY = new FacadeMethod<>( "IndexHits query( Object queryOrQueryObject )", self -> self.query( "foo" ) ); + private static final FacadeMethod> ADD = new FacadeMethod<>( "void add( T entity, String key, Object value )", self -> self.add( null, "foo", 42 ) ); + private static final FacadeMethod> REMOVE_BY_KEY_AND_VALUE = new FacadeMethod<>( "void remove( T entity, String key, Object value )", self -> self.remove( null, "foo", 42 ) ); + private static final FacadeMethod> REMOVE_BY_KEY = new FacadeMethod<>( "void remove( T entity, String key )", self -> self.remove( null, "foo" ) ); + private static final FacadeMethod> REMOVE = new FacadeMethod<>( "void remove( T entity )", self -> self.remove( null ) ); + private static final FacadeMethod> DELETE = new FacadeMethod<>( "void delete()", Index::delete ); + private static final FacadeMethod> PUT_IF_ABSENT = new FacadeMethod<>( "T putIfAbsent( T entity, String key, Object value )", self -> self.putIfAbsent( null, "foo", 42 ) ); static final Iterable>> ALL_NODE_INDEX_FACADE_METHODS = unmodifiableCollection( asList( diff --git a/community/community-it/index-it/src/test/java/org/neo4j/graphdb/RelationshipIndexFacadeMethods.java b/community/community-it/index-it/src/test/java/org/neo4j/graphdb/RelationshipIndexFacadeMethods.java index 23c8663a54a7..9fe7a6e3b953 100644 --- a/community/community-it/index-it/src/test/java/org/neo4j/graphdb/RelationshipIndexFacadeMethods.java +++ b/community/community-it/index-it/src/test/java/org/neo4j/graphdb/RelationshipIndexFacadeMethods.java @@ -26,126 +26,18 @@ public class RelationshipIndexFacadeMethods { - private static final FacadeMethod GET_WITH_FILTER = new FacadeMethod( - "IndexHits get( String key, Object valueOrNull, Node startNodeOrNull, Node endNodeOrNull )" ) - { - @Override - public void call( RelationshipIndex self ) - { - self.get( "foo", 42, null, null ); - } - }; - - private static final FacadeMethod QUERY_BY_KEY_WITH_FILTER = new - FacadeMethod( "IndexHits query( String key, " + - "Object queryOrQueryObjectOrNull, Node startNodeOrNull, Node endNodeOrNull )" ) - { - @Override - public void call( RelationshipIndex self ) - { - self.query( "foo", 42, null, null ); - } - }; - - private static final FacadeMethod QUERY_WITH_FILTER = new FacadeMethod( - "IndexHits query( Object queryOrQueryObjectOrNull, Node startNodeOrNull, " + - "Node endNodeOrNull )" ) - { - @Override - public void call( RelationshipIndex self ) - { - self.query( 42, null, null ); - } - }; - - private static final FacadeMethod GET = new FacadeMethod( "IndexHits" + - " get( String key, Object value )" ) - { - @Override - public void call( RelationshipIndex self ) - { - self.get( "foo", "bar" ); - } - }; - - private static final FacadeMethod QUERY_BY_KEY = new FacadeMethod( - "IndexHits query( String key, Object queryOrQueryObject )" ) - { - @Override - public void call( RelationshipIndex self ) - { - self.query( "foo", "bar" ); - } - }; - - private static final FacadeMethod QUERY = new FacadeMethod( - "IndexHits query( Object queryOrQueryObject )" ) - { - @Override - public void call( RelationshipIndex self ) - { - self.query( "foo" ); - } - }; - - private static final FacadeMethod ADD = new FacadeMethod( "void add( T " + - "entity, String key, Object value )" ) - { - @Override - public void call( RelationshipIndex self ) - { - self.add( null, "foo", 42 ); - } - }; - - private static final FacadeMethod REMOVE_BY_KEY_AND_VALUE = new - FacadeMethod( "void remove( T entity, String key, Object value )" ) - { - @Override - public void call( RelationshipIndex self ) - { - self.remove( null, "foo", 42 ); - } - }; - - private static final FacadeMethod REMOVE_BY_KEY = new FacadeMethod( - "void remove( T entity, String key )" ) - { - @Override - public void call( RelationshipIndex self ) - { - self.remove( null, "foo" ); - } - }; - - private static final FacadeMethod REMOVE = new FacadeMethod( "void " + - "remove( T entity )" ) - { - @Override - public void call( RelationshipIndex self ) - { - self.remove( null ); - } - }; - - private static final FacadeMethod DELETE = new FacadeMethod( "void delete()" ) - { - @Override - public void call( RelationshipIndex self ) - { - self.delete(); - } - }; - - private static final FacadeMethod PUT_IF_ABSENT = new FacadeMethod( "T " + - "putIfAbsent( T entity, String key, Object value )" ) - { - @Override - public void call( RelationshipIndex self ) - { - self.putIfAbsent( null, "foo", 42 ); - } - }; + private static final FacadeMethod GET_WITH_FILTER = new FacadeMethod<>( "IndexHits get( String key, Object valueOrNull, Node startNodeOrNull, Node endNodeOrNull )", ri -> ri.get( "foo", 42, null, null ) ); + private static final FacadeMethod QUERY_BY_KEY_WITH_FILTER = new FacadeMethod<>( "IndexHits query( String key, Object queryOrQueryObjectOrNull, Node startNodeOrNull, Node endNodeOrNull )", ri -> ri.query( "foo", 42, null, null ) ); + private static final FacadeMethod QUERY_WITH_FILTER = new FacadeMethod<>( "IndexHits query( Object queryOrQueryObjectOrNull, Node startNodeOrNull, Node endNodeOrNull )", ri -> ri.query( 42, null, null ) ); + private static final FacadeMethod GET = new FacadeMethod<>( "IndexHits get( String key, Object value )", ri -> ri.get( "foo", "bar" ) ); + private static final FacadeMethod QUERY_BY_KEY = new FacadeMethod<>( "IndexHits query( String key, Object queryOrQueryObject )", ri -> ri.query( "foo", "bar" ) ); + private static final FacadeMethod QUERY = new FacadeMethod<>( "IndexHits query( Object queryOrQueryObject )", ri -> ri.query( "foo" ) ); + private static final FacadeMethod ADD = new FacadeMethod<>( "void add( T entity, String key, Object value )", ri -> ri.add( null, "foo", 42 ) ); + private static final FacadeMethod REMOVE_BY_KEY_AND_VALUE = new FacadeMethod<>( "void remove( T entity, String key, Object value )", ri -> ri.remove( null, "foo", 42 ) ); + private static final FacadeMethod REMOVE_BY_KEY = new FacadeMethod<>( "void remove( T entity, String key )", ri -> ri.remove( null, "foo" ) ); + private static final FacadeMethod REMOVE = new FacadeMethod<>( "void remove( T entity )", ri -> ri.remove( null ) ); + private static final FacadeMethod DELETE = new FacadeMethod<>( "void delete()", RelationshipIndex::delete ); + private static final FacadeMethod PUT_IF_ABSENT = new FacadeMethod<>( "T putIfAbsent( T entity, String key, Object value )", ri -> ri.putIfAbsent( null, "foo", 42 ) ); static final Iterable> ALL_RELATIONSHIP_INDEX_FACADE_METHODS = unmodifiableCollection( diff --git a/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/ConstraintCreatorFacadeMethods.java b/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/ConstraintCreatorFacadeMethods.java index e14c875dbfb3..d9c18d26f7c7 100644 --- a/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/ConstraintCreatorFacadeMethods.java +++ b/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/ConstraintCreatorFacadeMethods.java @@ -26,25 +26,8 @@ public class ConstraintCreatorFacadeMethods { - private static final FacadeMethod UNIQUE = - new FacadeMethod( "ConstraintCreator unique()" ) - { - @Override - public void call( ConstraintCreator self ) - { - self.assertPropertyIsUnique( "property" ); - } - }; - - private static final FacadeMethod CREATE = - new FacadeMethod( "ConstraintDefinition create()" ) - { - @Override - public void call( ConstraintCreator self ) - { - self.create(); - } - }; + private static final FacadeMethod UNIQUE = new FacadeMethod<>( "ConstraintCreator assertPropertyIsUnique()", self -> self.assertPropertyIsUnique( "property" ) ); + private static final FacadeMethod CREATE = new FacadeMethod<>( "ConstraintDefinition create()", ConstraintCreator::create ); static final Iterable> ALL_CONSTRAINT_CREATOR_FACADE_METHODS = unmodifiableCollection( asList( diff --git a/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/ConstraintDefinitionFacadeMethods.java b/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/ConstraintDefinitionFacadeMethods.java index 1115aabeb5d6..4fcdad324680 100644 --- a/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/ConstraintDefinitionFacadeMethods.java +++ b/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/ConstraintDefinitionFacadeMethods.java @@ -27,55 +27,11 @@ public class ConstraintDefinitionFacadeMethods { - private static final FacadeMethod GET_LABEL = - new FacadeMethod( "Label getLabel()" ) - { - @Override - public void call( ConstraintDefinition self ) - { - self.getLabel(); - } - }; - - private static final FacadeMethod GET_RELATIONSHIP_TYPE = - new FacadeMethod( "RelationshipType getRelationshipType()" ) - { - @Override - public void call( ConstraintDefinition self ) - { - self.getRelationshipType(); - } - }; - - private static final FacadeMethod DROP = - new FacadeMethod( "void drop()" ) - { - @Override - public void call( ConstraintDefinition self ) - { - self.drop(); - } - }; - - private static final FacadeMethod IS_CONSTRAINT_TYPE = - new FacadeMethod( "boolean isConstraintType( ConstraintType type )" ) - { - @Override - public void call( ConstraintDefinition self ) - { - self.isConstraintType( ConstraintType.UNIQUENESS ); - } - }; - - private static final FacadeMethod GET_PROPERTY_KEYS = - new FacadeMethod( "Iterable getPropertyKeys()" ) - { - @Override - public void call( ConstraintDefinition self ) - { - self.getPropertyKeys(); - } - }; + private static final FacadeMethod GET_LABEL = new FacadeMethod<>( "Label getLabel()", ConstraintDefinition::getLabel ); + private static final FacadeMethod GET_RELATIONSHIP_TYPE = new FacadeMethod<>( "RelationshipType getRelationshipType()", ConstraintDefinition::getRelationshipType ); + private static final FacadeMethod DROP = new FacadeMethod<>( "void drop()", ConstraintDefinition::drop ); + private static final FacadeMethod IS_CONSTRAINT_TYPE = new FacadeMethod<>( "boolean isConstraintType( ConstraintType type )", self -> self.isConstraintType( ConstraintType.UNIQUENESS ) ); + private static final FacadeMethod GET_PROPERTY_KEYS = new FacadeMethod<>( "Iterable getPropertyKeys()", ConstraintDefinition::getPropertyKeys ); static final Iterable> ALL_CONSTRAINT_DEFINITION_FACADE_METHODS = unmodifiableCollection( asList( diff --git a/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/GraphDatabaseServiceFacadeMethods.java b/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/GraphDatabaseServiceFacadeMethods.java index 7a4a1eae38ad..6814dc3af1a0 100644 --- a/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/GraphDatabaseServiceFacadeMethods.java +++ b/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/GraphDatabaseServiceFacadeMethods.java @@ -21,6 +21,7 @@ import static java.util.Arrays.asList; import static java.util.Collections.unmodifiableCollection; +import static org.neo4j.graphdb.FacadeMethod.consume; import static org.neo4j.graphdb.Label.label; import static org.neo4j.helpers.collection.Iterators.loop; @@ -29,145 +30,22 @@ */ public class GraphDatabaseServiceFacadeMethods { - static final FacadeMethod CREATE_NODE = - new FacadeMethod( "Node createNode()" ) - { - @Override - public void call( GraphDatabaseService graphDatabaseService ) - { - graphDatabaseService.createNode(); - } - }; - - static final FacadeMethod CREATE_NODE_WITH_LABELS = - new FacadeMethod( "Node createNode( Label... labels )" ) - { - @Override - public void call( GraphDatabaseService graphDatabaseService ) - { - graphDatabaseService.createNode( label( "FOO" ) ); - } - }; - - static final FacadeMethod GET_NODE_BY_ID = - new FacadeMethod( "Node getNodeById( long id )" ) - { - @Override - public void call( GraphDatabaseService graphDatabaseService ) - { - graphDatabaseService.getNodeById( 42 ); - } - }; - - static final FacadeMethod GET_RELATIONSHIP_BY_ID = - new FacadeMethod( "Relationship getRelationshipById( long id )" ) - { - @Override - public void call( GraphDatabaseService graphDatabaseService ) - { - graphDatabaseService.getRelationshipById( 87 ); - } - }; - - static final FacadeMethod GET_ALL_NODES = - new FacadeMethod( "Iterable getAllNodes()" ) - { - @Override - public void call( GraphDatabaseService graphDatabaseService ) - { - for ( Node node : graphDatabaseService.getAllNodes() ) - { - - } - } - }; - - static final FacadeMethod FIND_NODES_BY_LABEL_AND_PROPERTY_DEPRECATED = - new FacadeMethod( - "ResourceIterator findNodeByLabelAndProperty( Label label, String key, Object value )" ) - { - @Override - public void call( GraphDatabaseService graphDatabaseService ) - { - for ( Node node : loop( graphDatabaseService.findNodes( label( "bar" ), "baz", 23 ) ) ) - { - - } - } - }; - - static final FacadeMethod FIND_NODES_BY_LABEL = - new FacadeMethod( - "ResourceIterator findNodes( Label label )" ) - { - @Override - public void call( GraphDatabaseService graphDatabaseService ) - { - for ( Node node : loop( graphDatabaseService.findNodes( label( "bar" ) ) ) ) - { - - } - } - }; - - static final FacadeMethod GET_ALL_LABELS = - new FacadeMethod( "Iterable