提交 7d248e35 编写于 作者: J Jesse Glick

Merge pull request #1507 from darxriggs/no-more-GroovyHudsonTestCase

not using the deprecated GroovyHudsonTestCase anymore
......@@ -23,17 +23,23 @@
*/
package hudson
import org.jvnet.hudson.test.GroovyHudsonTestCase
import org.junit.Rule
import org.junit.Test
import org.jvnet.hudson.test.JenkinsRule
/**
* First groovy test!
*
* @author Kohsuke Kawaguchi
*/
public class GroovyTest extends GroovyHudsonTestCase {
void test1() {
def wc = createWebClient();
wc.goTo("/");
public class GroovyTest {
@Rule
public JenkinsRule j = new JenkinsRule()
@Test
void test() {
def wc = j.createWebClient();
wc.goTo("");
}
}
\ No newline at end of file
}
......@@ -23,57 +23,65 @@
*/
package hudson.model
import static hudson.util.FormValidation.Kind.ERROR
import static hudson.util.FormValidation.Kind.WARNING
import static org.junit.Assert.assertNotNull
import static org.junit.Assert.assertEquals
import hudson.slaves.DumbSlave
import hudson.slaves.JNLPLauncher
import hudson.util.FormValidation
import org.jvnet.hudson.test.GroovyHudsonTestCase
import org.junit.Rule
import org.junit.Test
import org.apache.commons.io.IOUtils
import hudson.slaves.JNLPLauncher
import static hudson.util.FormValidation.Kind.ERROR
import static hudson.util.FormValidation.Kind.WARNING
import org.jvnet.hudson.test.GroovyJenkinsRule
/**
*
*
* @author Kohsuke Kawaguchi
*/
public class SlaveTest extends GroovyHudsonTestCase {
class SlaveTest {
@Rule
public GroovyJenkinsRule j = new GroovyJenkinsRule()
/**
* Makes sure that a form validation method gets inherited.
*/
void testFormValidation() {
executeOnServer {
assertNotNull(jenkins.getDescriptor(DumbSlave.class).getCheckUrl("remoteFS"))
@Test
void formValidation() {
j.executeOnServer {
assertNotNull(j.jenkins.getDescriptor(DumbSlave).getCheckUrl("remoteFS"))
}
}
/**
* Programmatica config.xml submission.
* Programmatic config.xml submission.
*/
void testSlaveConfigDotXml() {
DumbSlave s = createSlave();
def wc = createWebClient()
def p = wc.goTo("/computer/${s.name}/config.xml","application/xml");
@Test
void slaveConfigDotXml() {
DumbSlave s = j.createSlave()
def wc = j.createWebClient()
def p = wc.goTo("computer/${s.name}/config.xml", "application/xml")
def xml = p.webResponse.contentAsString
new XmlSlurper().parseText(xml) // verify that it is XML
// make sure it survives the roundtrip
post("/computer/${s.name}/config.xml",xml);
post("computer/${s.name}/config.xml",xml);
assertNotNull(jenkins.getNode(s.name))
assertNotNull(j.jenkins.getNode(s.name))
xml = IOUtils.toString(getClass().getResource("SlaveTest/slave.xml").openStream());
xml = xml.replace("NAME",s.name)
post("/computer/${s.name}/config.xml",xml);
post("computer/${s.name}/config.xml",xml);
s = jenkins.getNode(s.name)
s = j.jenkins.getNode(s.name)
assertNotNull(s)
assertEquals("some text",s.nodeDescription)
assertEquals(JNLPLauncher.class,s.launcher.class)
}
def post(url,String xml) {
HttpURLConnection con = new URL(this.getURL(),url).openConnection();
HttpURLConnection con = new URL(j.getURL(),url).openConnection();
con.requestMethod = "POST"
con.setRequestProperty("Content-Type","application/xml;charset=UTF-8")
con.setRequestProperty(".crumb","test")
......@@ -83,8 +91,9 @@ public class SlaveTest extends GroovyHudsonTestCase {
IOUtils.copy(con.inputStream,System.out)
}
public void testRemoteFsCheck() {
def d = jenkins.getDescriptorByType(DumbSlave.DescriptorImpl.class)
@Test
void remoteFsCheck() {
def d = j.jenkins.getDescriptorByType(DumbSlave.DescriptorImpl.class)
assert d.doCheckRemoteFS("c:\\")==FormValidation.ok();
assert d.doCheckRemoteFS("/tmp")==FormValidation.ok();
assert d.doCheckRemoteFS("relative/path").kind==ERROR;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册