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();
}
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);
}
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();
}
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();
}
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);
}
}
Aggregations