Search in sources :

Example 6 with RelExistenceConstraintDescriptor

use of org.neo4j.internal.schema.constraints.RelExistenceConstraintDescriptor in project neo4j by neo4j.

the class SchemaCheckerTest method shouldPopulateMandatoryPropertiesMap.

@Test
void shouldPopulateMandatoryPropertiesMap() throws Exception {
    // given
    try (AutoCloseable ignored = tx()) {
        var cursorContext = CursorContext.NULL;
        NodeExistenceConstraintDescriptor constraint1 = ConstraintDescriptorFactory.existsForLabel(label1, propertyKey1).withId(schemaStore.nextId(cursorContext)).withName(NAME);
        NodeExistenceConstraintDescriptor constraint2 = ConstraintDescriptorFactory.existsForLabel(label2, propertyKey1, propertyKey2).withId(schemaStore.nextId(cursorContext)).withName(NAME2);
        RelExistenceConstraintDescriptor constraint3 = ConstraintDescriptorFactory.existsForRelType(relationshipType1, propertyKey2).withId(schemaStore.nextId(cursorContext)).withName(NAME);
        RelExistenceConstraintDescriptor constraint4 = ConstraintDescriptorFactory.existsForRelType(relationshipType2, propertyKey1, propertyKey2).withId(schemaStore.nextId(cursorContext)).withName(NAME2);
        schemaStorage.writeSchemaRule(constraint1, cursorContext, INSTANCE);
        schemaStorage.writeSchemaRule(constraint2, cursorContext, INSTANCE);
        schemaStorage.writeSchemaRule(constraint3, cursorContext, INSTANCE);
        schemaStorage.writeSchemaRule(constraint4, cursorContext, INSTANCE);
    }
    // when
    check();
    // then
    assertEquals(IntSets.mutable.of(propertyKey1), mandatoryNodeProperties.remove(label1));
    assertEquals(IntSets.mutable.of(propertyKey1, propertyKey2), mandatoryNodeProperties.remove(label2));
    assertTrue(mandatoryNodeProperties.isEmpty());
    assertEquals(IntSets.mutable.of(propertyKey2), mandatoryRelationshipProperties.remove(relationshipType1));
    assertEquals(IntSets.mutable.of(propertyKey1, propertyKey2), mandatoryRelationshipProperties.remove(relationshipType2));
    assertTrue(mandatoryRelationshipProperties.isEmpty());
}
Also used : RelExistenceConstraintDescriptor(org.neo4j.internal.schema.constraints.RelExistenceConstraintDescriptor) NodeExistenceConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeExistenceConstraintDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

RelExistenceConstraintDescriptor (org.neo4j.internal.schema.constraints.RelExistenceConstraintDescriptor)6 Test (org.junit.jupiter.api.Test)4 NodeExistenceConstraintDescriptor (org.neo4j.internal.schema.constraints.NodeExistenceConstraintDescriptor)4 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)3 NodeKeyConstraintDescriptor (org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor)3 IndexBackedConstraintDescriptor (org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor)2 UniquenessConstraintDescriptor (org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor)2 RelationTypeSchemaDescriptor (org.neo4j.internal.schema.RelationTypeSchemaDescriptor)1 AlreadyConstrainedException (org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException)1 TxState (org.neo4j.kernel.impl.api.state.TxState)1 NamedToken (org.neo4j.token.api.NamedToken)1