Search in sources :

Example 6 with PropertyContainer

use of org.neo4j.graphdb.PropertyContainer in project neo4j by neo4j.

the class Neo4jJsonCodecTest method testIteratorWriting.

@Test
public void testIteratorWriting() throws IOException {
    //Given
    PropertyContainer propertyContainer = mock(PropertyContainer.class);
    when(propertyContainer.getAllProperties()).thenThrow(RuntimeException.class);
    //When
    try {
        jsonCodec.writeValue(jsonGenerator, Arrays.asList(propertyContainer));
    } catch (Exception ignored) {
    }
    //Then
    verify(jsonGenerator, times(1)).writeEndArray();
}
Also used : PropertyContainer(org.neo4j.graphdb.PropertyContainer) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with PropertyContainer

use of org.neo4j.graphdb.PropertyContainer in project neo4j by neo4j.

the class Neo4jJsonCodecTest method testPropertyContainerWriting.

@Test
public void testPropertyContainerWriting() throws IOException {
    //Given
    PropertyContainer propertyContainer = mock(PropertyContainer.class);
    when(propertyContainer.getAllProperties()).thenThrow(RuntimeException.class);
    boolean exceptionThrown = false;
    //When
    try {
        jsonCodec.writeValue(jsonGenerator, propertyContainer);
    } catch (IllegalArgumentException e) {
        //Then
        verify(jsonGenerator, times(0)).writeEndObject();
        exceptionThrown = true;
    }
    assertTrue(exceptionThrown);
}
Also used : PropertyContainer(org.neo4j.graphdb.PropertyContainer) Test(org.junit.Test)

Example 8 with PropertyContainer

use of org.neo4j.graphdb.PropertyContainer in project neo4j by neo4j.

the class Neo4jJsonCodecTest method testRelationshipWriting.

@Test
public void testRelationshipWriting() throws IOException {
    //Given
    PropertyContainer relationship = mock(Relationship.class);
    when(relationship.getAllProperties()).thenThrow(RuntimeException.class);
    //When
    try {
        jsonCodec.writeValue(jsonGenerator, relationship);
    } catch (Exception e) {
    // do nothing
    }
    //Then
    verify(jsonGenerator, times(1)).writeEndObject();
}
Also used : PropertyContainer(org.neo4j.graphdb.PropertyContainer) IOException(java.io.IOException) Test(org.junit.Test)

Example 9 with PropertyContainer

use of org.neo4j.graphdb.PropertyContainer in project neo4j by neo4j.

the class Neo4jJsonCodecTest method testNodeWriting.

@Test
public void testNodeWriting() throws IOException {
    //Given
    PropertyContainer node = mock(Node.class);
    when(node.getAllProperties()).thenThrow(RuntimeException.class);
    //When
    try {
        jsonCodec.writeValue(jsonGenerator, node);
    } catch (RuntimeException e) {
    // do nothing
    }
    //Then
    verify(jsonGenerator, times(1)).writeEndObject();
}
Also used : PropertyContainer(org.neo4j.graphdb.PropertyContainer) Test(org.junit.Test)

Example 10 with PropertyContainer

use of org.neo4j.graphdb.PropertyContainer in project neo4j by neo4j.

the class Neo4jJsonCodec method writeValue.

@Override
public void writeValue(JsonGenerator out, Object value) throws IOException {
    if (value instanceof PropertyContainer) {
        writePropertyContainer(out, (PropertyContainer) value, TransactionStateChecker.create(container));
    } else if (value instanceof Path) {
        writePath(out, ((Path) value).iterator(), TransactionStateChecker.create(container));
    } else if (value instanceof Iterable) {
        writeIterator(out, ((Iterable) value).iterator());
    } else if (value instanceof byte[]) {
        writeByteArray(out, (byte[]) value);
    } else if (value instanceof Map) {
        writeMap(out, (Map) value);
    } else if (value instanceof Geometry) {
        Geometry geom = (Geometry) value;
        Object coordinates = (geom instanceof Point) ? ((Point) geom).getCoordinate() : geom.getCoordinates();
        writeMap(out, genericMap(new LinkedHashMap<>(), "type", geom.getGeometryType(), "coordinates", coordinates, "crs", geom.getCRS()));
    } else if (value instanceof Coordinate) {
        Coordinate coordinate = (Coordinate) value;
        writeIterator(out, coordinate.getCoordinate().iterator());
    } else if (value instanceof CRS) {
        CRS crs = (CRS) value;
        writeMap(out, genericMap(new LinkedHashMap<>(), "name", crs.getType(), "type", "link", "properties", genericMap(new LinkedHashMap<>(), "href", crs.getHref() + "ogcwkt/", "type", "ogcwkt")));
    } else {
        super.writeValue(out, value);
    }
}
Also used : Path(org.neo4j.graphdb.Path) Geometry(org.neo4j.graphdb.spatial.Geometry) PropertyContainer(org.neo4j.graphdb.PropertyContainer) Coordinate(org.neo4j.graphdb.spatial.Coordinate) CRS(org.neo4j.graphdb.spatial.CRS) Point(org.neo4j.graphdb.spatial.Point) LinkedHashMap(java.util.LinkedHashMap) MapUtil.genericMap(org.neo4j.helpers.collection.MapUtil.genericMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

PropertyContainer (org.neo4j.graphdb.PropertyContainer)36 Test (org.junit.Test)11 Node (org.neo4j.graphdb.Node)11 LinkedList (java.util.LinkedList)8 Relationship (org.neo4j.graphdb.Relationship)7 Transaction (org.neo4j.graphdb.Transaction)6 HashSet (java.util.HashSet)4 IOException (java.io.IOException)3 List (java.util.List)3 Map (java.util.Map)3 GraphDatabaseAPI (org.neo4j.kernel.GraphDatabaseAPI)3 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)3 HashMap (java.util.HashMap)2 SystemException (javax.transaction.SystemException)2 NotFoundException (org.neo4j.graphdb.NotFoundException)2 Path (org.neo4j.graphdb.Path)2 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)2 ArrayBackedList (apoc.util.ArrayBackedList)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1