[jboss-cvs] JBossAS SVN: r90933 - in projects/mc-tools/grapher/trunk: src and 16 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jul 8 09:46:52 EDT 2009


Author: alesj
Date: 2009-07-08 09:46:51 -0400 (Wed, 08 Jul 2009)
New Revision: 90933

Added:
   projects/mc-tools/grapher/trunk/src/test/
   projects/mc-tools/grapher/trunk/src/test/java/
   projects/mc-tools/grapher/trunk/src/test/java/org/
   projects/mc-tools/grapher/trunk/src/test/java/org/jboss/
   projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/
   projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/
   projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/
   projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/GrapherTest.java
   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/test/
   projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/test/GraphCreatorTestCase.java
   projects/mc-tools/grapher/trunk/src/test/resources/
   projects/mc-tools/grapher/trunk/src/test/resources/org/
   projects/mc-tools/grapher/trunk/src/test/resources/org/jboss/
   projects/mc-tools/grapher/trunk/src/test/resources/org/jboss/test/
   projects/mc-tools/grapher/trunk/src/test/resources/org/jboss/test/mctools/
   projects/mc-tools/grapher/trunk/src/test/resources/org/jboss/test/mctools/grapher/
   projects/mc-tools/grapher/trunk/src/test/resources/org/jboss/test/mctools/grapher/test/
   projects/mc-tools/grapher/trunk/src/test/resources/org/jboss/test/mctools/grapher/test/GraphCreatorTestCase.xml
Modified:
   projects/mc-tools/grapher/trunk/pom.xml
   projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AbstractGraphCreator.java
Log:
Add tests.

Modified: projects/mc-tools/grapher/trunk/pom.xml
===================================================================
--- projects/mc-tools/grapher/trunk/pom.xml	2009-07-08 13:16:49 UTC (rev 90932)
+++ projects/mc-tools/grapher/trunk/pom.xml	2009-07-08 13:46:51 UTC (rev 90933)
@@ -19,8 +19,102 @@
    
   <properties>
     <version.batik>1.6</version.batik>
+    <version.org.jboss.test>1.1.1.GA</version.org.jboss.test>
+    <version.junit>4.4</version.junit>
   </properties>
 
+  <profiles>
+    <profile>
+      <id>default</id>
+      <activation>
+        <activeByDefault>true</activeByDefault>
+      </activation>
+      <properties>
+        <mctools.outputDirectory>target/classes</mctools.outputDirectory>
+        <mctools.testOutputDirectory>target/test-classes</mctools.testOutputDirectory>
+      </properties>
+    </profile>
+  </profiles>
+
+  <build>
+    <outputDirectory>${mctools.outputDirectory}</outputDirectory>
+    <testOutputDirectory>${mctools.testOutputDirectory}</testOutputDirectory>
+    <finalName>${artifactId}</finalName>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-enforcer-plugin</artifactId>
+        <version>1.0-alpha-3</version>
+        <executions>
+          <execution>
+            <id>enforce-versions</id>
+            <goals>
+              <goal>enforce</goal>
+            </goals>
+            <phase>validate</phase>
+            <configuration>
+              <rules>
+                <requireMavenVersion>
+                  <version>2.0.9</version>
+                </requireMavenVersion>
+                <requireJavaVersion>
+                  <version>1.5.0</version>
+                </requireJavaVersion>
+              </rules>
+            </configuration>
+          </execution>
+        </executions>
+        <inherited>true</inherited>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-release-plugin</artifactId>
+        <version>2.0-beta-9</version>
+        <configuration>
+          <generateReleasePoms>false</generateReleasePoms>
+          <tagBase>https://svn.jboss.org/repos/jbossas/projects/kernel/tags</tagBase>
+          <autoVersionSubmodules>true</autoVersionSubmodules>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.0.2</version>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+          <showDeprecation>true</showDeprecation>
+          <showWarnings>true</showWarnings>
+          <optimize>true</optimize>
+        </configuration>
+      </plugin>
+    </plugins>
+
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-idea-plugin</artifactId>
+          <version>2.2</version>
+          <configuration>
+            <downloadSources>true</downloadSources>
+          </configuration>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-surefire-plugin</artifactId>
+          <version>2.4.3</version>
+          <configuration>
+            <redirectTestOutputToFile>true</redirectTestOutputToFile>
+            <includes>
+              <include>org/jboss/test/**/*TestCase.java</include>
+            </includes>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+
   <dependencies>
     <dependency>
        <groupId>batik</groupId>
@@ -142,6 +236,20 @@
       <version>2.0.5.GA</version>
       <scope>provided</scope>
     </dependency>
+
+      <!-- test dependencies -->
+      <dependency>
+        <groupId>org.jboss.test</groupId>
+        <artifactId>jboss-test</artifactId>
+        <version>${version.org.jboss.test}</version>
+        <scope>test</scope>
+      </dependency>
+      <dependency>
+        <groupId>junit</groupId>
+        <artifactId>junit</artifactId>
+        <version>${version.junit}</version>
+        <scope>test</scope>
+      </dependency>
   </dependencies>
   
 </project>
\ No newline at end of file

Modified: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AbstractGraphCreator.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AbstractGraphCreator.java	2009-07-08 13:16:49 UTC (rev 90932)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AbstractGraphCreator.java	2009-07-08 13:46:51 UTC (rev 90933)
@@ -22,29 +22,29 @@
 package org.jboss.mctools.grapher.graph;
 
 import java.awt.*;
-import java.awt.geom.Rectangle2D;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Hashtable;
 import java.util.Map;
 import java.util.Set;
