1 37 package net.sourceforge.cruisecontrol.webtest; 38 39 import java.io.IOException ; 40 41 import javax.management.AttributeNotFoundException ; 42 import javax.management.InstanceNotFoundException ; 43 import javax.management.MBeanException ; 44 import javax.management.MalformedObjectNameException ; 45 import javax.management.ReflectionException ; 46 47 import junit.framework.TestCase; 48 import net.sourceforge.cruisecontrol.sourcecontrols.ConcurrentVersionsSystem; 49 import net.sourceforge.cruisecontrol.Configuration; 50 import net.sourceforge.cruisecontrol.PluginDetail; 51 import net.sourceforge.cruisecontrol.GenericPluginDetail; 52 import net.sourceforge.cruisecontrol.PluginConfiguration; 53 import net.sourceforge.cruisecontrol.CruiseControlException; 54 55 import org.jdom.JDOMException; 56 57 public class ConfigurationTest extends TestCase { 58 private final String contents; 59 private Configuration configuration; 60 61 public ConfigurationTest() throws MalformedObjectNameException , IOException , AttributeNotFoundException , 62 InstanceNotFoundException , MBeanException , ReflectionException , JDOMException { 63 configuration = createConfig(); 64 contents = configuration.getConfiguration(); 65 } 66 67 protected void setUp() throws Exception { 68 super.setUp(); 69 configuration = createConfig(); 70 } 71 72 protected void tearDown() throws Exception { 73 super.tearDown(); 74 configuration.setConfiguration(contents); 75 configuration.save(); 76 } 77 78 public void testGetConfiguration() throws Exception { 79 String contents = getContents(); 80 String xmlHdr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; 81 assertTrue(contents.indexOf(xmlHdr) == 0); 82 assertTrue(contents.indexOf("<cruisecontrol>") != -1); 83 assertTrue(contents.indexOf("</cruisecontrol>") != -1); 84 } 85 86 public void testSetConfiguration() throws Exception { 87 String addContent = "<!-- Hello, world! -->"; 88 configuration.setConfiguration(getContents() + addContent); 89 assertTrue(getContents().indexOf(addContent) != -1); 90 } 91 92 public void testCanUpdatePluginConfiguration() throws Exception { 93 String addContent = "projects/foobar"; 94 PluginDetail cvsDetail = new GenericPluginDetail("cvs", ConcurrentVersionsSystem.class); 95 PluginConfiguration pluginConfiguration = new PluginConfiguration(cvsDetail, configuration); 96 pluginConfiguration.setDetail("cvsRoot", "projects/foobar"); 97 configuration.updatePluginConfiguration(pluginConfiguration); 98 assertTrue(getContents().indexOf(addContent) != -1); 99 } 100 101 public void testGetPluginDetails() throws Exception { 102 PluginDetail[] pluginDetails = configuration.getPluginDetails(); 103 assertNotNull(pluginDetails); 104 assertTrue(0 < pluginDetails.length); 105 } 106 107 public void testLoad() throws Exception { 108 String addContent = "<!-- Hello, world! -->"; 109 configuration.setConfiguration(getContents() + addContent); 110 configuration.load(); 111 assertTrue(getContents().indexOf(addContent) == -1); 112 } 113 114 public void testSave() throws Exception { 115 String addContent = "<!-- Hello, world! -->"; 116 configuration.setConfiguration(getContents() + addContent); 117 configuration.save(); 118 configuration.load(); 119 assertTrue(getContents().indexOf(addContent) != -1); 120 } 121 122 public void testGetConfiguredBootstrappers() throws CruiseControlException, AttributeNotFoundException , 123 InstanceNotFoundException , MBeanException , ReflectionException , IOException , JDOMException { 124 PluginDetail[] bootstrappers = configuration.getConfiguredBootstrappers("connectfour"); 125 assertNotNull(bootstrappers); 126 assertTrue(1 == bootstrappers.length); 127 } 128 129 public void testGetConfiguredListeners() throws AttributeNotFoundException , InstanceNotFoundException , 130 MBeanException , ReflectionException , IOException , CruiseControlException, JDOMException { 131 PluginDetail[] listeners = configuration.getConfiguredListeners("connectfour"); 132 assertNotNull(listeners); 133 assertTrue(1 == listeners.length); 134 } 135 136 public void testGetConfiguredSourceControls() throws AttributeNotFoundException , InstanceNotFoundException , 137 MBeanException , ReflectionException , IOException , CruiseControlException, JDOMException { 138 PluginDetail[] sourceControls = configuration.getConfiguredSourceControls("connectfour"); 139 assertNotNull(sourceControls); 140 assertTrue(1 == sourceControls.length); 141 } 142 143 private static Configuration createConfig() throws IOException , MalformedObjectNameException { 144 return new Configuration("localhost", 7856); 145 } 146 147 private String getContents() throws AttributeNotFoundException , InstanceNotFoundException , MBeanException , 148 ReflectionException , IOException , JDOMException { 149 return configuration.getConfiguration(); 150 } 151 } 152 | Popular Tags |