use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class SchemaStatementProcedureTest method schemaStatementsShouldHandleConstraintWithBackticks.
@Test
void schemaStatementsShouldHandleConstraintWithBackticks() throws IndexNotFoundKernelException, ProcedureException, LabelNotFoundKernelException, PropertyKeyIdNotFoundKernelException {
ConstraintDescriptor constraint = ConstraintDescriptorFactory.existsForSchema(forLabel(1, 1)).withName(NAME_WITH_BACKTICKS);
SchemaReadCore schemaReadCore = getSchemaReadCore(constraint);
TokenRead tokenRead = mock(TokenRead.class);
when(tokenRead.nodeLabelName(1)).thenReturn(LABEL_WITH_BACKTICKS);
when(tokenRead.propertyKeyName(1)).thenReturn(PROPERTY_KEY_WITH_BACKTICKS);
Collection<BuiltInProcedures.SchemaStatementResult> result = createSchemaStatementResults(schemaReadCore, tokenRead);
Iterator<BuiltInProcedures.SchemaStatementResult> iter = result.iterator();
assertTrue(iter.hasNext());
BuiltInProcedures.SchemaStatementResult next = iter.next();
assertEquals(NAME_WITH_BACKTICKS, next.name);
assertEquals(format("CREATE CONSTRAINT %s ON (a:%s) ASSERT (a.%s) IS NOT NULL", ESCAPED_NAME_WITH_BACKTICKS, ESCAPED_LABEL_WITH_BACKTICKS, ESCAPED_PROPERTY_KEY_WITH_BACKTICKS), next.createStatement);
assertEquals(format("DROP CONSTRAINT %s", ESCAPED_NAME_WITH_BACKTICKS), next.dropStatement);
assertEquals(NAME_WITH_BACKTICKS, next.name);
assertFalse(iter.hasNext());
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class SchemaStatementProcedureTest method schemaStatementsMustOnlyIncludeIndexBackedConstraintNotActualIndex.
@Test
void schemaStatementsMustOnlyIncludeIndexBackedConstraintNotActualIndex() throws IndexNotFoundKernelException, ProcedureException {
IndexDescriptor index = someOrphanedIndex();
ConstraintDescriptor constraint = indexBackedConstraint(index);
index = indexBoundToConstraint(index, constraint);
InternalIndexState internalIndexState = InternalIndexState.ONLINE;
SchemaReadCore schemaReadCore = getSchemaReadCore(constraint, index, internalIndexState);
TokenRead tokenRead = mock(TokenRead.class);
Collection<BuiltInProcedures.SchemaStatementResult> result = createSchemaStatementResults(schemaReadCore, tokenRead);
Iterator<BuiltInProcedures.SchemaStatementResult> iter = result.iterator();
assertTrue(iter.hasNext());
BuiltInProcedures.SchemaStatementResult next = iter.next();
assertEquals(SchemaStatementProcedure.SchemaRuleType.CONSTRAINT.name(), next.type);
assertEquals(CONSTRAINT_NAME, next.name);
assertFalse(iter.hasNext());
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class TxStateTest method shouldDropRelationshipPropertyExistenceConstraint.
@Test
void shouldDropRelationshipPropertyExistenceConstraint() {
// Given
ConstraintDescriptor constraint = ConstraintDescriptorFactory.existsForRelType(1, 42);
state.constraintDoAdd(constraint);
// When
state.constraintDoDrop(constraint);
// Then
assertTrue(state.constraintsChangesForRelationshipType(1).isEmpty());
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class TxStateTest method addingRelationshipPropertyExistenceConstraintConstraintShouldBeIdempotent.
@Test
void addingRelationshipPropertyExistenceConstraintConstraintShouldBeIdempotent() {
// Given
ConstraintDescriptor constraint1 = ConstraintDescriptorFactory.existsForRelType(1, 42);
ConstraintDescriptor constraint2 = ConstraintDescriptorFactory.existsForRelType(1, 42);
// When
state.constraintDoAdd(constraint1);
state.constraintDoAdd(constraint2);
// Then
assertEquals(constraint1, constraint2);
assertEquals(singleton(constraint1), state.constraintsChangesForRelationshipType(1).getAdded());
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class TxStateTest method shouldDifferentiateRelationshipPropertyExistenceConstraints.
@Test
void shouldDifferentiateRelationshipPropertyExistenceConstraints() {
// Given
ConstraintDescriptor constraint1 = ConstraintDescriptorFactory.existsForRelType(1, 11);
ConstraintDescriptor constraint2 = ConstraintDescriptorFactory.existsForRelType(1, 22);
ConstraintDescriptor constraint3 = ConstraintDescriptorFactory.existsForRelType(3, 33);
// When
state.constraintDoAdd(constraint1);
state.constraintDoAdd(constraint2);
state.constraintDoAdd(constraint3);
// Then
assertEquals(asSet(constraint1, constraint2), state.constraintsChangesForRelationshipType(1).getAdded());
assertEquals(singleton(constraint1), state.constraintsChangesForSchema(constraint1.schema()).getAdded());
assertEquals(singleton(constraint2), state.constraintsChangesForSchema(constraint2.schema()).getAdded());
assertEquals(singleton(constraint3), state.constraintsChangesForRelationshipType(3).getAdded());
assertEquals(singleton(constraint3), state.constraintsChangesForSchema(constraint3.schema()).getAdded());
}
Aggregations