use of org.neo4j.kernel.api.SchemaWriteOperations in project neo4j by neo4j.
the class AbstractConstraintCreationIT method shouldNotCreateConstraintThatAlreadyExists.
@Test
public void shouldNotCreateConstraintThatAlreadyExists() throws Exception {
// given
{
SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
createConstraint(statement, descriptor);
commit();
}
// when
try {
SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
createConstraint(statement, descriptor);
fail("Should not have validated");
}// then
catch (AlreadyConstrainedException e) {
// good
}
}
use of org.neo4j.kernel.api.SchemaWriteOperations in project neo4j by neo4j.
the class AbstractConstraintCreationIT method shouldNotPersistConstraintCreatedInAbortedTransaction.
@Test
public void shouldNotPersistConstraintCreatedInAbortedTransaction() throws Exception {
// given
SchemaWriteOperations schemaWriteOperations = schemaWriteOperationsInNewTransaction();
createConstraint(schemaWriteOperations, descriptor);
// when
rollback();
ReadOperations readOperations = readOperationsInNewTransaction();
// then
Iterator<?> constraints = readOperations.constraintsGetAll();
assertFalse("should not have any constraints", constraints.hasNext());
}
use of org.neo4j.kernel.api.SchemaWriteOperations in project neo4j by neo4j.
the class NodePropertyExistenceConstraintCreationIT method shouldNotDropPropertyExistenceConstraintThatDoesNotExistWhenThereIsAUniquePropertyConstraint.
@Test
public void shouldNotDropPropertyExistenceConstraintThatDoesNotExistWhenThereIsAUniquePropertyConstraint() throws Exception {
// given
UniquenessConstraintDescriptor constraint;
{
SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
constraint = statement.uniquePropertyConstraintCreate(descriptor);
commit();
}
// when
try {
SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
statement.constraintDrop(ConstraintDescriptorFactory.existsForSchema(constraint.schema()));
fail("expected exception");
}// then
catch (DropConstraintFailureException e) {
assertThat(e.getCause(), instanceOf(NoSuchConstraintException.class));
} finally {
rollback();
}
// then
{
ReadOperations statement = readOperationsInNewTransaction();
Iterator<ConstraintDescriptor> constraints = statement.constraintsGetForSchema(descriptor);
assertEquals(constraint, single(constraints));
}
}
use of org.neo4j.kernel.api.SchemaWriteOperations in project neo4j by neo4j.
the class UniquenessConstraintCreationIT method shouldAbortConstraintCreationWhenDuplicatesExist.
@Test
public void shouldAbortConstraintCreationWhenDuplicatesExist() throws Exception {
// given
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
// name is not unique for Foo in the existing data
int foo = statement.tokenWriteOperations().labelGetOrCreateForName("Foo");
int name = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("name");
long node1 = statement.dataWriteOperations().nodeCreate();
statement.dataWriteOperations().nodeAddLabel(node1, foo);
statement.dataWriteOperations().nodeSetProperty(node1, Property.stringProperty(name, "foo"));
long node2 = statement.dataWriteOperations().nodeCreate();
statement.dataWriteOperations().nodeAddLabel(node2, foo);
statement.dataWriteOperations().nodeSetProperty(node2, Property.stringProperty(name, "foo"));
commit();
// when
LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(foo, name);
try {
SchemaWriteOperations schemaWriteOperations = schemaWriteOperationsInNewTransaction();
schemaWriteOperations.uniquePropertyConstraintCreate(descriptor);
fail("expected exception");
}// then
catch (CreateConstraintFailureException ex) {
assertEquals(ConstraintDescriptorFactory.uniqueForSchema(descriptor), ex.constraint());
Throwable cause = ex.getCause();
assertThat(cause, instanceOf(ConstraintValidationException.class));
String expectedMessage = String.format("Both Node(%d) and Node(%d) have the label `Foo` and property `name` = 'foo'", node1, node2);
String actualMessage = userMessage((ConstraintValidationException) cause);
assertEquals(expectedMessage, actualMessage);
}
}
use of org.neo4j.kernel.api.SchemaWriteOperations in project neo4j by neo4j.
the class UniquenessConstraintCreationIT method shouldNotDropUniquePropertyConstraintThatDoesNotExistWhenThereIsAPropertyExistenceConstraint.
@Test
public void shouldNotDropUniquePropertyConstraintThatDoesNotExistWhenThereIsAPropertyExistenceConstraint() throws Exception {
// given
SchemaWriteOperations schemaWriteOperations = schemaWriteOperationsInNewTransaction();
schemaWriteOperations.nodePropertyExistenceConstraintCreate(descriptor);
commit();
// when
try {
SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
statement.constraintDrop(ConstraintDescriptorFactory.uniqueForSchema(descriptor));
fail("expected exception");
}// then
catch (DropConstraintFailureException e) {
assertThat(e.getCause(), instanceOf(NoSuchConstraintException.class));
} finally {
rollback();
}
// then
{
ReadOperations statement = readOperationsInNewTransaction();
Iterator<ConstraintDescriptor> constraints = statement.constraintsGetForSchema(descriptor);
assertEquals(ConstraintDescriptorFactory.existsForSchema(descriptor), single(constraints));
}
}
Aggregations