Search in sources :

Example 71 with ByteArrayOutputStream

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")));
}
Also used : PrintStream(java.io.PrintStream) Graph(com.tinkerpop.blueprints.Graph) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 72 with ByteArrayOutputStream

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());
}
Also used : Graph(com.tinkerpop.blueprints.Graph) JsonNode(com.fasterxml.jackson.databind.JsonNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 73 with ByteArrayOutputStream

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"));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 74 with ByteArrayOutputStream

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")));
}
Also used : PrintStream(java.io.PrintStream) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 75 with ByteArrayOutputStream

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")));
}
Also used : PrintStream(java.io.PrintStream) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)8438 Test (org.junit.Test)2232 ByteArrayInputStream (java.io.ByteArrayInputStream)2148 IOException (java.io.IOException)2037 PrintStream (java.io.PrintStream)800 InputStream (java.io.InputStream)765 ObjectOutputStream (java.io.ObjectOutputStream)759 DataOutputStream (java.io.DataOutputStream)705 ObjectInputStream (java.io.ObjectInputStream)361 File (java.io.File)331 OutputStream (java.io.OutputStream)318 HashMap (java.util.HashMap)279 ArrayList (java.util.ArrayList)264 FileInputStream (java.io.FileInputStream)211 OutputStreamWriter (java.io.OutputStreamWriter)207 DataInputStream (java.io.DataInputStream)198 Test (org.testng.annotations.Test)184 PrintWriter (java.io.PrintWriter)162 URL (java.net.URL)160 Map (java.util.Map)158