package org.jenkinsci.plugins.p4; import com.cloudbees.plugins.credentials.CredentialsScope; import com.cloudbees.plugins.credentials.SystemCredentialsProvider; import hudson.FilePath; import hudson.Launcher; import hudson.model.AbstractBuild; import hudson.model.BuildListener; import hudson.model.Cause; import hudson.model.FreeStyleBuild; import hudson.model.FreeStyleProject; import hudson.model.Result; import hudson.tasks.Builder; import org.jenkinsci.plugins.p4.client.ClientHelper; import org.jenkinsci.plugins.p4.credentials.P4PasswordImpl; 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.Publish; 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.StaticWorkspaceImpl; import org.jenkinsci.plugins.p4.workspace.Workspace; import org.jenkinsci.plugins.p4.workspace.WorkspaceSpec; import org.jvnet.hudson.test.JenkinsRule; import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.logging.Handler; import java.util.logging.LogRecord; 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 R18_1 = "r18.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, String p4port, String id) throws IOException { CredentialsScope scope = CredentialsScope.GLOBAL; P4PasswordImpl auth = new P4PasswordImpl(scope, id, "desc", p4port, null, user, "0", "0", null, password); 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 Workspace defaultWorkspace(String name) { StaticWorkspaceImpl workspace = new StaticWorkspaceImpl("none", false, name); return workspace; } 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 = "submit.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, null, null, true); ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", true, client, spec); workspace.setExpand(new HashMap<String, String>()); File wsRoot = new File("target/submit.ws").getAbsoluteFile(); workspace.setRootPath(wsRoot.toString()); File file = new File(wsRoot + File.separator + filename).getAbsoluteFile(); FilePath filePath = new FilePath(file); filePath.delete(); filePath.write(content, "UTF-8"); ClientHelper p4 = new ClientHelper(jenkins.getInstance(), CREDENTIAL, null, workspace); Publish publish = new SubmitImpl("Submit test files", false, false, false, null); boolean open = p4.buildChange(publish); if (open) { p4.publishChange(publish); } filePath.delete(); } 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()); } public class TestHandler extends Handler { private StringBuffer sb = new StringBuffer(); @Override public void publish(LogRecord record) { sb.append(record.getMessage()); sb.append("\n"); } @Override public void flush() { } @Override public void close() throws SecurityException { } public String getLogBuffer() { return sb.toString(); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#8 | 24428 | Paul Allen |
Merging using p4-jenkins_main>dev @24406 - @24411 |
||
#7 | 24426 | Paul Allen |
Merging using p4-jenkins_main>dev @24402 @24403 @24404 |
||
#6 | 24421 | Paul Allen | Test fixes relating to change 24233 | ||
#5 | 24420 | Paul Allen |
Merging using p4-jenkins_main>dev @24233 |
||
#4 | 23951 | Paul Allen | Merging using p4-jenkins_main>dev | ||
#3 | 23862 | Paul Allen | Merging using p4-jenkins_main>dev | ||
#2 | 23820 | Paul Allen | Merging using p4-jenkins_main>dev | ||
#1 | 23685 | Paul Allen | Copy main -> dev | ||
//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). |