-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Matt Sicker <boards@gmail.com>
- Loading branch information
Showing
2 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/test/java/com/cloudbees/plugins/credentials/CredentialsParametersActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.cloudbees.plugins.credentials; | ||
|
||
import com.cloudbees.plugins.credentials.common.IdCredentials; | ||
import com.cloudbees.plugins.credentials.domains.Domain; | ||
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl; | ||
import hudson.model.Cause; | ||
import hudson.model.FreeStyleBuild; | ||
import hudson.model.FreeStyleProject; | ||
import hudson.model.ParametersAction; | ||
import hudson.model.ParametersDefinitionProperty; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
|
||
public class CredentialsParametersActionTest { | ||
|
||
@ClassRule public static JenkinsRule j = new JenkinsRule(); | ||
|
||
@BeforeClass | ||
public static void setUpClass() throws IOException { | ||
j.jenkins.setSecurityRealm(j.createDummySecurityRealm()); | ||
CredentialsProvider.lookupStores(j.jenkins).iterator().next() | ||
.addCredentials(Domain.global(), new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "cred-id", "global credential", "root", "correct horse battery staple")); | ||
} | ||
|
||
@Test | ||
public void forRunReturnsNullWhenRunHasNoParameters() throws Exception { | ||
final FreeStyleProject project = j.createFreeStyleProject(); | ||
final FreeStyleBuild build = j.assertBuildStatusSuccess(project.scheduleBuild2(0)); | ||
assertNull(CredentialsParametersAction.forRun(build)); | ||
} | ||
|
||
@Test | ||
public void forRunCopiesParametersWhenRunIsParameterized() throws Exception { | ||
final FreeStyleProject project = j.createFreeStyleProject(); | ||
project.addProperty(new ParametersDefinitionProperty(new CredentialsParameterDefinition("cred", "", null, IdCredentials.class.getName(), true))); | ||
final CredentialsParameterValue parameterValue = new CredentialsParameterValue("cred", "cred-id", "", false, "alpha"); | ||
final FreeStyleBuild build = j.assertBuildStatusSuccess(project.scheduleBuild2(0, new Cause.UserIdCause("alpha"), new ParametersAction(parameterValue))); | ||
final CredentialsParametersAction action = CredentialsParametersAction.forRun(build); | ||
assertNotNull(action); | ||
assertEquals(parameterValue, action.findParameterByName("cred")); | ||
} | ||
} |