コード例 #1
0
  @Test
  public void testGettingAutoIndexByNameReturnsSomethingReadOnly() {
    // Create the node and relationship auto-indexes
    graphDb.index().getNodeAutoIndexer().setEnabled(true);
    graphDb.index().getNodeAutoIndexer().startAutoIndexingProperty("nodeProp");
    graphDb.index().getRelationshipAutoIndexer().setEnabled(true);
    graphDb.index().getRelationshipAutoIndexer().startAutoIndexingProperty("relProp");

    newTransaction();

    Node node1 = graphDb.createNode();
    Node node2 = graphDb.createNode();
    Relationship rel = node1.createRelationshipTo(node2, DynamicRelationshipType.withName("FOO"));
    node1.setProperty("nodeProp", "nodePropValue");
    rel.setProperty("relProp", "relPropValue");

    newTransaction();

    assertEquals(1, graphDb.index().nodeIndexNames().length);
    assertEquals(1, graphDb.index().relationshipIndexNames().length);

    assertEquals("node_auto_index", graphDb.index().nodeIndexNames()[0]);
    assertEquals("relationship_auto_index", graphDb.index().relationshipIndexNames()[0]);

    Index<Node> nodeIndex = graphDb.index().forNodes("node_auto_index");
    RelationshipIndex relIndex = graphDb.index().forRelationships("relationship_auto_index");
    assertEquals(node1, nodeIndex.get("nodeProp", "nodePropValue").getSingle());
    assertEquals(rel, relIndex.get("relProp", "relPropValue").getSingle());
    try {
      nodeIndex.add(null, null, null);
      fail("Auto indexes should not allow external manipulation");
    } catch (UnsupportedOperationException e) { // good
    }

    try {
      relIndex.add(null, null, null);
      fail("Auto indexes should not allow external manipulation");
    } catch (UnsupportedOperationException e) { // good
    }
  }