Search in sources :

Example 11 with ResourceIterator

use of org.neo4j.graphdb.ResourceIterator in project elasticsearch-river-neo4j by sksamuel.

the class SimpleIndexingStrategyTest method thatNodePropertiesAreUsedAsFieldValues.

@Test
public void thatNodePropertiesAreUsedAsFieldValues() throws IOException {
    long id = new Random().nextInt(50000) + 1;
    Node node = mock(Node.class);
    when(node.getId()).thenReturn(id);
    when(node.getPropertyKeys()).thenReturn(Arrays.asList("name", "location", "band"));
    when(node.getProperty("name")).thenReturn("chris martin");
    when(node.getProperty("location")).thenReturn("hampstead");
    when(node.getProperty("band")).thenReturn("coldplay");
    when(node.hasLabel(DynamicLabel.label("User"))).thenReturn(true);
    when(node.getLabels()).thenReturn(new ResourceIterable<Label>() {

        @Override
        public ResourceIterator<Label> iterator() {
            return new ResourceIterator<Label>() {

                private List<Label> labels = Arrays.asList(DynamicLabel.label("User"), DynamicLabel.label("Swedish"));

                private int position = 0;

                @Override
                public void close() {
                }

                @Override
                public boolean hasNext() {
                    boolean result = false;
                    if (position < labels.size()) {
                        result = true;
                    }
                    return result;
                }

                @Override
                public Label next() {
                    Label label = labels.get(position);
                    position++;
                    return label;
                }

                @Override
                public void remove() {
                }
            };
        }
    });
    IndexRequest req = s.build("neo4j-index", "node", node, 12);
    assertEquals("neo4j-index", req.index());
    assertEquals("node", req.type());
    assertEquals(12, req.sourceAsMap().get("version"));
    assertEquals(String.valueOf(id), req.id());
    assertEquals(new ArrayList<String>() {

        {
            add("User");
            add("Swedish");
        }
    }, req.sourceAsMap().get("labels"));
    assertEquals("coldplay", req.sourceAsMap().get("band"));
    assertEquals("hampstead", req.sourceAsMap().get("location"));
    assertEquals("chris martin", req.sourceAsMap().get("name"));
}
Also used : Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) DynamicLabel(org.neo4j.graphdb.DynamicLabel) IndexRequest(org.elasticsearch.action.index.IndexRequest) Random(java.util.Random) ResourceIterator(org.neo4j.graphdb.ResourceIterator) Test(org.junit.Test)

Aggregations

ResourceIterator (org.neo4j.graphdb.ResourceIterator)11 File (java.io.File)5 Test (org.junit.Test)5 Map (java.util.Map)4 Label (org.neo4j.graphdb.Label)4 Node (org.neo4j.graphdb.Node)4 ArrayList (java.util.ArrayList)3 TimeUnit (java.util.concurrent.TimeUnit)3 Transaction (org.neo4j.graphdb.Transaction)3 GraphDatabaseSettings (org.neo4j.graphdb.factory.GraphDatabaseSettings)3 Config (org.neo4j.kernel.configuration.Config)3 GraphDatabaseFacade (org.neo4j.kernel.impl.factory.GraphDatabaseFacade)3 Clock (java.time.Clock)2 Future (java.util.concurrent.Future)2 Predicate (java.util.function.Predicate)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 After (org.junit.After)2 AfterClass (org.junit.AfterClass)2 Assert.fail (org.junit.Assert.fail)2 BeforeClass (org.junit.BeforeClass)2