Skip to content

Commit

Permalink
Merge pull request #14 from jglick/tests
Browse files Browse the repository at this point in the history
Test fixes
  • Loading branch information
jglick authored Dec 2, 2016
2 parents 1671973 + 2c3125c commit 9434d52
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
11 changes: 9 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.7</version>
<version>2.19</version>
<relativePath/>
</parent>
<artifactId>build-token-root</artifactId>
<version>1.5-SNAPSHOT</version>
Expand All @@ -27,9 +28,15 @@
<properties>
<jenkins.version>1.580.1</jenkins.version>
<java.level>6</java.level>
<workflow.version>1.4.3-beta-1</workflow.version>
<workflow.version>1.4.3</workflow.version>
</properties>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>${workflow.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,19 @@

package org.jenkinsci.plugins.build_token_root;

import com.gargoylesoftware.htmlunit.ElementNotFoundException;
import com.gargoylesoftware.htmlunit.HttpMethod;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.util.NameValuePair;
import hudson.model.AbstractProject;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Job;
import hudson.model.ParametersAction;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.Run;
import hudson.model.StringParameterDefinition;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
Expand All @@ -56,7 +55,6 @@
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.recipes.PresetData;
import org.xml.sax.SAXException;

@SuppressWarnings({"deprecation", "unchecked"}) // RunList.size, BuildAuthorizationToken, AbstractItem.getParent snafu
public class BuildRootActionTest {
Expand Down Expand Up @@ -93,13 +91,19 @@ private <JobT extends Job<JobT, RunT> & ParameterizedJobMixIn.ParameterizedJob,
assertEquals(2, p.getBuilds().size());
}

private <JobT extends Job<JobT, RunT> & ParameterizedJobMixIn.ParameterizedJob, RunT extends Run<JobT, RunT>> void setAuthToken(JobT p) throws IOException, ElementNotFoundException, Exception, SAXException {
private <JobT extends Job<JobT, RunT> & ParameterizedJobMixIn.ParameterizedJob, RunT extends Run<JobT, RunT>> void setAuthToken(JobT p) throws Exception {
// TODO should this be a method in ParameterizedJob?
Field authTokenF = (p instanceof AbstractProject ? AbstractProject.class : p.getClass()).getDeclaredField("authToken");
authTokenF.setAccessible(true);
authTokenF.set(p, new hudson.model.BuildAuthorizationToken("secret"));
/* Too slow:
JenkinsRule.WebClient wc = j.createWebClient();
wc.login("alice", "alice");
HtmlForm form = wc.getPage(p, "configure").getFormByName("config");
form.getInputByName("pseudoRemoteTrigger").setChecked(true);
form.getInputByName("authToken").setValueAttribute("secret");
j.submit(form);
*/
hudson.model.BuildAuthorizationToken token = p.getAuthToken();
assertNotNull(token);
assertEquals("secret", token.getToken());
Expand Down

0 comments on commit 9434d52

Please sign in to comment.