use of org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor in project neo4j by neo4j.
the class SchemaCacheTest method shouldListConstraintsForRelationshipType.
@Test
public void shouldListConstraintsForRelationshipType() {
// Given
ConstraintRule rule1 = relPropertyExistenceConstraintRule(0, 1, 1);
ConstraintRule rule2 = relPropertyExistenceConstraintRule(0, 2, 1);
ConstraintRule rule3 = relPropertyExistenceConstraintRule(0, 1, 2);
SchemaCache cache = newSchemaCache(rule1, rule2, rule3);
// When
Set<ConstraintDescriptor> listed = asSet(cache.constraintsForRelationshipType(1));
// Then
Set<ConstraintDescriptor> expected = asSet(rule1.getConstraintDescriptor(), rule3.getConstraintDescriptor());
assertEquals(expected, listed);
}
use of org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor in project neo4j by neo4j.
the class SchemaCacheTest method should_remove_constraints.
@Test
public void should_remove_constraints() {
// GIVEN
SchemaCache cache = newSchemaCache();
cache.addSchemaRule(uniquenessConstraintRule(0L, 1, 2, 133L));
cache.addSchemaRule(uniquenessConstraintRule(1L, 3, 4, 133L));
// WHEN
cache.removeSchemaRule(0L);
// THEN
ConstraintDescriptor dropped = ConstraintDescriptorFactory.uniqueForLabel(1, 1);
ConstraintDescriptor unique = ConstraintDescriptorFactory.uniqueForLabel(3, 4);
assertEquals(asSet(unique), asSet(cache.constraints()));
assertEquals(asSet(), asSet(cache.constraintsForLabel(1)));
assertEquals(asSet(), asSet(cache.constraintsForSchema(dropped.schema())));
}
use of org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor in project neo4j by neo4j.
the class SchemaCacheTest method should_list_constraints.
@Test
public void should_list_constraints() {
// GIVEN
SchemaCache cache = newSchemaCache();
// WHEN
cache.addSchemaRule(uniquenessConstraintRule(0L, 1, 2, 133L));
cache.addSchemaRule(uniquenessConstraintRule(1L, 3, 4, 133L));
cache.addSchemaRule(relPropertyExistenceConstraintRule(2L, 5, 6));
cache.addSchemaRule(nodePropertyExistenceConstraintRule(3L, 7, 8));
// THEN
ConstraintDescriptor unique1 = ConstraintDescriptorFactory.uniqueForLabel(1, 2);
ConstraintDescriptor unique2 = ConstraintDescriptorFactory.uniqueForLabel(3, 4);
ConstraintDescriptor existsRel = ConstraintDescriptorFactory.existsForRelType(5, 6);
ConstraintDescriptor existsNode = ConstraintDescriptorFactory.existsForLabel(7, 8);
assertEquals(asSet(unique1, unique2, existsRel, existsNode), asSet(cache.constraints()));
assertEquals(asSet(unique1), asSet(cache.constraintsForLabel(1)));
assertEquals(asSet(unique1), asSet(cache.constraintsForSchema(unique1.schema())));
assertEquals(asSet(), asSet(cache.constraintsForSchema(SchemaDescriptorFactory.forLabel(1, 3))));
assertEquals(asSet(existsRel), asSet(cache.constraintsForRelationshipType(5)));
}
use of org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor in project neo4j by neo4j.
the class SchemaCacheTest method shouldListConstraintsForSchema.
@Test
public void shouldListConstraintsForSchema() {
// Given
ConstraintRule rule1 = uniquenessConstraintRule(0, 1, 1, 0);
ConstraintRule rule2 = uniquenessConstraintRule(1, 2, 1, 0);
ConstraintRule rule3 = nodePropertyExistenceConstraintRule(2, 1, 2);
SchemaCache cache = newSchemaCache(rule1, rule2, rule3);
// When
Set<ConstraintDescriptor> listed = asSet(cache.constraintsForSchema(rule3.schema()));
// Then
assertEquals(singleton(rule3.getConstraintDescriptor()), listed);
}
use of org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor in project neo4j by neo4j.
the class SchemaCacheTest method shouldListConstraintsForLabel.
@Test
public void shouldListConstraintsForLabel() {
// Given
ConstraintRule rule1 = uniquenessConstraintRule(0, 1, 1, 0);
ConstraintRule rule2 = uniquenessConstraintRule(1, 2, 1, 0);
ConstraintRule rule3 = nodePropertyExistenceConstraintRule(2, 1, 2);
SchemaCache cache = newSchemaCache(rule1, rule2, rule3);
// When
Set<ConstraintDescriptor> listed = asSet(cache.constraintsForLabel(1));
// Then
Set<ConstraintDescriptor> expected = asSet(rule1.getConstraintDescriptor(), rule3.getConstraintDescriptor());
assertEquals(expected, listed);
}
Aggregations