GraphvizEngine { public String execute(String src) throws IOException, GraphvizException { return execute(src, Options.create()); } GraphvizEngine();  GraphvizEngine(String graphvizVersion); String execute(String src); String execute(String src, Options options); void close();  }
@Test public void happyFlowDot2SVG() throws IOException, GraphvizException { GraphvizEngine engine = new GraphvizEngine(); assertNotNull(engine); String result = engine.execute(dot); URL svg = ClassUtils.getResourceURL(classLoader, "flow.svg"); assertNotNull(svg); assertEqualsIgnoreWhitespaces(Misc.streamToString(svg.openStream()), result); }
@Test public void happyFlowRender2SVG() throws IOException, GraphvizException { GraphvizEngine engine = new GraphvizEngine(); assertNotNull(engine); String render = "render('" + dot + "'," + Options.create().toJson(false) + ");"; String result = engine.execute(render); URL svg = ClassUtils.getResourceURL(classLoader, "flow.svg"); assertNotNull(svg); assertEqualsIgnoreWhitespaces(Misc.streamToString(svg.openStream()), result); }
@Test public void happyFlowDot2SVG_STANDALONE() throws IOException, GraphvizException { GraphvizEngine engine = new GraphvizEngine(); assertNotNull(engine); String result = engine.execute(dot, Options.create().format(Format.SVG_STANDALONE)); URL svg = ClassUtils.getResourceURL(classLoader, "flow.svg_standalone"); assertNotNull(svg); assertEqualsIgnoreWhitespaces(Misc.streamToString(svg.openStream()), result); }
@Test public void happyFlowRender2SVG_STANDALONE() throws IOException, GraphvizException { GraphvizEngine engine = new GraphvizEngine(); assertNotNull(engine); Options options = Options.create().format(Format.SVG_STANDALONE); assertEquals("{format:'SVG_STANDALONE',engine:'dot'}", options.toJson(true)); assertEquals("{format:'svg',engine:'dot'}", options.toJson(false)); String render = "render('" + dot + "'," + options.toJson(false) + ");"; String result = engine.execute(render, options); URL svg = ClassUtils.getResourceURL(classLoader, "flow.svg_standalone"); assertNotNull(svg); assertEqualsIgnoreWhitespaces(Misc.streamToString(svg.openStream()), result); }
@Test public void happyFlowDot2SVGCustomOptions() throws IOException, GraphvizException { GraphvizEngine engine = new GraphvizEngine(); assertNotNull(engine); String result = engine.execute(dot, Options.create().format(Format.SVG)); assertNotNull(result); URL svg = ClassUtils.getResourceURL(classLoader, "flow.svg"); assertNotNull(svg); assertEqualsIgnoreWhitespaces(Misc.streamToString(svg.openStream()), result); }
@Test(expected = IOException.class) public void getUnknownVizJsVersion() throws IOException, GraphvizException { GraphvizEngine engine = new GraphvizEngine("1.2.3"); assertNotNull(engine); engine.execute(dot); }
@Test(expected = GraphvizException.class) public void getFaultyDot() throws IOException, GraphvizException { GraphvizEngine engine = new GraphvizEngine(); assertNotNull(engine); engine.execute("i'm not a dot!"); }
@Test public void smallerFontSize() throws IOException, GraphvizException { GraphvizEngine engine = new GraphvizEngine(); assertNotNull(engine); Options options = Options.create(); options.fontAdjust(0.5); String result = engine.execute(dot, options); assertNotNull(result); URL svg = ClassUtils.getResourceURL(classLoader, "flow.0.5.svg"); assertNotNull(svg); assertEqualsIgnoreWhitespaces(Misc.streamToString(svg.openStream()), result); }
@Test public void largerFontSize() throws IOException, GraphvizException { GraphvizEngine engine = new GraphvizEngine(); assertNotNull(engine); Options options = Options.create(); options.fontAdjust(1.5); String result = engine.execute(dot, options); assertNotNull(result); URL svg = ClassUtils.getResourceURL(classLoader, "flow.1.5.svg"); assertNotNull(svg); assertEqualsIgnoreWhitespaces(Misc.streamToString(svg.openStream()), result); }