[jboss-cvs] JBossAS SVN: r90938 - in projects/mc-tools/grapher/trunk/src/test: java/org/jboss/test/mctools/grapher/test and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jul 8 10:51:10 EDT 2009


Author: alesj
Date: 2009-07-08 10:51:10 -0400 (Wed, 08 Jul 2009)
New Revision: 90938

Added:
   projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/test/AbstractRendererTest.java
   projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/test/ManualGraphWrite2FileTestCase.java
   projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/test/RendererTestCase.java
   projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/test/Write2FileTestCase.java
   projects/mc-tools/grapher/trunk/src/test/resources/org/jboss/test/mctools/grapher/test/RendererTestCase.xml
   projects/mc-tools/grapher/trunk/src/test/resources/org/jboss/test/mctools/grapher/test/Write2FileTestCase.xml
Modified:
   projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/GrapherTestSuite.java
Log:
More renderer tests.

Modified: projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/GrapherTestSuite.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/GrapherTestSuite.java	2009-07-08 14:44:19 UTC (rev 90937)
+++ projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/GrapherTestSuite.java	2009-07-08 14:51:10 UTC (rev 90938)
@@ -21,10 +21,13 @@
  */
 package org.jboss.test.mctools.grapher;
 
+import junit.framework.Test;
 import junit.framework.TestSuite;
-import junit.framework.Test;
 import junit.textui.TestRunner;
 import org.jboss.test.mctools.grapher.test.GraphCreatorTestCase;
