1 package net.sourceforge.cruisecontrol.publishers.sfee; 2 3 import java.lang.reflect.InvocationTargetException ; 4 import java.lang.reflect.Method ; 5 6 import junit.framework.Assert; 7 8 public class SfeeTestUtils { 9 private Object inMemorySfee; 10 private boolean notUsingInMemory; 11 12 void loadSfeeInMemory(String serverUrl, String username, String password) { 13 try { 16 Class inMemSfeeFactoryClass = Class.forName("com.vasoftware.sf.InMemorySfeeFactory"); 17 Method resetMethod = inMemSfeeFactoryClass.getMethod("reset", null); 18 resetMethod.invoke(null, null); 19 Method createMethod = inMemSfeeFactoryClass.getMethod("create", new Class [] { String .class, String .class, 20 String .class }); 21 inMemorySfee = createMethod.invoke(null, new Object [] { serverUrl, username, password }); 22 } catch (NoSuchMethodException e) { 23 Assert.fail("Must be using the wrong version of the sfee soap stubs."); 24 } catch (IllegalAccessException e) { 25 Assert.fail("Must be using the wrong version of the sfee soap stubs."); 26 } catch (InvocationTargetException e) { 27 Assert.fail("Must be using the wrong version of the sfee soap stubs."); 28 } catch (ClassNotFoundException e) { 29 notUsingInMemory = true; 33 } 34 } 35 36 void addProject(String projectName) { 37 if (notUsingInMemory) { 38 return; 39 } 40 41 try { 42 Method addProjectMethod = inMemorySfee.getClass().getMethod("addProject", new Class [] { String .class }); 43 addProjectMethod.invoke(inMemorySfee, new Object [] { projectName }); 44 } catch (NoSuchMethodException e) { 45 Assert.fail("Must be using the wrong version of the sfee soap stubs."); 46 } catch (IllegalAccessException e) { 47 Assert.fail("Must be using the wrong version of the sfee soap stubs."); 48 } catch (InvocationTargetException e) { 49 Assert.fail("Must be using the wrong version of the sfee soap stubs."); 50 } 51 } 52 53 void addTracker(String trackerName, String projectName) { 54 if (notUsingInMemory) { 55 return; 56 } 57 58 try { 59 Method addTracker = inMemorySfee.getClass().getMethod("addTracker", 60 new Class [] { String .class, String .class }); 61 addTracker.invoke(inMemorySfee, new Object [] { trackerName, projectName }); 62 } catch (NoSuchMethodException e) { 63 Assert.fail("Must be using the wrong version of the sfee soap stubs."); 64 } catch (IllegalAccessException e) { 65 Assert.fail("Must be using the wrong version of the sfee soap stubs."); 66 } catch (InvocationTargetException e) { 67 Assert.fail("Must be using the wrong version of the sfee soap stubs."); 68 } 69 } 70 71 void createFolders(String projectName, String path) { 72 if (notUsingInMemory) { 73 return; 74 } 75 76 try { 77 Method createFolders = inMemorySfee.getClass().getMethod("createFolders", 78 new Class [] { String .class, String .class }); 79 createFolders.invoke(inMemorySfee, new Object [] { projectName, path }); 80 } catch (NoSuchMethodException e) { 81 Assert.fail("Must be using the wrong version of the sfee soap stubs."); 82 } catch (IllegalAccessException e) { 83 Assert.fail("Must be using the wrong version of the sfee soap stubs."); 84 } catch (InvocationTargetException e) { 85 Assert.fail("Must be using the wrong version of the sfee soap stubs."); 86 } 87 } 88 } 89 | Popular Tags |