use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class SchemaAcceptanceTest method constraintNamesInTransactionStateMustBeUniqueEvenWhenGenerated.
@Test
void constraintNamesInTransactionStateMustBeUniqueEvenWhenGenerated() {
try (Transaction tx = db.beginTx()) {
ConstraintDefinition constraint = tx.schema().constraintFor(label).assertPropertyIsUnique(propertyKey).create();
ConstraintCreator creator = tx.schema().constraintFor(otherLabel).assertPropertyIsUnique(secondPropertyKey).withName(constraint.getName());
ConstraintViolationException exception = assertThrows(ConstraintViolationException.class, creator::create);
assertThat(exception).hasMessageContaining(thereAlreadyExistsConstraintMessage(constraint.getName()));
tx.commit();
}
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class SchemaAcceptanceTest method constraintNamesCanContainBackTicks.
@Test
void constraintNamesCanContainBackTicks() {
try (Transaction tx = db.beginTx()) {
ConstraintCreator creator = tx.schema().constraintFor(label).withName("`a`b``").assertPropertyIsUnique(propertyKey);
creator.create();
tx.commit();
}
try (Transaction tx = db.beginTx()) {
final Iterable<IndexDefinition> indexes = tx.schema().getIndexes();
assertThat(count(indexes)).isEqualTo(1L);
assertEquals("`a`b``", indexes.iterator().next().getName());
final Iterable<ConstraintDefinition> constraints = tx.schema().getConstraints();
assertThat(count(constraints)).isEqualTo(1L);
assertEquals("`a`b``", constraints.iterator().next().getName());
tx.commit();
}
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class SchemaAcceptanceTest method shouldDropUniquenessConstraint.
@Test
void shouldDropUniquenessConstraint() {
// GIVEN
ConstraintDefinition constraint = createUniquenessConstraint(label, propertyKey);
// WHEN
dropConstraint(db, constraint);
// THEN
try (Transaction tx = db.beginTx()) {
assertThat(getConstraints(tx, label)).isEmpty();
}
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class SchemaAcceptanceTest method shouldCreateNamedUniquenessConstraint.
@Test
void shouldCreateNamedUniquenessConstraint() {
// When
ConstraintDefinition constraint = createUniquenessConstraint("MyConstraint", label, propertyKey);
// Then
try (Transaction tx = db.beginTx()) {
constraint = tx.schema().getConstraintByName(constraint.getName());
assertEquals(ConstraintType.UNIQUENESS, constraint.getConstraintType());
assertEquals(label.name(), constraint.getLabel().name());
assertEquals(asSet(propertyKey), Iterables.asSet(constraint.getPropertyKeys()));
assertEquals("MyConstraint", constraint.getName());
tx.commit();
}
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class SchemaAcceptanceTest method constraintNamesInTransactionStateMustBeUniqueEvenWhenGenerated2.
@Test
void constraintNamesInTransactionStateMustBeUniqueEvenWhenGenerated2() {
try (Transaction tx = db.beginTx()) {
ConstraintDefinition constraint = tx.schema().constraintFor(otherLabel).assertPropertyIsUnique(secondPropertyKey).withName("constraint_c8a3b28f").create();
ConstraintCreator creator = tx.schema().constraintFor(label).assertPropertyIsUnique(propertyKey);
ConstraintViolationException exception = assertThrows(ConstraintViolationException.class, creator::create);
assertThat(exception).hasMessageContaining(thereAlreadyExistsConstraintMessage(constraint.getName()));
tx.commit();
}
}
Aggregations