use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class SchemaAcceptanceTest method shouldCreateUniquenessConstraint.
@Test
public void shouldCreateUniquenessConstraint() throws Exception {
// WHEN
ConstraintDefinition constraint = createUniquenessConstraint(label, propertyKey);
// THEN
try (Transaction tx = db.beginTx()) {
assertEquals(ConstraintType.UNIQUENESS, constraint.getConstraintType());
assertEquals(label.name(), constraint.getLabel().name());
assertEquals(asSet(propertyKey), Iterables.asSet(constraint.getPropertyKeys()));
tx.success();
}
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class DatabaseActionsTest method shouldCreatePropertyUniquenessConstraint.
@Test
public void shouldCreatePropertyUniquenessConstraint() throws Exception {
// GIVEN
String labelName = "person", propertyKey = "name";
// WHEN
actions.createPropertyUniquenessConstraint(labelName, asList(propertyKey));
// THEN
try (Transaction tx = graph.beginTx()) {
Iterable<ConstraintDefinition> defs = graphdbHelper.getPropertyUniquenessConstraints(labelName, propertyKey);
assertEquals(asSet(propertyKey), Iterables.asSet(single(defs).getPropertyKeys()));
tx.success();
}
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class DatabaseActionsTest method shouldDropPropertyUniquenessConstraint.
@Test
public void shouldDropPropertyUniquenessConstraint() throws Exception {
// GIVEN
String labelName = "user", propertyKey = "login";
ConstraintDefinition index = graphdbHelper.createPropertyUniquenessConstraint(labelName, asList(propertyKey));
// WHEN
actions.dropPropertyUniquenessConstraint(labelName, asList(propertyKey));
// THEN
assertFalse("Constraint should have been dropped", Iterables.asSet(graphdbHelper.getPropertyUniquenessConstraints(labelName, propertyKey)).contains(index));
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class DatabaseActionsTest method dropNonExistentConstraint.
@Test
public void dropNonExistentConstraint() throws Exception {
// GIVEN
String labelName = "user", propertyKey = "login";
ConstraintDefinition constraint = graphdbHelper.createPropertyUniquenessConstraint(labelName, asList(propertyKey));
// EXPECT
expectedException.expect(ConstraintViolationException.class);
// WHEN
try (Transaction tx = graph.beginTx()) {
constraint.drop();
constraint.drop();
}
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class Schema method reportConstraints.
private void reportConstraints(Output out, Iterable<ConstraintDefinition> constraints) throws RemoteException {
int j = 0;
for (ConstraintDefinition constraint : constraints) {
if (j == 0) {
out.println();
out.println("Constraints");
}
out.println(indent(constraint.toString()));
j++;
}
if (j == 0) {
out.println();
out.println("No constraints");
}
}
Aggregations