use of java.io.ByteArrayOutputStream in project blueprints by tinkerpop.
the class GraphSONWriterTest method streamStaysOpen.
@Test
public void streamStaysOpen() throws JSONException, IOException {
final Graph g = TinkerGraphFactory.createTinkerGraph();
final PrintStream oldStream = System.out;
final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
final GraphSONWriter writer = new GraphSONWriter(g);
writer.outputGraph(System.out, null, null, GraphSONMode.NORMAL);
System.out.println("working");
System.setOut(oldStream);
Assert.assertTrue(outContent.toString().endsWith("working" + System.getProperty("line.separator")));
}
use of java.io.ByteArrayOutputStream in project blueprints by tinkerpop.
the class GraphSONWriterTest method outputGraphNoEmbeddedTypes.
@Test
public void outputGraphNoEmbeddedTypes() throws JSONException, IOException {
Graph g = TinkerGraphFactory.createTinkerGraph();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
GraphSONWriter writer = new GraphSONWriter(g);
writer.outputGraph(stream, null, null, GraphSONMode.NORMAL);
stream.flush();
stream.close();
String jsonString = new String(stream.toByteArray());
ObjectMapper m = new ObjectMapper();
JsonNode rootNode = m.readValue(jsonString, JsonNode.class);
// ensure that the JSON conforms to basic structure and that the right
// number of graph elements are present. other tests already cover element formatting
Assert.assertNotNull(rootNode);
Assert.assertTrue(rootNode.has(GraphSONTokens.MODE));
Assert.assertEquals("NORMAL", rootNode.get(GraphSONTokens.MODE).asText());
Assert.assertTrue(rootNode.has(GraphSONTokens.VERTICES));
ArrayNode vertices = (ArrayNode) rootNode.get(GraphSONTokens.VERTICES);
Assert.assertEquals(6, vertices.size());
Assert.assertTrue(rootNode.has(GraphSONTokens.EDGES));
ArrayNode edges = (ArrayNode) rootNode.get(GraphSONTokens.EDGES);
Assert.assertEquals(6, edges.size());
}
use of java.io.ByteArrayOutputStream in project blueprints by tinkerpop.
the class GMLWriterTest method testWriteStringPropertyWithQuotationMarks.
/**
* This tests checks, if quotation marks (") are escaped correctly, before
* they are written to the GML file.
* @throws Exception if something fails
*/
public void testWriteStringPropertyWithQuotationMarks() throws Exception {
TinkerGraph g1 = TinkerGraphFactory.createTinkerGraph();
Vertex v = g1.getVertex(1);
v.setProperty("escape_property", "quotation \"quote\" quotation end");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
GMLWriter w = new GMLWriter(g1);
w.setUseId(true);
w.outputGraph(bos);
String gmlOutput = bos.toString();
Assert.assertNotNull(gmlOutput);
String message = "escaped_property was not escaped properly";
Assert.assertTrue(message, gmlOutput.contains("quotation \\\"quote\\\" quotation end"));
}
use of java.io.ByteArrayOutputStream in project blueprints by tinkerpop.
the class GMLWriterTest method testStreamStaysOpen.
public void testStreamStaysOpen() throws IOException {
final Graph g = TinkerGraphFactory.createTinkerGraph();
final PrintStream oldStream = System.out;
final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
final GMLWriter writer = new GMLWriter(g);
writer.outputGraph(System.out);
System.out.println("working");
System.setOut(oldStream);
assertTrue(outContent.toString().endsWith("working" + System.getProperty("line.separator")));
}
use of java.io.ByteArrayOutputStream in project blueprints by tinkerpop.
the class GraphMLWriterTest method testStreamStaysOpen.
public void testStreamStaysOpen() throws IOException {
final Graph g = TinkerGraphFactory.createTinkerGraph();
final PrintStream oldStream = System.out;
final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
final GraphMLWriter writer = new GraphMLWriter(g);
writer.outputGraph(System.out);
System.out.println("working");
System.setOut(oldStream);
assertTrue(outContent.toString().endsWith("working" + System.getProperty("line.separator")));
}
Aggregations