use of org.neo4j.graphdb.ConstraintViolationException in project neo4j by neo4j.
the class BatchInsertTest method shouldNotAllowDuplicatedIndexes.
@Test
public void shouldNotAllowDuplicatedIndexes() throws Exception {
// Given
Label label = label("Person3-" + denseNodeThreshold);
String property = "name";
BatchInserter inserter = globalInserter;
// When
inserter.createDeferredSchemaIndex(label).on(property).create();
try {
inserter.createDeferredSchemaIndex(label).on(property).create();
fail("Exception expected");
} catch (ConstraintViolationException e) {
// Then
assertEquals("Index for given {label;property} already exists", e.getMessage());
}
}
use of org.neo4j.graphdb.ConstraintViolationException in project neo4j by neo4j.
the class BatchInsertTest method shouldNotAllowCreationOfDuplicateConstraint.
@Test
public void shouldNotAllowCreationOfDuplicateConstraint() throws Exception {
// GIVEN
BatchInserter inserter = globalInserter;
String labelName = "Hacker2-" + denseNodeThreshold;
// WHEN
inserter.createDeferredConstraint(label(labelName)).assertPropertyIsUnique("handle").create();
try {
inserter.createDeferredConstraint(label(labelName)).assertPropertyIsUnique("handle").create();
fail("Should have thrown exception.");
} catch (ConstraintViolationException e) {
// THEN Good
}
}
use of org.neo4j.graphdb.ConstraintViolationException in project neo4j by neo4j.
the class BatchInsertTest method shouldCreateUniquenessConstraint.
@Test
public void shouldCreateUniquenessConstraint() throws Exception {
// Given
Label label = label("Person");
String propertyKey = "name";
String duplicatedValue = "Tom";
BatchInserter inserter = newBatchInserter();
// When
inserter.createDeferredConstraint(label).assertPropertyIsUnique(propertyKey).create();
// Then
GraphDatabaseService db = switchToEmbeddedGraphDatabaseService(inserter);
try {
try (Transaction tx = db.beginTx()) {
List<ConstraintDefinition> constraints = Iterables.asList(db.schema().getConstraints());
assertEquals(1, constraints.size());
ConstraintDefinition constraint = constraints.get(0);
assertEquals(label.name(), constraint.getLabel().name());
assertEquals(propertyKey, single(constraint.getPropertyKeys()));
db.createNode(label).setProperty(propertyKey, duplicatedValue);
tx.success();
}
try (Transaction tx = db.beginTx()) {
db.createNode(label).setProperty(propertyKey, duplicatedValue);
tx.success();
}
fail("Uniqueness property constraint was violated, exception expected");
} catch (ConstraintViolationException e) {
assertEquals(format("Node(0) already exists with label `%s` and property `%s` = '%s'", label.name(), propertyKey, duplicatedValue), e.getMessage());
} finally {
db.shutdown();
}
}
use of org.neo4j.graphdb.ConstraintViolationException in project neo4j by neo4j.
the class BatchInsertTest method shouldNotAllowCreationOfUniquenessConstraintAndIndexOnSameLabelAndProperty.
@Test
public void shouldNotAllowCreationOfUniquenessConstraintAndIndexOnSameLabelAndProperty() throws Exception {
// Given
Label label = label("Person1-" + denseNodeThreshold);
String property = "name";
BatchInserter inserter = globalInserter;
// When
inserter.createDeferredConstraint(label).assertPropertyIsUnique(property).create();
try {
inserter.createDeferredSchemaIndex(label).on(property).create();
fail("Exception expected");
} catch (ConstraintViolationException e) {
// Then
assertEquals("Index for given {label;property} already exists", e.getMessage());
}
}
use of org.neo4j.graphdb.ConstraintViolationException in project neo4j by neo4j.
the class BatchInsertTest method shouldNotAllowCreationOfDeferredSchemaConstraintAfterIndexOnSameKeys.
@Test
public void shouldNotAllowCreationOfDeferredSchemaConstraintAfterIndexOnSameKeys() throws Exception {
// GIVEN
BatchInserter inserter = globalInserter;
String labelName = "Hacker3-" + denseNodeThreshold;
// WHEN
inserter.createDeferredSchemaIndex(label(labelName)).on("handle").create();
try {
inserter.createDeferredConstraint(label(labelName)).assertPropertyIsUnique("handle").create();
fail("Should have thrown exception.");
} catch (ConstraintViolationException e) {
// THEN Good
}
}
Aggregations