maven-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bwald...@apache.org
Subject cvs commit: maven/src/test/java/org/apache/maven/jelly/tags/maven DependencyResolverTestData.java DependencyResolverTest.java
Date Wed, 18 Jun 2003 00:01:11 GMT
bwalding    2003/06/17 17:01:11

  Modified:    src/test/java/org/apache/maven/jelly/tags/maven
                        DependencyResolverTest.java
  Added:       src/test/java/org/apache/maven/jelly/tags/maven
                        DependencyResolverTestData.java
  Log:
  Remove digester dependency.
  
  Revision  Changes    Path
  1.3       +32 -93    maven/src/test/java/org/apache/maven/jelly/tags/maven/DependencyResolverTest.java
  
  Index: DependencyResolverTest.java
  ===================================================================
  RCS file: /home/cvs/maven/src/test/java/org/apache/maven/jelly/tags/maven/DependencyResolverTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DependencyResolverTest.java	13 Feb 2003 14:21:38 -0000	1.2
  +++ DependencyResolverTest.java	18 Jun 2003 00:01:11 -0000	1.3
  @@ -56,103 +56,71 @@
    * ====================================================================
    */
   
  -import java.io.File;
  -import java.io.FileInputStream;
  -import java.io.IOException;
  -import java.io.InputStream;
  -import java.util.ArrayList;
   import java.util.Iterator;
   import java.util.List;
   
  -import org.apache.commons.digester.Digester;
  -import org.apache.maven.project.Dependency;
  -import org.apache.maven.project.Project;
  -import org.xml.sax.SAXException;
  -
   import junit.framework.TestCase;
   
  +import org.apache.maven.project.Project;
  +
   /**
    * @author <a href="bwalding@jakarta.org">Ben Walding</a>
    * @version $Id$
    */
  -public class DependencyResolverTest extends TestCase
  -{
  -    protected InputStream getResource(String resource) throws IOException
  -    {
  -        String baseDir = System.getProperty("basedir");
  -        File f = new File(baseDir + "/src/test/dependency-resolver/" + resource);
  -        return new FileInputStream(f);
  -    }
  +public class DependencyResolverTest extends TestCase {
  +    
   
  -    public void testSimple1() throws Exception
  -    {
  -        InputStream is = getResource("test-simple1.xml");
  -        List projects = getProjects(is);
  +    public void testSimple1() throws Exception {
  +        List projects = DependencyResolverTestData.getTestSimple1();
           testSimple1Source(new GraphDependencyResolver(), projects);
           testSimple1Binary(new GraphDependencyResolver(), projects);
           testSimple1Source(new WerkzDependencyResolver(), projects);
           testSimple1Binary(new WerkzDependencyResolver(), projects);
       }
   
  -    public void testSimple2() throws Exception
  -    {
  -        InputStream is = getResource("test-simple2.xml");
  -        List projects = getProjects(is);
  +    public void testSimple2() throws Exception {
  +        List projects = DependencyResolverTestData.getTestSimple2();
           testSimple2(new GraphDependencyResolver(), projects);
           testSimple2(new WerkzDependencyResolver(), projects);
       }
   
  -    public void testSimple3() throws Exception
  -    {
  -        InputStream is = getResource("test-simple3.xml");
  -        List projects = getProjects(is);
  +    public void testSimple3() throws Exception {
  +        List projects = DependencyResolverTestData.getTestSimple3();
           testSimple3(new GraphDependencyResolver(), projects);
           testSimple3(new WerkzDependencyResolver(), projects);
       }
   
  -    public void testComplex() throws Exception
  -    {
  -        InputStream is = getResource("test-complex.xml");
  -        List projects = getProjects(is);
  +    public void testComplex() throws Exception {
  +        List projects = DependencyResolverTestData.getTestComplex();
           testComplex(new GraphDependencyResolver(), projects);
           testComplex(new WerkzDependencyResolver(), projects);
       }
   
  -    public void testCycle() throws Exception
  -    {
  -        InputStream is = getResource("test-cycle.xml");
  -        List projects = getProjects(is);
  +    public void testCycle() throws Exception {
  +        List projects = DependencyResolverTestData.getTestCycle();
           testCycle(new GraphDependencyResolver(), projects);
           testCycle(new WerkzDependencyResolver(), projects);
       }
   
  -    public void testCycle(DependencyResolverInterface dri, List projects) throws Exception
  -    {
  +    public void testCycle(DependencyResolverInterface dri, List projects) throws Exception
{
           DependencyResolver dr = new DependencyResolver(dri);
           dr.setProjects(projects);
  -        try
  -        {
  +        try {
               dr.getSortedDependencies(true);
               fail("Shouldn't be able to resolve cycles");
  -        }
  -        catch (Exception e)
  -        {
  +        } catch (Exception e) {
               //Success
           }
   
  -        try
  -        {
  +        try {
               dr.getSortedDependencies(false);
               fail("Shouldn't be able to resolve cycles");
  -        }
  -        catch (Exception e)
  -        {
  +        } catch (Exception e) {
               //Success
           }
       }
   
  -    public void testSimple1Source(DependencyResolverInterface dri, List projects) throws
Exception
  -    {
  +    public void testSimple1Source(DependencyResolverInterface dri, List projects) throws
Exception {
           DependencyResolver dr = new DependencyResolver(dri);
           dr.setProjects(projects);
   
  @@ -171,8 +139,7 @@
           assertEquals("test1.sorted", "b:b,e:e,n:n,j:j", listify(dri.getSortedDependencies(j,
true)));
       }
   
  -    public void testSimple1Binary(DependencyResolverInterface dri, List projects) throws
Exception
  -    {
  +    public void testSimple1Binary(DependencyResolverInterface dri, List projects) throws
Exception {
           DependencyResolver dr = new DependencyResolver(dri);
           dr.setProjects(projects);
   
  @@ -191,8 +158,7 @@
           assertEquals("test1.sorted", "b:b,e:e,n:n,j:j", listify(dri.getSortedDependencies(j,
true)));
       }
   
  -    public void testSimple2(DependencyResolverInterface dri, List projects) throws Exception
  -    {
  +    public void testSimple2(DependencyResolverInterface dri, List projects) throws Exception
{
           dri.setProjects(projects);
           projects = dri.getSortedDependencies(true);
   
  @@ -211,8 +177,7 @@
               listify(dri.getSortedDependencies(ow, true)));
       }
   
  -    public void testSimple3(DependencyResolverInterface dri, List projects) throws Exception
  -    {
  +    public void testSimple3(DependencyResolverInterface dri, List projects) throws Exception
{
           dri.setProjects(projects);
           projects = dri.getSortedDependencies(true);
   
  @@ -231,8 +196,7 @@
               listify(dri.getSortedDependencies(ow, true)));
       }
   
  -    public void testComplex(DependencyResolverInterface dri, List projects) throws Exception
  -    {
  +    public void testComplex(DependencyResolverInterface dri, List projects) throws Exception
{
           dri.setProjects(projects);
           //System.out.println("Source DepResolver:" + dri.getClass().getName());
           projects = dri.getSortedDependencies(true);
  @@ -252,25 +216,20 @@
   
       }
   
  -    public void dumpList(List projects)
  -    {
  +    public void dumpList(List projects) {
           Iterator iter = projects.iterator();
  -        while (iter.hasNext())
  -        {
  +        while (iter.hasNext()) {
               Project project = (Project) iter.next();
               System.out.println(project.getId());
           }
       }
   
  -    public void assertBefore(List projects, String first, String second)
  -    {
  +    public void assertBefore(List projects, String first, String second) {
           assertTrue(first + " earlier than " + second, getIndex(projects, first) < getIndex(projects,
second));
       }
   
  -    public int getIndex(List projects, String id)
  -    {
  -        for (int i = 0; i < projects.size(); i++)
  -        {
  +    public int getIndex(List projects, String id) {
  +        for (int i = 0; i < projects.size(); i++) {
               Project p = (Project) projects.get(i);
               if (p.getId().equals(id))
                   return i;
  @@ -278,36 +237,16 @@
           throw new IllegalArgumentException("No such project: " + id);
       }
   
  -    public String listify(List projects)
  -    {
  +    public String listify(List projects) {
           StringBuffer buf = new StringBuffer();
           Iterator iter = projects.iterator();
  -        while (iter.hasNext())
  -        {
  +        while (iter.hasNext()) {
               Project project = (Project) iter.next();
               buf.append(project.getId());
               if (iter.hasNext())
                   buf.append(",");
           }
           return buf.toString();
  -    }
  -
  -    public static List getProjects(InputStream is) throws IOException, SAXException
  -    {
  -        Digester d = new Digester();
  -        List projects = new ArrayList();
  -        d.push(projects);
  -
  -        d.addObjectCreate("*/project", Project.class);
  -        d.addCallMethod("*/id", "setId", 0);
  -        d.addSetNext("*/project", "add");
  -
  -        d.addObjectCreate("*/dependency", Dependency.class);
  -        d.addCallMethod("*/id", "setId", 0);
  -        d.addSetNext("*/dependency", "addDependency");
  -
  -        d.parse(is);
  -        return projects;
       }
   
   }
  
  
  
  1.1                  maven/src/test/java/org/apache/maven/jelly/tags/maven/DependencyResolverTestData.java
  
  Index: DependencyResolverTestData.java
  ===================================================================
  package org.apache.maven.jelly.tags.maven;
  
  import java.util.ArrayList;
  import java.util.List;
  import java.util.StringTokenizer;
  
  import org.apache.maven.project.Dependency;
  import org.apache.maven.project.Project;
  
  /**
   * @author  Ben Walding
   * @version $Id: DependencyResolverTestData.java,v 1.1 2003/06/18 00:01:11 bwalding Exp
$
   */
  public class DependencyResolverTestData {
  
      public static List getTestSimple1() {
          List results = new ArrayList();
          results.add(createProject("j:j", "n:n"));
          results.add(createProject("n:n", "e:e"));
          results.add(createProject("e:e", "b:b"));
          results.add(createProject("b:b", ""));
          return results;
      }
  
      public static List getTestSimple2() {
          List results = new ArrayList();
          results.add(createProject("ox:ox", "nf:nf"));
          results.add(createProject("nf:nf", "ow:ow"));
          results.add(createProject("ow:ow", "br:br"));
          results.add(createProject("br:br", "ck:ck"));
          results.add(createProject("ck:ck", "ui:ui"));
          results.add(createProject("ui:ui", "eq:eq"));
          results.add(createProject("eq:eq", "th:th"));
          results.add(createProject("th:th", ""));
          results.add(createProject("ox:ox", "nf:nf"));
          results.add(createProject("ox:ox", "nf:nf"));
          return results;
      }
  
      public static List getTestSimple3() {
          List results = new ArrayList();
          results.add(createProject("ox:ox", "nf:nf"));
          results.add(createProject("ui:ui", "eq:eq"));
          results.add(createProject("ow:ow", "br:br"));
          results.add(createProject("ck:ck", "ui:ui"));
          results.add(createProject("nf:nf", "ow:ow"));
          results.add(createProject("eq:eq", "th:th"));
          results.add(createProject("br:br", "ck:ck"));
          results.add(createProject("th:th", ""));
          return results;
      }
  
      public static List getTestCycle() {
          List results = new ArrayList();
          results.add(createProject("a:a", "b:b"));
          results.add(createProject("b:b", "c:c"));
          results.add(createProject("c:c", "a:a"));
          return results;
      }
  
      public static List getTestComplex() {
          List results = new ArrayList();
          results.add(createProject("tyre:tyre", "rubber:rubber"));
          results.add(createProject("car:car", "petrol:petrol,driver:driver,key:key,tyre:tyre"));
          results.add(createProject("car:car", ""));
          results.add(createProject("driver:driver", "wallet:wallet,license:license,key:key"));
          results.add(createProject("driver:driver", "beer:beer"));
          results.add(createProject("beer:beer", "water:water,hops:hops,malt:malt"));
          results.add(createProject("hops:hops", ""));
          return results;
      }
  
      private static  Project createProject(String id) {
          Project p = new Project();
          p.setId(id);
          return p;
      }
  
      private static Dependency createDependency(String id) {
          Dependency d = new Dependency();
          d.setId(id);
          return d;
      }
  
      private static Project createProject(String id, String dependencies) {
          StringTokenizer depToks = new StringTokenizer(dependencies, ",", false);
          Project p = createProject(id);
          while (depToks.hasMoreTokens()) {
              String token = depToks.nextToken();
              Dependency d = createDependency(token);
              p.addDependency(d);
          }
          return p;
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Mime
View raw message