KickJava   Java API By Example, From Geeks To Geeks.

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


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
9 import junit.framework.TestCase;
10
11 import com.inversoft.savant.Artifact;
12 import com.inversoft.savant.ArtifactGroup;
13 import com.inversoft.savant.Dependencies;
14 import com.inversoft.savant.DependencyListener;
15 import com.inversoft.savant.DependencyMediator;
16 import com.inversoft.savant.LocalProject;
17 import com.inversoft.savant.SavantException;
18 import com.inversoft.savant.Workflow;
19
20
21 /**
22  * <p>
23  * This class is the test case for the dependency mediator.
24  * </p>
25  *
26  * @author Brian Pontarelli
27  */

28 public class DependencyMediatorTest extends TestCase {
29
30     /**
31      * Constructs a new <code>DependencyMediatorTest</code>.
32      */

33     public DependencyMediatorTest(String JavaDoc name) {
34         super(name);
35     }
36
37     /**
38      * Tests that mediator builds local projects properly.
39      */

40     public void testLocalProject() throws SavantException {
41         Dependencies d = new Dependencies();
42         TestLocalProject p = new TestLocalProject();
43         d.addProject(p);
44
45         Artifact a = new Artifact();
46         a.setGroup("my_group");
47         a.setName("my_name");
48         a.setProjectname("my_project");
49         a.setType("exe");
50         a.setVersion("2.0");
51         d.addArtifact(a);
52
53         Artifact a1 = new Artifact();
54         a1.setGroup("my_group");
55         a1.setName("my_md5_artifact");
56         a1.setProjectname("my_project");
57         a1.setType("jar");
58         a1.setVersion("2.0");
59         d.addArtifact(a1);
60
61         DependencyMediator dm = new DependencyMediator();
62         dm.setLocalCacheDir(new File JavaDoc("test/savant"));
63         dm.setDependencies(d);
64         dm.setWorkflow(new Workflow());
65
66         TestListener l = new TestListener();
67         dm.addListener(l);
68
69         l.artifactCalled = false;
70         l.projectCalled = false;
71         p.built = false;
72         dm.mediate();
73
74         assertTrue(l.artifactCalled);
75         assertTrue(l.projectCalled);
76         assertTrue(p.built);
77     }
78
79     /**
80      * Tests that mediator fails correctly.
81      */

82     public void testFailure() throws SavantException {
83         Dependencies d = new Dependencies();
84         TestLocalProject p = new TestLocalProject();
85         d.addProject(p);
86
87         Artifact a = new Artifact();
88         a.setGroup("wrong_group");
89         a.setName("my_name");
90         a.setProjectname("my_project");
91         a.setType("exe");
92         a.setVersion("2.0");
93         d.addArtifact(a);
94
95         DependencyMediator dm = new DependencyMediator();
96         dm.setLocalCacheDir(new File JavaDoc("test/savant"));
97         dm.setDependencies(d);
98         dm.setWorkflow(new Workflow());
99
100         try {
101             dm.mediate();
102             fail("Should have failed");
103         } catch (SavantException e) {
104             // Expected
105
}
106     }
107
108
109     public static class TestLocalProject extends LocalProject {
110         public boolean built = false;
111
112         public TestLocalProject() {
113             setName("my_project");
114             setGroup("my_group");
115             setDir(new File JavaDoc("."));
116         }
117
118         public void build() {
119             assertFalse(built);
120             built = true;
121         }
122     }
123
124     public static class TestListener implements DependencyListener {
125         public boolean projectCalled = false;
126         public boolean artifactCalled = false;
127
128         public void projectBuilt(LocalProject project) {
129             projectCalled = true;
130         }
131
132         public void artifactFound(File JavaDoc file, Artifact artifact, ArtifactGroup group) {
133             artifactCalled = true;
134         }
135     }
136 }
Popular Tags