KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > savant > test > DependencyMediatorDepsTest


1 /*
2  * Copyright (c) 2003-2004, Inversoft, All Rights Reserved
3  */

4 package com.inversoft.savant.test;
5
6
7 import java.io.File JavaDoc;
8 import java.net.MalformedURLException JavaDoc;
9 import java.util.Arrays JavaDoc;
10
11 import junit.framework.TestCase;
12
13 import com.inversoft.savant.Artifact;
14 import com.inversoft.savant.Dependencies;
15 import com.inversoft.savant.DependencyMediator;
16 import com.inversoft.savant.SavantException;
17 import com.inversoft.savant.SavantInternetProcess;
18 import com.inversoft.savant.Workflow;
19
20
21 /**
22  * <p>
23  * This class is a test case that tests the dependency mediator
24  * and how the artifact dependencies are resolved.
25  * </p>
26  *
27  * @author Brian Pontarelli
28  */

29 public class DependencyMediatorDepsTest extends TestCase {
30
31     public DependencyMediatorDepsTest(String JavaDoc s) {
32         super(s);
33     }
34
35
36
37     /**
38      * Tests that the mediator fetches all dependencies using the deps XML file.
39      */

40     public void testArtifactDeps() throws SavantException, MalformedURLException JavaDoc {
41         Artifact a = new Artifact();
42         a.setGroup("my_group");
43         a.setName("my_complete_artifact");
44         a.setProjectname("my_project");
45         a.setType("jar");
46         a.setVersion("42");
47
48         Dependencies d = new Dependencies();
49         d.addArtifact(a);
50
51         File JavaDoc root = new File JavaDoc("test/savant");
52         SavantInternetProcess sip = new SavantInternetProcess();
53         sip.setDefaultdomain(root.toURL().toString());
54
55         Workflow w = new Workflow();
56         w.addProcess(sip);
57
58         File JavaDoc cache = new File JavaDoc("test/cache");
59         File JavaDoc toClear = new File JavaDoc(cache, "my_group/my_project");
60         File JavaDoc[] files = toClear.listFiles();
61         for (int i = 0; i < files.length; i++) {
62             File JavaDoc file = files[i];
63             System.out.println("Deleting: " + file.getAbsolutePath());
64             file.delete();
65         }
66
67         DependencyMediator dm = new DependencyMediator();
68         dm.setLocalCacheDir(cache);
69         dm.setDependencies(d);
70         dm.setWorkflow(w);
71         dm.mediate();
72
73         files = toClear.listFiles();
74         assertEquals(4, files.length);
75
76         Arrays.sort(files);
77         assertTrue(Arrays.binarySearch(files, new File JavaDoc(toClear, "my_name-2.0.exe")) >= 0);
78         assertTrue(Arrays.binarySearch(files, new File JavaDoc(toClear, "my_md5_artifact-2.0.jar")) >= 0);
79         assertTrue(Arrays.binarySearch(files, new File JavaDoc(toClear, "my_complete_artifact-42.jar")) >= 0);
80     }
81 }
Popular Tags