KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > publishers > sfee > SfeeTestUtils


1 package net.sourceforge.cruisecontrol.publishers.sfee;
2
3 import java.lang.reflect.InvocationTargetException JavaDoc;
4 import java.lang.reflect.Method JavaDoc;
5
6 import junit.framework.Assert;
7
8 public class SfeeTestUtils {
9     private Object JavaDoc inMemorySfee;
10     private boolean notUsingInMemory;
11
12     void loadSfeeInMemory(String JavaDoc serverUrl, String JavaDoc username, String JavaDoc password) {
13         // Instantiate the in-memory stub implementation of SFEE using reflection so that
14
// this class will still compile and run when the REAL implementation of SFEE is used.
15
try {
16             Class JavaDoc inMemSfeeFactoryClass = Class.forName("com.vasoftware.sf.InMemorySfeeFactory");
17             Method JavaDoc resetMethod = inMemSfeeFactoryClass.getMethod("reset", null);
18             resetMethod.invoke(null, null);
19             Method JavaDoc createMethod = inMemSfeeFactoryClass.getMethod("create", new Class JavaDoc[] { String JavaDoc.class, String JavaDoc.class,
20                     String JavaDoc.class });
21             inMemorySfee = createMethod.invoke(null, new Object JavaDoc[] { serverUrl, username, password });
22         } catch (NoSuchMethodException JavaDoc e) {
23             Assert.fail("Must be using the wrong version of the sfee soap stubs.");
24         } catch (IllegalAccessException JavaDoc e) {
25             Assert.fail("Must be using the wrong version of the sfee soap stubs.");
26         } catch (InvocationTargetException JavaDoc e) {
27             Assert.fail("Must be using the wrong version of the sfee soap stubs.");
28         } catch (ClassNotFoundException JavaDoc e) {
29             // Must be running with the real SFEE implementation, which does NOT contain
30
// the InMemorySfeeFactory class. So, we can ignore this
31
// exception and go on with the test.
32
notUsingInMemory = true;
33         }
34     }
35
36     void addProject(String JavaDoc projectName) {
37         if (notUsingInMemory) {
38             return;
39         }
40
41         try {
42             Method JavaDoc addProjectMethod = inMemorySfee.getClass().getMethod("addProject", new Class JavaDoc[] { String JavaDoc.class });
43             addProjectMethod.invoke(inMemorySfee, new Object JavaDoc[] { projectName });
44         } catch (NoSuchMethodException JavaDoc e) {
45             Assert.fail("Must be using the wrong version of the sfee soap stubs.");
46         } catch (IllegalAccessException JavaDoc e) {
47             Assert.fail("Must be using the wrong version of the sfee soap stubs.");
48         } catch (InvocationTargetException JavaDoc e) {
49             Assert.fail("Must be using the wrong version of the sfee soap stubs.");
50         }
51     }
52
53     void addTracker(String JavaDoc trackerName, String JavaDoc projectName) {
54         if (notUsingInMemory) {
55             return;
56         }
57
58         try {
59             Method JavaDoc addTracker = inMemorySfee.getClass().getMethod("addTracker",
60                     new Class JavaDoc[] { String JavaDoc.class, String JavaDoc.class });
61             addTracker.invoke(inMemorySfee, new Object JavaDoc[] { trackerName, projectName });
62         } catch (NoSuchMethodException JavaDoc e) {
63             Assert.fail("Must be using the wrong version of the sfee soap stubs.");
64         } catch (IllegalAccessException JavaDoc e) {
65             Assert.fail("Must be using the wrong version of the sfee soap stubs.");
66         } catch (InvocationTargetException JavaDoc e) {
67             Assert.fail("Must be using the wrong version of the sfee soap stubs.");
68         }
69     }
70
71     void createFolders(String JavaDoc projectName, String JavaDoc path) {
72         if (notUsingInMemory) {
73             return;
74         }
75
76         try {
77             Method JavaDoc createFolders = inMemorySfee.getClass().getMethod("createFolders",
78                     new Class JavaDoc[] { String JavaDoc.class, String JavaDoc.class });
79             createFolders.invoke(inMemorySfee, new Object JavaDoc[] { projectName, path });
80         } catch (NoSuchMethodException JavaDoc e) {
81             Assert.fail("Must be using the wrong version of the sfee soap stubs.");
82         } catch (IllegalAccessException JavaDoc e) {
83             Assert.fail("Must be using the wrong version of the sfee soap stubs.");
84         } catch (InvocationTargetException JavaDoc e) {
85             Assert.fail("Must be using the wrong version of the sfee soap stubs.");
86         }
87     }
88 }
89
Popular Tags