-import java.util.Arrays;
-import java.util.Hashtable;
 
 import org.jboss.dependency.spi.ControllerContext;
 import org.jboss.dependency.spi.DependencyInfo;
 import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.dependency.spi.ControllerState;
 import org.jboss.kernel.spi.dependency.KernelController;
 import org.jboss.logging.Logger;
+import org.jgraph.JGraph;
+import org.jgraph.graph.AttributeMap;
+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.GraphCell;
 import org.jgraph.graph.GraphConstants;
-import org.jgraph.graph.ConnectionSet;
 import org.jgraph.graph.GraphModel;
-import org.jgraph.graph.DefaultGraphModel;
-import org.jgraph.graph.GraphCell;
-import org.jgraph.graph.AttributeMap;
-import org.jgraph.JGraph;
 
 /**
  * Abstract MC components renderer.
@@ -118,10 +118,12 @@
     */
    protected DefaultGraphCell createCell(Object label)
    {
-      DefaultGraphCell cell = new ColorableGraphCell(label, Color.BLUE);
+      DefaultGraphCell cell = new ColorableGraphCell(label, Color.YELLOW);
+/*
       GraphConstants.setBounds(cell.getAttributes(), new Rectangle2D.Double(20,20,30,15));
       GraphConstants.setGradientColor(cell.getAttributes(), Color.orange);
       GraphConstants.setOpaque(cell.getAttributes(), true);
+*/
 
       cell.addPort();
 
@@ -168,7 +170,8 @@
                }
             }
 
-            Edge edge = new DefaultEdge();
+            ControllerState state = item.getWhenRequired();
+            Edge edge = new DefaultEdge(state != null ? state.getStateString() : "UNKNOWN");
             cs.connect(edge, owner.getChildAt(0), dependency.getChildAt(0));
 
             int arrow = GraphConstants.ARROW_CLASSIC;

Added: projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/GrapherTest.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/GrapherTest.java	                        (rev 0)
+++ projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/GrapherTest.java	2009-07-08 13:46:51 UTC (rev 90933)
@@ -0,0 +1,53 @@
+/*
+ * 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;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.test.kernel.junit.MicrocontainerTest;
+
+/**
+ * Grapher test.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class GrapherTest extends MicrocontainerTest
+{
+   protected GrapherTest(String name)
+   {
+      super(name);
+   }
+
+   /**
+    * Return the name of the bean that's present in config.
+    *
+    * @return the default bean name
+    */
+   protected abstract String getDefaultBean();
+
+   // A bit of a hack to get KernelController
+   protected KernelController getKernelController()
+   {
+      ControllerContext cc = getControllerContext(getDefaultBean());
+      return KernelController.class.cast(cc.getController());
+   }
+}
\ No newline at end of file

Added: 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	                        (rev 0)
+++ projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/GrapherTestSuite.java	2009-07-08 13:46:51 UTC (rev 90933)
@@ -0,0 +1,50 @@
+/*
+ * 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;
+
+import junit.framework.TestSuite;
+import junit.framework.Test;
+import junit.textui.TestRunner;
+import org.jboss.test.mctools.grapher.test.GraphCreatorTestCase;
+
+/**
+ * Grapher test suite.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class GrapherTestSuite extends TestSuite
+{
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("Grapher Tests");
+
+      suite.addTest(GraphCreatorTestCase.suite());
+
+      return suite;
+   }
+
+}

Added: 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/GraphCreatorTestCase.java	                        (rev 0)
+++ projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/test/GraphCreatorTestCase.java	2009-07-08 13:46:51 UTC (rev 90933)
@@ -0,0 +1,82 @@
+/*
+ * 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.Arrays;
+
+import junit.framework.Test;
+import org.jboss.mctools.grapher.graph.AllGraphCreator;
+import org.jboss.mctools.grapher.graph.BeanGraphCreator;
+import org.jboss.mctools.grapher.graph.GraphCreator;
+import org.jboss.test.mctools.grapher.GrapherTest;
+import org.jgraph.JGraph;
+import org.jgraph.graph.DefaultGraphCell;
+import org.jgraph.graph.Edge;
+
+/**
+ * Graph creator impl tests.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class GraphCreatorTestCase extends GrapherTest
+{
+   public GraphCreatorTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(GraphCreatorTestCase.class);
+   }
+
+   protected String getDefaultBean()
+   {
+      return "Owner";
+   }
+
+   protected void assertGraphCreator(GraphCreator creator, int vertices, int edges)
+   {
+      JGraph graph = creator.createGraph(getKernelController());
+      Object[] roots = graph.getRoots();
+      assertNotNull(roots);
+      for (Object cell : roots)
+      {
+         if (cell instanceof Edge)
+            edges--;
+         else if (cell instanceof DefaultGraphCell)
+            vertices--;
+      }
+      assertEquals("Vertices: " + Arrays.asList(roots).toString(), 0, vertices);
+      assertEquals("Edges: " + Arrays.asList(roots).toString(), 0, edges);
+   }
+
+   public void testAll()
+   {
+      assertGraphCreator(new AllGraphCreator(), 3, 3);
+   }
+
+   public void testBean()
+   {
+      assertGraphCreator(new BeanGraphCreator("Dep2"), 2, 2);
+   }
+}

Added: 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/GraphCreatorTestCase.xml	                        (rev 0)
+++ projects/mc-tools/grapher/trunk/src/test/resources/org/jboss/test/mctools/grapher/test/GraphCreatorTestCase.xml	2009-07-08 13:46:51 UTC (rev 90933)
@@ -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