I guess it was just an oversight from Kohsuke to put these tests under src/main as Maven won't run them if not located under src/test

This commit is contained in:
Christoph Kutzinski committed 2012-06-24 14:08:56 +02:00
1 parent 4b828e4e63
commit a2f2ae9b2b
2 files changed

No files matched your search

@@ -1,76 +0,0 @@
package jenkins.scm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.model.FreeStyleProject;
import hudson.model.Item;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.TestExtension;
import hudson.model.AbstractProject;
import org.kohsuke.stapler.DataBoundConstructor;
import hudson.model.AbstractBuild.AbstractBuildExecution;
import org.xml.sax.SAXException;
import java.io.IOException;
/**
*
*
* @author Kohsuke Kawaguchi
*/
public class SCMCheckoutStrategyTest extends HudsonTestCase {
public void testConfigRoundtrip() throws Exception {
assertEquals(1,SCMCheckoutStrategyDescriptor.all().size());
FreeStyleProject p = createFreeStyleProject();
assertFalse(pageHasUI(p)); // no configuration UI because there's only one option
}
/**
* This should show the UI.
*/
public void testConfigRoundtrip2() throws Exception {
assertEquals(2,SCMCheckoutStrategyDescriptor.all().size());
FreeStyleProject p = createFreeStyleProject();
System.out.println(SCMCheckoutStrategyDescriptor.all());
TestSCMCheckoutStrategy before = new TestSCMCheckoutStrategy();
p.setScmCheckoutStrategy(before);
configRoundtrip((Item)p);
SCMCheckoutStrategy after = p.getScmCheckoutStrategy();
assertNotSame(before,after);
assertSame(before.getClass(), after.getClass());
assertTrue(pageHasUI(p));
}
private boolean pageHasUI(FreeStyleProject p) throws IOException, SAXException {
HtmlPage page = createWebClient().getPage(p, "configure");
return page.getWebResponse().getContentAsString().contains("Advanced Source Code Management");
}
@SuppressWarnings("rawtypes")
public static class TestSCMCheckoutStrategy extends SCMCheckoutStrategy {
@DataBoundConstructor
public TestSCMCheckoutStrategy() {
}
@Override
public void checkout(AbstractBuildExecution execution) throws IOException, InterruptedException {
execution.getListener().getLogger().println("Hello!");
super.checkout(execution);
}
@TestExtension("testConfigRoundtrip2")
public static class DescriptorImpl extends SCMCheckoutStrategyDescriptor {
@Override
public boolean isApplicable(AbstractProject project) {
return true;
}
@Override
public String getDisplayName() {
return getClass().getName();
}
}
}
}
@@ -1,63 +0,0 @@
package jenkins.security;
import com.gargoylesoftware.htmlunit.HttpWebConnection;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.model.User;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScheme;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.auth.CredentialsNotAvailableException;
import org.apache.commons.httpclient.auth.CredentialsProvider;
import org.jvnet.hudson.test.HudsonTestCase;
import java.util.concurrent.Callable;
/**
* @author Kohsuke Kawaguchi
*/
public class ApiTokenPropertyTest extends HudsonTestCase {
/**
* Tests the UI interaction and authentication.
*/
public void testBasics() throws Exception {
jenkins.setSecurityRealm(createDummySecurityRealm());
User u = User.get("foo");
ApiTokenProperty t = u.getProperty(ApiTokenProperty.class);
final String token = t.getApiToken();
// make sure the UI shows the token
HtmlPage config = createWebClient().goTo(u.getUrl() + "/configure");
HtmlForm form = config.getFormByName("config");
assertEquals(token, form.getInputByName("_.apiToken").getValueAttribute());
// round-trip shouldn't change the API token
submit(form);
assertSame(t, u.getProperty(ApiTokenProperty.class));
WebClient wc = createWebClient();
wc.setCredentialsProvider(new CredentialsProvider() {
public Credentials getCredentials(AuthScheme scheme, String host, int port, boolean proxy) throws CredentialsNotAvailableException {
return new UsernamePasswordCredentials("foo", token);
}
});
wc.setWebConnection(new HttpWebConnection(wc) {
@Override
protected HttpClient getHttpClient() {
HttpClient c = super.getHttpClient();
c.getParams().setAuthenticationPreemptive(true);
c.getState().setCredentials(new AuthScope("localhost", localPort, AuthScope.ANY_REALM), new UsernamePasswordCredentials("foo", token));
return c;
}
});
// test the authentication
assertEquals(u,wc.executeOnServer(new Callable<User>() {
public User call() throws Exception {
return User.current();
}
}));
}
}