Skip to content

Commit

Permalink
#96 Remove CoreGraphValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
augustearth committed Aug 6, 2022
1 parent 70c6092 commit 5e34350
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class CoreGraphNeo4j extends CoreGraph {
if (args.vertexBuilders) graphSchema = new CoreGraphSchema(args.vertexBuilders)
else graphSchema = new CoreGraphSchema()

def graphValidator = new CoreGraphValidator()
def graphValidator = new GremlinGraphValidator()
def coreGraph = new CoreGraphNeo4j(graph, graphSchema, graphValidator)

def g = graph.traversal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CoreGraphTinker extends CoreGraph {
if (args.vertexBuilders) graphSchema = new CoreGraphSchema(args.vertexBuilders)
else graphSchema = new CoreGraphSchema()

def graphValidator = new CoreGraphValidator()
def graphValidator = new GremlinGraphValidator()
def coreGraph = new CoreGraphTinker(graph, graphSchema, graphValidator)

def g = graph.traversal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__

/** */
@Slf4j
public class CoreGraphValidator extends GremlinGraphValidator {
public class LegacyValidator extends GremlinGraphValidator {

///////////////////////////////////////////////////////////////////////////
// MODEL CHECKING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CoreGraphInitSpec extends Specification {

when:
def graphSchema = new CoreGraphSchema()
def graphValidator = new CoreGraphValidator()
def graphValidator = new GremlinGraphValidator()
def coreGraph = new CoreGraphNeo4j(graph, graphSchema, graphValidator)

then:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,101 +291,6 @@ class CoreGraphSpec extends Specification {
}


def "test checkConstraints for identifier uniqueness"() {
given:
def graph = coreGraph.graph
def g = graph.traversal()

def idClass1 = graph.addVertex(T.label, 'IdentifierClass', 'name', 'idClass1', 'hasCreationFacility', false, 'hasScope', false)
def idClass2 = graph.addVertex(T.label, 'IdentifierClass', 'name', 'idClass2', 'hasCreationFacility', false, 'hasScope', false)
def scopedIdClass = graph.addVertex(T.label, 'IdentifierClass', 'name', 'testIdClass', 'hasCreationFacility', false, 'hasScope', true)
def facilityIdClass = graph.addVertex(T.label, 'IdentifierClass', 'name', 'testFacilityClass', 'hasCreationFacility', true, 'hasScope', false)

def scope1 = graph.addVertex(T.label, 'IdentifierScope', "name", "scope1")
def scope2 = graph.addVertex(T.label, 'IdentifierScope', "name", "scope2")

def facility1 = graph.addVertex(T.label, 'IdentifierFacility', "name", "facility1")
def facility2 = graph.addVertex(T.label, 'IdentifierFacility', "name", "facility2")

def id1Class1 = graph.addVertex(T.label, 'Identifier', 'value', 'id1')
id1Class1.addEdge('is_instance_of', idClass1)

def id2Class1 = graph.addVertex(T.label, 'Identifier', 'value', 'id2')
id2Class1.addEdge('is_instance_of', idClass1)

def id1Class2 = graph.addVertex(T.label, 'Identifier', 'value', 'id1')
id1Class2.addEdge('is_instance_of', idClass2)

// scope
def scopedId1Scope1 = graph.addVertex(T.label, 'Identifier', 'value', 'scopedId1')
scopedId1Scope1.addEdge('is_instance_of', scopedIdClass)
scopedId1Scope1.addEdge('is_scoped_by', scope1)

def scopedId1Scope2 = graph.addVertex(T.label, 'Identifier', 'value', 'scopedId1')
scopedId1Scope2.addEdge('is_instance_of', scopedIdClass)
scopedId1Scope2.addEdge('is_scoped_by', scope2)


// facility
def facilityId1Facility1 = graph.addVertex(T.label, 'Identifier', 'value', 'facilityId1')
facilityId1Facility1.addEdge('is_instance_of', facilityIdClass)
facilityId1Facility1.addEdge('was_created_by', facility1)

def facilityId1Facility2 = graph.addVertex(T.label, 'Identifier', 'value', 'facilityId1')
facilityId1Facility2.addEdge('is_instance_of', facilityIdClass)
facilityId1Facility2.addEdge('was_created_by', facility2)



expect:
coreGraph.checkConstraints().size() == 0

// duplicate id val of the same class
when:
def id1Class1Dupe = graph.addVertex(T.label, 'Identifier', 'value', 'id1')
id1Class1Dupe.addEdge('is_instance_of', idClass1)

then:
coreGraph.checkConstraints().size() == 1

// reset
when:
id1Class1Dupe.remove()

then:
coreGraph.checkConstraints().size() == 0


//duplicate id val of the same class, same scope
when:
def scopedId1Scope1Dupe = graph.addVertex(T.label, 'Identifier', 'value', 'scopedId1')
scopedId1Scope1Dupe.addEdge('is_instance_of', scopedIdClass)
scopedId1Scope1Dupe.addEdge('is_scoped_by', scope1)


then:
coreGraph.checkConstraints().size() == 1

// reset
when:
scopedId1Scope1Dupe.remove()

then:
coreGraph.checkConstraints().size() == 0


//duplicate id val of the same class, same facility
when:
def facilityId1Facility1Dupe = graph.addVertex(T.label, 'Identifier', 'value', 'facilityId1')
facilityId1Facility1Dupe.addEdge('is_instance_of', facilityIdClass)
facilityId1Facility1Dupe.addEdge('was_created_by', facility1)

then:
coreGraph.checkConstraints().size() == 1

}


def "test checkModel for unmodeled vertex and edge labels"() {
given:
def graph = coreGraph.graph
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
package carnival.core.graph



import spock.lang.Specification
import spock.lang.Unroll
import spock.lang.Shared

import org.apache.tinkerpop.gremlin.structure.T
import org.apache.tinkerpop.gremlin.process.traversal.Traversal
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource
import static org.apache.tinkerpop.gremlin.neo4j.process.traversal.LabelP.of

import carnival.graph.*



/**
* gradle test --tests "carnival.core.graph.CoreGraphSpec"
*
*/
class LegacyGraphSpec extends Specification {

///////////////////////////////////////////////////////////////////////////
// DEFS
///////////////////////////////////////////////////////////////////////////

static enum VX implements VertexDefinition {
CGS_SUITCASE
}

///////////////////////////////////////////////////////////////////////////
// FIELDS
///////////////////////////////////////////////////////////////////////////

@Shared coreGraph

@Shared vertexBuilders = [
Core.VX.IDENTIFIER.instance().withProperty(Core.PX.VALUE, "1"),
Core.VX.IDENTIFIER.instance().withProperty(Core.PX.VALUE, "2"),
]


///////////////////////////////////////////////////////////////////////////
// SET UP
///////////////////////////////////////////////////////////////////////////


def setup() {
coreGraph = CoreGraphTinker.create(vertexBuilders:vertexBuilders)
coreGraph.graphValidator = new LegacyValidator()
}

def setupSpec() {
//CoreGraphNeo4j.clearGraph()
//coreGraph = CoreGraphNeo4j.create(vertexBuilders:vertexBuilders)
}


def cleanupSpec() {
//if (coreGraph) coreGraph.graph.close()
}


def cleanup() {
//if (coreGraph) coreGraph.graph.tx().rollback()
if (coreGraph) coreGraph.close()
}



///////////////////////////////////////////////////////////////////////////
// TESTS
///////////////////////////////////////////////////////////////////////////


def "test checkConstraints for identifier uniqueness"() {
given:
def graph = coreGraph.graph
def g = graph.traversal()

def idClass1 = graph.addVertex(T.label, 'IdentifierClass', 'name', 'idClass1', 'hasCreationFacility', false, 'hasScope', false)
def idClass2 = graph.addVertex(T.label, 'IdentifierClass', 'name', 'idClass2', 'hasCreationFacility', false, 'hasScope', false)
def scopedIdClass = graph.addVertex(T.label, 'IdentifierClass', 'name', 'testIdClass', 'hasCreationFacility', false, 'hasScope', true)
def facilityIdClass = graph.addVertex(T.label, 'IdentifierClass', 'name', 'testFacilityClass', 'hasCreationFacility', true, 'hasScope', false)

def scope1 = graph.addVertex(T.label, 'IdentifierScope', "name", "scope1")
def scope2 = graph.addVertex(T.label, 'IdentifierScope', "name", "scope2")

def facility1 = graph.addVertex(T.label, 'IdentifierFacility', "name", "facility1")
def facility2 = graph.addVertex(T.label, 'IdentifierFacility', "name", "facility2")

def id1Class1 = graph.addVertex(T.label, 'Identifier', 'value', 'id1')
id1Class1.addEdge('is_instance_of', idClass1)

def id2Class1 = graph.addVertex(T.label, 'Identifier', 'value', 'id2')
id2Class1.addEdge('is_instance_of', idClass1)

def id1Class2 = graph.addVertex(T.label, 'Identifier', 'value', 'id1')
id1Class2.addEdge('is_instance_of', idClass2)

// scope
def scopedId1Scope1 = graph.addVertex(T.label, 'Identifier', 'value', 'scopedId1')
scopedId1Scope1.addEdge('is_instance_of', scopedIdClass)
scopedId1Scope1.addEdge('is_scoped_by', scope1)

def scopedId1Scope2 = graph.addVertex(T.label, 'Identifier', 'value', 'scopedId1')
scopedId1Scope2.addEdge('is_instance_of', scopedIdClass)
scopedId1Scope2.addEdge('is_scoped_by', scope2)


// facility
def facilityId1Facility1 = graph.addVertex(T.label, 'Identifier', 'value', 'facilityId1')
facilityId1Facility1.addEdge('is_instance_of', facilityIdClass)
facilityId1Facility1.addEdge('was_created_by', facility1)

def facilityId1Facility2 = graph.addVertex(T.label, 'Identifier', 'value', 'facilityId1')
facilityId1Facility2.addEdge('is_instance_of', facilityIdClass)
facilityId1Facility2.addEdge('was_created_by', facility2)



expect:
coreGraph.checkConstraints().size() == 0

// duplicate id val of the same class
when:
def id1Class1Dupe = graph.addVertex(T.label, 'Identifier', 'value', 'id1')
id1Class1Dupe.addEdge('is_instance_of', idClass1)

then:
coreGraph.checkConstraints().size() == 1

// reset
when:
id1Class1Dupe.remove()

then:
coreGraph.checkConstraints().size() == 0


//duplicate id val of the same class, same scope
when:
def scopedId1Scope1Dupe = graph.addVertex(T.label, 'Identifier', 'value', 'scopedId1')
scopedId1Scope1Dupe.addEdge('is_instance_of', scopedIdClass)
scopedId1Scope1Dupe.addEdge('is_scoped_by', scope1)


then:
coreGraph.checkConstraints().size() == 1

// reset
when:
scopedId1Scope1Dupe.remove()

then:
coreGraph.checkConstraints().size() == 0


//duplicate id val of the same class, same facility
when:
def facilityId1Facility1Dupe = graph.addVertex(T.label, 'Identifier', 'value', 'facilityId1')
facilityId1Facility1Dupe.addEdge('is_instance_of', facilityIdClass)
facilityId1Facility1Dupe.addEdge('was_created_by', facility1)

then:
coreGraph.checkConstraints().size() == 1

}

}

0 comments on commit 5e34350

Please sign in to comment.