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 net.sourceforge.jwebunit.WebTestCase; 48 import net.sourceforge.cruisecontrol.Configuration; 49 50 import org.jdom.JDOMException; 51 52 public class ProjectConfigurationPageWebTest extends WebTestCase { 53 private static final String CONFIG_URL = "/cruisecontrol/config.jspa?project=connectfour"; 54 private static final String CONTENTS_URL = "/cruisecontrol/contents.jspa?project=connectfour"; 55 private final String contents; 56 private Configuration configuration; 57 58 public ProjectConfigurationPageWebTest() throws MalformedObjectNameException , IOException , 59 AttributeNotFoundException , InstanceNotFoundException , MBeanException , ReflectionException , JDOMException { 60 configuration = createConfig(); 61 contents = configuration.getConfiguration(); 62 } 63 64 protected void setUp() throws Exception { 65 super.setUp(); 66 getTestContext().setBaseUrl("http://localhost:7854"); 67 configuration = createConfig(); 68 } 69 70 protected void tearDown() throws Exception { 71 super.tearDown(); 72 configuration.setConfiguration(contents); 73 configuration.save(); 74 } 75 76 public void testShouldLinkToRawXMLConfigurationData() { 77 beginAt(CONFIG_URL); 78 assertLinkPresentWithImage("xml.png"); 79 clickLinkWithImage("xml.png"); 80 assertTitleEquals("CruiseControl Raw XML Configuration"); 81 } 82 83 public void testShouldLinkBackToMainPage() { 84 beginAt(CONTENTS_URL); 85 assertLinkPresentWithText("Return to configuration editor"); 86 clickLinkWithText("Return to configuration editor"); 87 assertFormPresent("reload-configuration"); 88 } 89 90 public void testShouldReloadConfiguration() throws Exception { 91 testLoad(); 92 gotoPage(CONFIG_URL); 93 setWorkingForm("reload-configuration"); 94 submit(); 95 assertTextPresent("Reloaded configuration"); 96 assertTextNotPresent("Hello, world!"); 97 } 98 99 public void testShouldLoadRawXMLConfigurationData() { 100 beginAt(CONTENTS_URL); 101 assertFormPresent("project-configuration"); 102 assertFormElementPresent("contents"); 103 assertTextPresent("<cruisecontrol>"); 104 assertTextPresent("</cruisecontrol>"); 105 } 106 107 public void testShouldSaveChangesToXMLConfigurationData() throws Exception { 108 beginAt(CONTENTS_URL); 109 setWorkingForm("project-configuration"); 110 setFormElement("contents", contents + "<!-- Hello, world! -->"); 111 submit(); 112 assertFormPresent("project-configuration"); 113 assertFormElementPresent("contents"); 114 assertTextPresent("<cruisecontrol>"); 115 assertTextPresent("</cruisecontrol>"); 116 assertTextPresent("<!-- Hello, world! -->"); 117 } 118 119 public void testLoad() throws Exception { 120 String newContent = "<!-- Hello, world! -->"; 121 122 beginAt(CONTENTS_URL); 123 assertFormPresent("project-configuration"); 124 setWorkingForm("project-configuration"); 125 setFormElement("contents", contents + "<!-- Hello, world! -->"); 126 submit(); 127 assertFormPresent("project-configuration"); 128 assertFormElementPresent("contents"); 129 assertTextPresent("<cruisecontrol>"); 130 assertTextPresent("</cruisecontrol>"); 131 assertTextPresent(newContent); 132 } 133 134 private static Configuration createConfig() throws IOException , MalformedObjectNameException { 135 return new Configuration("localhost", 7856); 136 } 137 } 138 | Popular Tags |