Search in sources :

Example 1 with SchemaKernelException

use of org.neo4j.kernel.api.exceptions.schema.SchemaKernelException in project neo4j by neo4j.

the class IndexIT method shouldFailToCreateIndexWhereAConstraintAlreadyExists.

@Test
public void shouldFailToCreateIndexWhereAConstraintAlreadyExists() throws Exception {
    // given
    {
        SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
        statement.uniquePropertyConstraintCreate(SchemaBoundary.map(descriptor));
        commit();
    }
    // when
    try {
        SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
        statement.indexCreate(SchemaBoundary.map(descriptor));
        commit();
        fail("expected exception");
    }// then
     catch (SchemaKernelException e) {
        assertEquals("Label '" + LABEL + "' and property '" + PROPERTY_KEY + "' have a unique constraint defined" + " on them, so an index is already created that matches this.", e.getMessage());
    }
}
Also used : SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations) SchemaKernelException(org.neo4j.kernel.api.exceptions.schema.SchemaKernelException) Test(org.junit.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 2 with SchemaKernelException

use of org.neo4j.kernel.api.exceptions.schema.SchemaKernelException in project neo4j by neo4j.

the class IndexIT method shouldDisallowDroppingIndexThatDoesNotExist.

@Test
public void shouldDisallowDroppingIndexThatDoesNotExist() throws Exception {
    // given
    NewIndexDescriptor index;
    {
        SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
        index = statement.indexCreate(SchemaBoundary.map(descriptor));
        commit();
    }
    {
        SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
        statement.indexDrop(index);
        commit();
    }
    // when
    try {
        SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
        statement.indexDrop(index);
        commit();
    }// then
     catch (SchemaKernelException e) {
        assertEquals("Unable to drop index on :label[" + labelId + "](property[" + propertyKeyId + "]): " + "No such INDEX ON :label[" + labelId + "](property[" + propertyKeyId + "]).", e.getMessage());
    }
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations) SchemaKernelException(org.neo4j.kernel.api.exceptions.schema.SchemaKernelException) Test(org.junit.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Aggregations

Test (org.junit.Test)2 SchemaWriteOperations (org.neo4j.kernel.api.SchemaWriteOperations)2 SchemaKernelException (org.neo4j.kernel.api.exceptions.schema.SchemaKernelException)2 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)2 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)1