use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class SchemaIndexIT method createIndex.
private IndexDefinition createIndex(String labelName, String propertyKey) {
try (Transaction tx = graphdb().beginTx()) {
IndexDefinition indexDefinition = graphdb().schema().indexFor(label(labelName)).on(propertyKey).create();
tx.success();
return indexDefinition;
}
}
use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class SchemaIndexRepresentationTest method shouldIncludeLabel.
@Test
public void shouldIncludeLabel() throws Exception {
// GIVEN
String labelName = "person", propertyKey = "name";
IndexDefinition definition = mock(IndexDefinition.class);
when(definition.getLabel()).thenReturn(label(labelName));
when(definition.getPropertyKeys()).thenReturn(asList(propertyKey));
IndexDefinitionRepresentation representation = new IndexDefinitionRepresentation(definition);
Map<String, Object> serialized = RepresentationTestAccess.serialize(representation);
// THEN
assertEquals(asList(propertyKey), serialized.get("property_keys"));
assertEquals(labelName, serialized.get("label"));
}
use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class DatabaseActionsTest method shouldDropSchemaIndex.
@Test
public void shouldDropSchemaIndex() throws Exception {
// GIVEN
String labelName = "user", propertyKey = "login";
IndexDefinition index = graphdbHelper.createSchemaIndex(labelName, propertyKey);
// WHEN
actions.dropSchemaIndex(labelName, propertyKey);
// THEN
try (Transaction transaction = graph.beginTx()) {
assertFalse("Index should have been dropped", Iterables.asSet(graphdbHelper.getSchemaIndexes(labelName)).contains(index));
}
}
use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class DatabaseActionsTest method shouldCreateSchemaIndex.
@Test
public void shouldCreateSchemaIndex() throws Exception {
// GIVEN
String labelName = "person", propertyKey = "name";
// WHEN
actions.createSchemaIndex(labelName, Arrays.asList(propertyKey));
// THEN
try (Transaction transaction = graph.beginTx()) {
Iterable<IndexDefinition> defs = graphdbHelper.getSchemaIndexes(labelName);
assertEquals(1, Iterables.count(defs));
assertEquals(propertyKey, firstOrNull(firstOrNull(defs).getPropertyKeys()));
}
}
Aggregations