package org.jenkinsci.plugins.p4; import com.cloudbees.plugins.credentials.CredentialsScope; import com.cloudbees.plugins.credentials.SystemCredentialsProvider; import hudson.Launcher; import hudson.model.*; import hudson.tasks.Builder; import org.jenkinsci.plugins.p4.credentials.P4PasswordImpl; import org.jenkinsci.plugins.p4.populate.AutoCleanImpl; import org.jenkinsci.plugins.p4.populate.GraphHybridImpl; import org.jenkinsci.plugins.p4.populate.Populate; import org.jenkinsci.plugins.p4.publish.CommitImpl; import org.jenkinsci.plugins.p4.publish.PublishNotifier; import org.jenkinsci.plugins.p4.publish.SubmitImpl; import org.jenkinsci.plugins.p4.workspace.ManualWorkspaceImpl; import org.jenkinsci.plugins.p4.workspace.WorkspaceSpec; import org.jvnet.hudson.test.JenkinsRule; import java.io.IOException; import static org.junit.Assert.assertEquals; abstract public class DefaultEnvironment { protected final static String R15_1 = "r15.1"; protected final static String R17_1 = "r17.1"; protected final static String CREDENTIAL = "id"; protected final static int HTTP_PORT = 1888; protected final static String HTTP_URL = "http://localhost:" + HTTP_PORT; protected final int LOG_LIMIT = 1000; protected P4PasswordImpl createCredentials(String user, String password, SampleServerRule p4d) throws IOException { String p4port = p4d.getRshPort(); CredentialsScope scope = CredentialsScope.GLOBAL; P4PasswordImpl auth = new P4PasswordImpl(scope, CREDENTIAL, "desc", p4port, null, user, "0", "0", null, password); SystemCredentialsProvider.getInstance().getCredentials().clear(); SystemCredentialsProvider.getInstance().getCredentials().add(auth); SystemCredentialsProvider.getInstance().save(); return auth; } protected static void startHttpServer(int port) throws Exception { DummyServer server = new DummyServer(port); new Thread(server).start(); } protected String defaultClient() { String client = "test.ws"; String os = System.getProperty("os.name").toLowerCase(); if (os.contains("win")) { client = "test.win"; } return client; } protected static final class CreateArtifact extends Builder { private final String filename; private final String content; public CreateArtifact(String filename, String content) { this.filename = filename; this.content = content; } @Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { build.getWorkspace().child(filename).write(content, "UTF-8"); return true; } } protected void submitFile(JenkinsRule jenkins, String path, String content) throws Exception { String filename = path.substring(path.lastIndexOf("/") + 1, path.length()); // Create workspace String client = "manual.ws"; String stream = null; String line = "LOCAL"; String view = path + " //" + client + "/" + filename; WorkspaceSpec spec = new WorkspaceSpec(true, true, false, false, false, false, stream, line, view); ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", true, client, spec); // Populate with P4 scm Populate populate = new AutoCleanImpl(); PerforceScm scm = new PerforceScm(CREDENTIAL, workspace, populate); // Freestyle job FreeStyleProject project = jenkins.createFreeStyleProject(); project.setScm(scm); // Create artifact files project.getBuildersList().add(new CreateArtifact(filename, content)); // Submit artifacts SubmitImpl submit = new SubmitImpl("publish", true, true, true, "3"); PublishNotifier publish = new PublishNotifier(CREDENTIAL, workspace, submit); project.getPublishersList().add(publish); project.save(); // Start build Cause.UserIdCause cause = new Cause.UserIdCause(); FreeStyleBuild build = project.scheduleBuild2(0, cause).get(); assertEquals(Result.SUCCESS, build.getResult()); } protected void commitFile(JenkinsRule jenkins, String path, String content) throws Exception { String filename = path.substring(path.lastIndexOf("/") + 1, path.length()); // Create workspace String client = "graphCommit.ws"; String stream = null; String line = "LOCAL"; String view = path + " //" + client + "/" + filename; WorkspaceSpec spec = new WorkspaceSpec(true, true, false, false, false, false, stream, line, view, null, "graph", null, true); ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", true, client, spec); // Populate with P4 scm Populate populate = new GraphHybridImpl(false, null, null); PerforceScm scm = new PerforceScm(CREDENTIAL, workspace, populate); // Freestyle job FreeStyleProject project = jenkins.createFreeStyleProject(); project.setScm(scm); // Create artifact files project.getBuildersList().add(new CreateArtifact(filename, content)); // Submit artifacts CommitImpl commit = new CommitImpl("publish", true, true); commit.addFile(path); PublishNotifier publish = new PublishNotifier(CREDENTIAL, workspace, commit); project.getPublishersList().add(publish); project.save(); // Start build Cause.UserIdCause cause = new Cause.UserIdCause(); FreeStyleBuild build = project.scheduleBuild2(0, cause).get(); assertEquals(Result.SUCCESS, build.getResult()); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 23650 | abraka | "Forking branch Main of p4-jenkins to mautokar-p4jenkins." | ||
//guest/perforce_software/p4jenkins/main/src/test/java/org/jenkinsci/plugins/p4/DefaultEnvironment.java | |||||
#10 | 22163 | Paul Allen |
Manual Workspace support for READONLY and PARTITIONED. Change Type to Enum. JENKINS-39753 |
||
#9 | 22128 | Paul Allen |
Helix Graph support for Jenkins. JENKINS-40354 |
||
#8 | 21936 | Paul Allen |
Refactor tests for 17.1 release. Removed pseudo web server on FreeStyleTest |
||
#7 | 21794 | Paul Allen |
Merge pull request #39 from Dohbedoh/JENKINS-34825 Jenkins 34825 |
||
#6 | 21562 | Paul Allen |
Expand variables for Spec Workspace definitions. Add test to verify variable expansion for name and view. |
||
#5 | 21171 | Paul Allen |
Jenkinsfile basic test. Moved Workflow tests out of Connection test class. |
||
#4 | 21154 | Paul Allen | P4HOST support for connection. | ||
#3 | 21146 | Paul Allen | Test Case support for Windows Clients. | ||
#2 | 20985 | Paul Allen |
Minor fixes to test cases. Clean credential list between tests and use unique names for test Jobs. |
||
#1 | 20980 | Paul Allen |
Functional test upgrade. Switched to RSH pipe for Perforce connection and upgraded to 15.1 P4D binaries. Made use of ClassRule for Jenkins (faster startup) and a Rule for Perforce with separate roots (to allow for parallel test runs). |