evenisse    2003/08/06 03:42:44

  Modified:    src/test/java/org/apache/maven/jelly/tags/maven
                        DependencyResolverTest.java
  Log:
  Backward code to the previous version. Now, we don't use digester in maven test 
classes. I think we can remove the dependency in Maven pom.
  
  Revision  Changes    Path
  1.6       +36 -118   
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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DependencyResolverTest.java       27 Jul 2003 23:34:00 -0000      1.5
  +++ DependencyResolverTest.java       6 Aug 2003 10:42:44 -0000       1.6
  @@ -56,123 +56,69 @@
    * ====================================================================
    */
   
  -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="[EMAIL PROTECTED]">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 void testSimple1() throws Exception
  -    {
  -        InputStream is = getResource("test-simple1.xml");
  -        List projects = getProjects(is);
  -        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 class DependencyResolverTest extends TestCase {
  +    
  +
  +    public void testSimple1() throws Exception {
  +        List projects = DependencyResolverTestData.getTestSimple1();
  +        testSimple1(new GraphDependencyResolver(), projects);
  +        testSimple1(new WerkzDependencyResolver(), projects);
  +    }
  +
  +    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
  -    {
  -        DependencyResolver dr = new DependencyResolver(dri);
  -        dr.setProjects(projects);
  -
  -        assertEquals("test1.sorted", "b:b,e:e,n:n,j:j", 
listify(dri.getSortedDependencies(true)));
  -
  -        projects = dr.getSortedDependencies(true);
  -        assertBefore(projects, "b:b", "e:e");
  -        assertBefore(projects, "e:e", "n:n");
  -        assertBefore(projects, "n:n", "j:j");
  -
  -        Project e = DependencyResolver.getProject(projects, "e:e");
  -        assertEquals("test1.sorted", "b:b,e:e", 
listify(dri.getSortedDependencies(e, true)));
  -        Project n = DependencyResolver.getProject(projects, "n:n");
  -        assertEquals("test1.sorted", "b:b,e:e,n:n", 
listify(dri.getSortedDependencies(n, true)));
  -        Project j = DependencyResolver.getProject(projects, "j:j");
  -        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 testSimple1(DependencyResolverInterface dri, List projects) throws 
Exception {
           DependencyResolver dr = new DependencyResolver(dri);
           dr.setProjects(projects);
   
  @@ -191,8 +137,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 +156,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 +175,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 +195,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 +216,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", "setVar", 0);
  -        d.addSetNext("*/project", "add");
  -
  -        d.addObjectCreate("*/dependency", Dependency.class);
  -        d.addCallMethod("*/id", "setVar", 0);
  -        d.addSetNext("*/dependency", "addDependency");
  -
  -        d.parse(is);
  -        return projects;
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to