+import org.jboss.test.mctools.grapher.test.RendererTestCase;
+import org.jboss.test.mctools.grapher.test.Write2FileTestCase;
+import org.jboss.test.mctools.grapher.test.ManualGraphWrite2FileTestCase;
 
 /**
  * Grapher test suite.
@@ -42,7 +45,12 @@
    {
       TestSuite suite = new TestSuite("Grapher Tests");
 
+      // graph creator tests
       suite.addTest(GraphCreatorTestCase.suite());
+      // renderers tests
+      suite.addTest(RendererTestCase.suite());
+      suite.addTest(Write2FileTestCase.suite());
+      suite.addTest(ManualGraphWrite2FileTestCase.suite());
 
       return suite;
    }

Added: projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/test/AbstractRendererTest.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/test/AbstractRendererTest.java	                        (rev 0)
+++ projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/test/AbstractRendererTest.java	2009-07-08 14:51:10 UTC (rev 90938)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.mctools.grapher.test;
+
+import java.io.OutputStream;
+import java.util.Map;
+import java.util.HashMap;
+
+import org.jboss.mctools.grapher.render.GIFRenderer;
+import org.jboss.mctools.grapher.render.JPGRenderer;
+import org.jboss.mctools.grapher.render.Renderer;
+import org.jboss.mctools.grapher.render.SVGRenderer;
+import org.jboss.test.mctools.grapher.GrapherTest;
+import org.jgraph.JGraph;
+
+/**
+ * Renderer impl tests.
+ *
+ * @param <T> exact output stream type
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class AbstractRendererTest<T extends OutputStream> extends GrapherTest
+{
+   protected AbstractRendererTest(String name)
+   {
+      super(name);
+   }
+
+   private static Map<Class<? extends Renderer>, String> suffixes;
+
+   static
+   {
+      suffixes = new HashMap<Class<? extends Renderer>, String>();
+      suffixes.put(SVGRenderer.class, ".svg");
+      suffixes.put(GIFRenderer.class, ".gif");
+      suffixes.put(JPGRenderer.class, ".jpg");
+   }
+
+   protected abstract T createOutputStream(String suffix) throws Throwable;
+
+   protected abstract void testOutputStream(T out, String suffix);
+
+   protected abstract JGraph createGraph();
+
+   protected void cleanupOutputStream(T out)
+   {
+      getLog().info(out);
+   }
+
+   protected void testRenderer(Renderer renderer) throws Throwable
+   {
+      JGraph graph = createGraph();
+      String suffix = suffixes.get(renderer.getClass());
+      T out = createOutputStream(suffix);
+      try
+      {
+         renderer.render(graph, out, 0);
+         testOutputStream(out, suffix);
+      }
+      finally
+      {
+         try
+         {
+            out.close();
+         }
+         finally
+         {
+            cleanupOutputStream(out);
+         }
+      }
+   }
+
+   public void testSVG() throws Throwable
+   {
+      testRenderer(new SVGRenderer());
+   }
+
+   public void testGIF() throws Throwable
+   {
+      testRenderer(new GIFRenderer());
+   }
+
+   public void testJPG() throws Throwable
+   {
+      testRenderer(new JPGRenderer());
+   }
+}
\ No newline at end of file

Added: projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/test/ManualGraphWrite2FileTestCase.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/test/ManualGraphWrite2FileTestCase.java	                        (rev 0)
+++ projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/test/ManualGraphWrite2FileTestCase.java	2009-07-08 14:51:10 UTC (rev 90938)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.mctools.grapher.test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Test;
+import org.jgraph.JGraph;
+import org.jgraph.graph.ConnectionSet;
+import org.jgraph.graph.DefaultEdge;
+import org.jgraph.graph.DefaultGraphCell;
+import org.jgraph.graph.DefaultGraphModel;
+import org.jgraph.graph.Edge;
+import org.jgraph.graph.GraphModel;
+
+/**
+ * Write to file tests, manual graph creation.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ManualGraphWrite2FileTestCase extends Write2FileTestCase
+{
+   public ManualGraphWrite2FileTestCase(String name)
+   {
+      super(name);
+      //setDeleteFile(false);
+   }
+
+   public static Test suite()
+   {
+      return suite(ManualGraphWrite2FileTestCase.class);
+   }
+
+   @SuppressWarnings("unchecked")
+   protected JGraph createGraph()
+   {
+      List cells = new ArrayList();
+      ConnectionSet cs = new ConnectionSet();
+      Map attributes = new HashMap();
+
+      DefaultGraphCell v1 = new DefaultGraphCell("v1");
+      v1.addPort();
+      cells.add(v1);
+
+      DefaultGraphCell v2 = new DefaultGraphCell("v2");
+      v2.addPort();
+      cells.add(v2);
+
+      Edge e1 = new DefaultEdge("e1");
+      cs.connect(e1, v1.getChildAt(0), v2.getChildAt(0));
+      cells.add(e1);
+
+      // create simple graph
+      GraphModel model = new DefaultGraphModel();
+      model.insert(cells.toArray(), attributes, cs, null, null);
+      return new JGraph(model);
+   }
+}
\ No newline at end of file

Copied: projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/test/RendererTestCase.java (from rev 90933, projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/test/GraphCreatorTestCase.java)
===================================================================
--- projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/test/RendererTestCase.java	                        (rev 0)
+++ projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/test/RendererTestCase.java	2009-07-08 14:51:10 UTC (rev 90938)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.mctools.grapher.test;
+
+import java.io.ByteArrayOutputStream;
+
+import junit.framework.Test;
+import org.jboss.mctools.grapher.graph.GraphCreator;
+import org.jboss.mctools.grapher.map.GraphCreatorMapper;
+import org.jgraph.JGraph;
+
+/**
+ * Renderer impl tests.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class RendererTestCase extends AbstractRendererTest<ByteArrayOutputStream>
+{
+   public RendererTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(RendererTestCase.class);
+   }
+
+   protected String getDefaultBean()
+   {
+      return "Owner";
+   }
+
+   protected ByteArrayOutputStream createOutputStream(String suffix)
+   {
+      return new ByteArrayOutputStream();
+   }
+
+   protected void testOutputStream(ByteArrayOutputStream out, String suffix)
+   {
+      byte[] bytes = out.toByteArray();
+      assertTrue(bytes.length > 0);
+   }
+
+   protected JGraph createGraph()
+   {
+      GraphCreator creator = GraphCreatorMapper.ALL;
+      return creator.createGraph(getKernelController());
+   }
+}
\ No newline at end of file

Added: projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/test/Write2FileTestCase.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/test/Write2FileTestCase.java	                        (rev 0)
+++ projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/test/Write2FileTestCase.java	2009-07-08 14:51:10 UTC (rev 90938)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.mctools.grapher.test;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.security.ProtectionDomain;
+import java.security.CodeSource;
+import java.net.URL;
+
+import junit.framework.Test;
+import org.jboss.mctools.grapher.graph.GraphCreator;
+import org.jboss.mctools.grapher.map.GraphCreatorMapper;
+import org.jgraph.JGraph;
+
+/**
+ * Write to file tests.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class Write2FileTestCase extends AbstractRendererTest<FileOutputStream>
+{
+   private boolean deleteFile = true; // change this if you wanna inspect the pics
+
+   private File tempFile;
+
+   public Write2FileTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(Write2FileTestCase.class);
+   }
+
+   protected String getDefaultBean()
+   {
+      return "Owner";
+   }
+
+   protected FileOutputStream createOutputStream(String suffix) throws Throwable
+   {
+      ProtectionDomain pd = getClass().getProtectionDomain();
+      CodeSource cs = pd.getCodeSource();
+      URL location = cs.getLocation();
+      File root = new File(location.toURI());
+      tempFile = File.createTempFile("grapher-", suffix, root);
+      return new FileOutputStream(tempFile);
+   }
+
+   protected void testOutputStream(FileOutputStream out, String suffix)
+   {
+   }
+
+   @Override
+   protected void cleanupOutputStream(FileOutputStream out)
+   {
+      if (deleteFile)
+         assertTrue(tempFile.delete());
+   }
+
+   protected JGraph createGraph()
+   {
+      GraphCreator creator = GraphCreatorMapper.ALL;
+      return creator.createGraph(getKernelController());
+   }
+
+   public void setDeleteFile(boolean deleteFile)
+   {
+      this.deleteFile = deleteFile;
+   }
+}
\ No newline at end of file

Copied: projects/mc-tools/grapher/trunk/src/test/resources/org/jboss/test/mctools/grapher/test/RendererTestCase.xml (from rev 90933, projects/mc-tools/grapher/trunk/src/test/resources/org/jboss/test/mctools/grapher/test/GraphCreatorTestCase.xml)
===================================================================
--- projects/mc-tools/grapher/trunk/src/test/resources/org/jboss/test/mctools/grapher/test/RendererTestCase.xml	                        (rev 0)
+++ projects/mc-tools/grapher/trunk/src/test/resources/org/jboss/test/mctools/grapher/test/RendererTestCase.xml	2009-07-08 14:51:10 UTC (rev 90938)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+  <bean name="Owner" class="java.lang.Object">
+    <alias>OwAlias</alias>
+  </bean>
+
+  <bean name="Dep1" class="java.lang.Object">
+    <alias>Dep1Alias</alias>
+    <demand>OwAlias</demand>
+  </bean>
+
+  <bean name="Dep2" class="java.lang.Object">
+    <alias>Dep2Alias</alias>
+    <depends>Dep1</depends>
+  </bean>
+
+</deployment>

Added: projects/mc-tools/grapher/trunk/src/test/resources/org/jboss/test/mctools/grapher/test/Write2FileTestCase.xml
===================================================================
--- projects/mc-tools/grapher/trunk/src/test/resources/org/jboss/test/mctools/grapher/test/Write2FileTestCase.xml	                        (rev 0)
+++ projects/mc-tools/grapher/trunk/src/test/resources/org/jboss/test/mctools/grapher/test/Write2FileTestCase.xml	2009-07-08 14:51:10 UTC (rev 90938)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+  <bean name="Owner" class="java.lang.Object">
+    <alias>OwAlias</alias>
+  </bean>
+
+  <bean name="Dep1" class="java.lang.Object">
+    <alias>Dep1Alias</alias>
+    <demand>OwAlias</demand>
+  </bean>
+
+  <bean name="Dep2" class="java.lang.Object">
+    <alias>Dep2Alias</alias>
+    <depends>Dep1</depends>
+  </bean>
+
+</deployment>




More information about the jboss-cvs-commits mailing list