package org.jenkinsci.plugins.p4.client; import hudson.model.Action; import hudson.model.AutoCompletionCandidates; import hudson.model.Cause; import hudson.model.Descriptor; import hudson.model.FreeStyleBuild; import hudson.model.FreeStyleProject; import hudson.model.ParameterValue; import hudson.model.Result; import hudson.model.StringParameterValue; import hudson.util.FormValidation; import hudson.util.ListBoxModel; import net.sf.json.JSONObject; import org.jenkinsci.plugins.p4.DefaultEnvironment; import org.jenkinsci.plugins.p4.PerforceScm; import org.jenkinsci.plugins.p4.SampleServerRule; import org.jenkinsci.plugins.p4.credentials.P4PasswordImpl; import org.jenkinsci.plugins.p4.populate.AutoCleanImpl; import org.jenkinsci.plugins.p4.populate.Populate; import org.jenkinsci.plugins.p4.review.ReviewProp; import org.jenkinsci.plugins.p4.review.SafeParametersAction; import org.jenkinsci.plugins.p4.workspace.ManualWorkspaceImpl; import org.jenkinsci.plugins.p4.workspace.StreamWorkspaceImpl; import org.jenkinsci.plugins.p4.workspace.TemplateWorkspaceImpl; import org.jenkinsci.plugins.p4.workspace.WorkspaceDescriptor; import org.jenkinsci.plugins.p4.workspace.WorkspaceSpec; import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.JenkinsRule; import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; /** * Created by pallen on 01/11/2016. */ public class WorkspaceTest extends DefaultEnvironment { private static Logger logger = Logger.getLogger(PollingTest.class.getName()); private static final String P4ROOT = "tmp-WorkspaceTest-p4root"; private static P4PasswordImpl auth; @ClassRule public static JenkinsRule jenkins = new JenkinsRule(); @Rule public SampleServerRule p4d = new SampleServerRule(P4ROOT, VERSION); @Before public void buildCredentials() throws Exception { auth = createCredentials("jenkins", "jenkins", p4d); } @Test public void testFreeStyleProject_ManualWs() throws Exception { String client = "manual.ws"; String stream = null; String line = "LOCAL"; String view = "//depot/Data/... //" + client + "/..."; WorkspaceSpec spec = new WorkspaceSpec(false, false, false, false, false, false, stream, line, view); FreeStyleProject project = jenkins.createFreeStyleProject("Manual-Head"); ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", false, client, spec); Populate populate = new AutoCleanImpl(); PerforceScm scm = new PerforceScm(CREDENTIAL, workspace, populate); project.setScm(scm); project.save(); FreeStyleBuild build; Cause.UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause).get(); assertEquals(Result.SUCCESS, build.getResult()); WorkspaceDescriptor desc = workspace.getDescriptor(); assertNotNull(desc); assertEquals("Manual (custom view)", desc.getDisplayName()); Descriptor<WorkspaceSpec> descSpec = spec.getDescriptor(); assertNotNull(descSpec); assertEquals("Perforce Client Spec", descSpec.getDisplayName()); // Log in for next set of tests... ConnectionHelper p4 = new ConnectionHelper(auth); p4.login(); WorkspaceSpec.DescriptorImpl implSpec = (WorkspaceSpec.DescriptorImpl) descSpec; AutoCompletionCandidates list = implSpec.doAutoCompleteStreamName("//"); assertTrue(list.getValues().contains("//stream/main")); ListBoxModel lineItems = implSpec.doFillLineItems(); assertFalse(lineItems.isEmpty()); ManualWorkspaceImpl.DescriptorImpl impl = (ManualWorkspaceImpl.DescriptorImpl) desc; FormValidation form = impl.doCheckName("test.ws"); assertEquals(FormValidation.Kind.OK, form.kind); list = impl.doAutoCompleteName("m"); assertTrue(list.getValues().contains(client)); JSONObject json = workspace.getSpecJSON("test.ws"); assertEquals("//depot/... //test.ws/...\n", json.getString("view")); p4.disconnect(); json = workspace.getSpecJSON("test.ws"); assertEquals("please define view...", json.getString("view")); } @Test public void testFreeStyleProject_TemplateWs() throws Exception { String client = "test.ws"; String format = "jenkins-${node}-${project}.ws"; FreeStyleProject project = jenkins.createFreeStyleProject("Template-Head"); TemplateWorkspaceImpl workspace = new TemplateWorkspaceImpl("none", false, client, format); Populate populate = new AutoCleanImpl(); PerforceScm scm = new PerforceScm(CREDENTIAL, workspace, populate); project.setScm(scm); project.save(); FreeStyleBuild build; Cause.UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause).get(); assertEquals(Result.SUCCESS, build.getResult()); WorkspaceDescriptor desc = workspace.getDescriptor(); assertNotNull(desc); assertEquals("Template (view generated for each node)", desc.getDisplayName()); // Log in for next set of tests... ConnectionHelper p4 = new ConnectionHelper(auth); p4.login(); TemplateWorkspaceImpl.DescriptorImpl impl = (TemplateWorkspaceImpl.DescriptorImpl) desc; FormValidation form = impl.doCheckTemplateName("test.ws"); assertEquals(FormValidation.Kind.OK, form.kind); AutoCompletionCandidates list = WorkspaceDescriptor.doAutoCompleteTemplateName("t"); assertTrue(list.getValues().contains("test.ws")); form = WorkspaceDescriptor.doCheckFormat(format); assertEquals(FormValidation.Kind.OK, form.kind); } @Test public void testFreeStyleProject_StreamWs() throws Exception { String stream = "//stream/main"; String format = "jenkins-${node}-${project}.ws"; FreeStyleProject project = jenkins.createFreeStyleProject("Stream-Head"); StreamWorkspaceImpl workspace = new StreamWorkspaceImpl("none", false, stream, format); Populate populate = new AutoCleanImpl(); PerforceScm scm = new PerforceScm(CREDENTIAL, workspace, populate); project.setScm(scm); project.save(); FreeStyleBuild build; Cause.UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause).get(); assertEquals(Result.SUCCESS, build.getResult()); WorkspaceDescriptor desc = workspace.getDescriptor(); assertNotNull(desc); assertEquals("Streams (view generated by Perforce for each node)", desc.getDisplayName()); // Log in for next set of tests... ConnectionHelper p4 = new ConnectionHelper(auth); p4.login(); FormValidation form = WorkspaceDescriptor.doCheckStreamName("//stream/main"); assertEquals(FormValidation.Kind.OK, form.kind); AutoCompletionCandidates list = WorkspaceDescriptor.doAutoCompleteStreamName("//"); assertTrue(list.getValues().contains("//stream/main")); form = WorkspaceDescriptor.doCheckFormat(format); assertEquals(FormValidation.Kind.OK, form.kind); // delete worksapce project.doDoWipeOutWorkspace(); } @Test public void testTPI95() throws Exception { String client = "test.ws"; String format = "jenkins-${node}-${project}.ws"; FreeStyleProject project = jenkins.createFreeStyleProject("TPI95"); TemplateWorkspaceImpl workspace = new TemplateWorkspaceImpl("none", false, client, format); Populate populate = new AutoCleanImpl(); PerforceScm scm = new PerforceScm(CREDENTIAL, workspace, populate); project.setScm(scm); project.save(); List<ParameterValue> list = new ArrayList<ParameterValue>(); list.add(new StringParameterValue(ReviewProp.STATUS.toString(), "shelved")); list.add(new StringParameterValue(ReviewProp.REVIEW.toString(), "19")); Action actions = new SafeParametersAction(new ArrayList<ParameterValue>(), list); FreeStyleBuild build; Cause.UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause, actions).get(); assertEquals(Result.SUCCESS, build.getResult()); List<String> log = build.getLog(LOG_LIMIT); assertTrue(log.contains("P4 Task: unshelve review: 19")); // TPI-95 Second build with template ws build = project.scheduleBuild2(0, cause).get(); assertEquals(Result.SUCCESS, build.getResult()); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#13 | 29476 | Paul Allen |
Merge pull request #174 from skumar7322/UpdateJenkins346 Update Jenkins Version to 2.346.3 |
||
#12 | 26673 | Paul Allen |
Code cleanup - remove calls to Deprecated methods - Deprecated classes like AbstractStepImpl, AbstractStepDescriptorImpl and AbstractSynchronousStepExecution for P4TaggingStep |
||
#11 | 25688 | Paul Allen |
Raise errors for execMap "client -i" in SpecWorkspaceImpl. JENKINS-52679 |
||
#10 | 24529 | Paul Allen |
Swarm Commit Event support, refactoring and test. JENKINS-52605 (Fix doc in 'Includes' help bubble for MultiBranch) JENKINS-52066 (Improve Swarm Commit and Branch Event support) |
||
#9 | 24487 | Paul Allen | Perforce Connection Refactor. | ||
#8 | 23819 | Paul Allen | Cleanup test cases to use Credential ID. | ||
#7 | 23796 | Paul Allen |
Look for the expanded original name when updating the view. Added test case for Job names with a '/' restricted character. JENKINS-50393 |
||
#6 | 22701 | Paul Allen |
SyncID to ignore clone ID in workspace name. Tracking build history during concurrent builds. |
||
#5 | 22163 | Paul Allen |
Manual Workspace support for READONLY and PARTITIONED. Change Type to Enum. JENKINS-39753 |
||
#4 | 22128 | Paul Allen |
Helix Graph support for Jenkins. JENKINS-40354 |
||
#3 | 21936 | Paul Allen |
Refactor tests for 17.1 release. Removed pseudo web server on FreeStyleTest |
||
#2 | 21562 | Paul Allen |
Expand variables for Spec Workspace definitions. Add test to verify variable expansion for name and view. |
||
#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). |