Search in sources :

Example 6 with ConstraintDefinition

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();
    }
}
Also used : ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition) Test(org.junit.Test)

Example 7 with ConstraintDefinition

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();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition) NodeRepresentationTest(org.neo4j.server.rest.repr.NodeRepresentationTest) RelationshipRepresentationTest(org.neo4j.server.rest.repr.RelationshipRepresentationTest) Test(org.junit.Test)

Example 8 with ConstraintDefinition

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));
}
Also used : ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition) NodeRepresentationTest(org.neo4j.server.rest.repr.NodeRepresentationTest) RelationshipRepresentationTest(org.neo4j.server.rest.repr.RelationshipRepresentationTest) Test(org.junit.Test)

Example 9 with ConstraintDefinition

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();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition) NodeRepresentationTest(org.neo4j.server.rest.repr.NodeRepresentationTest) RelationshipRepresentationTest(org.neo4j.server.rest.repr.RelationshipRepresentationTest) Test(org.junit.Test)

Example 10 with ConstraintDefinition

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");
    }
}
Also used : ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition)

Aggregations

ConstraintDefinition (org.neo4j.graphdb.schema.ConstraintDefinition)34 Test (org.junit.Test)16 Transaction (org.neo4j.graphdb.Transaction)12 NodePropertyExistenceConstraintDefinition (org.neo4j.kernel.impl.coreapi.schema.NodePropertyExistenceConstraintDefinition)5 RelationshipPropertyExistenceConstraintDefinition (org.neo4j.kernel.impl.coreapi.schema.RelationshipPropertyExistenceConstraintDefinition)5 UniquenessConstraintDefinition (org.neo4j.kernel.impl.coreapi.schema.UniquenessConstraintDefinition)5 NodeRepresentationTest (org.neo4j.server.rest.repr.NodeRepresentationTest)3 RelationshipRepresentationTest (org.neo4j.server.rest.repr.RelationshipRepresentationTest)3 ArrayList (java.util.ArrayList)2 ConstraintCreator (org.neo4j.graphdb.schema.ConstraintCreator)2 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)2 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)2 BatchInserter (org.neo4j.unsafe.batchinsert.BatchInserter)2 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 Label (org.neo4j.graphdb.Label)1 RelationshipType (org.neo4j.graphdb.RelationshipType)1 Schema (org.neo4j.graphdb.schema.Schema)1 ConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor)1 Documented (org.neo4j.kernel.impl.annotations.Documented)1