package org.jenkinsci.plugins.p4.client; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import hudson.model.Action; import hudson.model.AutoCompletionCandidates; import hudson.model.FreeStyleBuild; import hudson.model.ParameterValue; import hudson.model.Result; import hudson.model.Cause; import hudson.model.Cause.UserIdCause; import hudson.model.Descriptor; import hudson.model.FreeStyleProject; import hudson.model.ParametersAction; import hudson.model.StringParameterValue; import hudson.scm.RepositoryBrowser; import hudson.scm.SCMDescriptor; import hudson.util.FormValidation; import hudson.util.LogTaskListener; import hudson.util.ListBoxModel; import java.io.File; import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import net.sf.json.JSONObject; import org.jenkinsci.plugins.p4.DummyServer; import org.jenkinsci.plugins.p4.P4Server; import org.jenkinsci.plugins.p4.PerforceScm; import org.jenkinsci.plugins.p4.PerforceScm.DescriptorImpl; import org.jenkinsci.plugins.p4.browsers.P4WebBrowser; import org.jenkinsci.plugins.p4.browsers.SwarmBrowser; import org.jenkinsci.plugins.p4.credentials.P4PasswordImpl; import org.jenkinsci.plugins.p4.filters.Filter; import org.jenkinsci.plugins.p4.filters.FilterPerChangeImpl; 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.workspace.ManualWorkspaceImpl; import org.jenkinsci.plugins.p4.workspace.StaticWorkspaceImpl; import org.jenkinsci.plugins.p4.workspace.StreamWorkspaceImpl; import org.jenkinsci.plugins.p4.workspace.TemplateWorkspaceImpl; import org.jenkinsci.plugins.p4.workspace.Workspace; import org.jenkinsci.plugins.p4.workspace.WorkspaceDescriptor; import org.jenkinsci.plugins.p4.workspace.WorkspaceSpec; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.JenkinsRule; import com.cloudbees.plugins.credentials.CredentialsDescriptor; import com.cloudbees.plugins.credentials.CredentialsScope; import com.cloudbees.plugins.credentials.SystemCredentialsProvider; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.perforce.p4java.Metadata; public class ConnectionTest { private static Logger logger = Logger.getLogger(ConnectionTest.class .getName()); private final String credential = "id"; private static String PWD = System.getProperty("user.dir") + "/"; private static String P4BIN = "src/test/resources/r14.1/"; private final static String P4ROOT = "tmp-p4root"; private final static String P4PORT = "localhost:1999"; private final static int HTTP_PORT = 1888; private final static String HTTP_URL = "http://localhost:" + HTTP_PORT; private final int LOG_LIMIT = 1000; private final static P4Server p4d = new P4Server(PWD + P4BIN, P4ROOT, P4PORT); @Rule public JenkinsRule jenkins = new JenkinsRule(); @BeforeClass public static void setupServer() throws Exception { File ckp = new File("src/test/resources/checkpoint.gz"); assertTrue(ckp.exists()); File depot = new File("src/test/resources/depot.tar.gz"); assertTrue(depot.exists()); p4d.clean(); File root = new File(P4ROOT); assertTrue(root.exists()); p4d.restore(ckp); p4d.upgrade(); p4d.extract(depot); // start pseudo web server startHttpServer(HTTP_PORT); } @Before public void startServer() throws Exception { p4d.start(); } @After public void stopServer() throws Exception { p4d.stop(); } @AfterClass public static void cleanServer() throws Exception { p4d.clean(); } @Test public void testCheckP4d() throws Exception { int ver = p4d.getVersion(); assertTrue(ver >= 20121); } @Test public void testCredentialsList() throws Exception { P4PasswordImpl auth = new P4PasswordImpl(CredentialsScope.SYSTEM, credential, "desc", P4PORT, null, "jenkins", "jenkins"); SystemCredentialsProvider.getInstance().getCredentials().add(auth); SystemCredentialsProvider.getInstance().save(); FreeStyleProject project = jenkins .createFreeStyleProject("Static-Head"); Workspace workspace = new StaticWorkspaceImpl("none", "test.ws"); Populate populate = new AutoCleanImpl(true, true, false, null); PerforceScm scm = new PerforceScm(credential, workspace, populate); project.setScm(scm); project.save(); SCMDescriptor<?> desc = project.getScm().getDescriptor(); assertNotNull(desc); PerforceScm.DescriptorImpl impl = (DescriptorImpl) desc; ListBoxModel list = impl.doFillCredentialItems(); assertTrue(list.size() == 1); FormValidation form = impl.doCheckCredential(credential); assertEquals(FormValidation.Kind.OK, form.kind); } @Test public void testFreeStyleProject_buildHead() throws Exception { P4PasswordImpl auth = new P4PasswordImpl(CredentialsScope.SYSTEM, credential, "desc", P4PORT, null, "jenkins", "jenkins"); SystemCredentialsProvider.getInstance().getCredentials().add(auth); SystemCredentialsProvider.getInstance().save(); FreeStyleProject project = jenkins .createFreeStyleProject("Static-Head"); Workspace workspace = new StaticWorkspaceImpl("none", "test.ws"); Populate populate = new AutoCleanImpl(true, true, false, null); PerforceScm scm = new PerforceScm(credential, workspace, populate); project.setScm(scm); project.save(); FreeStyleBuild build; UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause).get(); assertEquals(Result.SUCCESS, build.getResult()); List<String> log = build.getLog(LOG_LIMIT); assertTrue(log.contains("SCM Task: syncing files at change: 40")); CredentialsDescriptor desc = auth.getDescriptor(); assertNotNull(desc); assertEquals("Perforce Password Credential", desc.getDisplayName()); P4PasswordImpl.DescriptorImpl impl = (P4PasswordImpl.DescriptorImpl) desc; FormValidation form = impl.doTestConnection(P4PORT, "false", null, "jenkins", "jenkins"); assertEquals(FormValidation.Kind.OK, form.kind); } @Test public void testFreeStyleProject_buildChange() throws Exception { P4PasswordImpl auth = new P4PasswordImpl(CredentialsScope.SYSTEM, credential, "desc", P4PORT, null, "jenkins", "jenkins"); SystemCredentialsProvider.getInstance().getCredentials().add(auth); SystemCredentialsProvider.getInstance().save(); FreeStyleProject project = jenkins .createFreeStyleProject("Static-Change"); StaticWorkspaceImpl workspace = new StaticWorkspaceImpl("none", "test.ws"); Populate populate = new AutoCleanImpl(true, true, false, null); 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(), "committed")); list.add(new StringParameterValue(ReviewProp.CHANGE.toString(), "9")); Action actions = new ParametersAction(list); FreeStyleBuild build; 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("SCM Task: syncing files at change: 9")); // Check web pages for changes HtmlPage page = jenkins.createWebClient().getPage(build); String text = page.asText(); assertTrue(text.contains("9 by jenkins@jenkins.data.ws")); page = jenkins.createWebClient().getPage(build, "changes"); text = page.asText(); assertTrue(text.contains("//depot/Main/file-11.txt#4")); // Check workspace descriptors WorkspaceDescriptor desc = workspace.getDescriptor(); assertNotNull(desc); assertEquals("Static (static view, master only)", desc.getDisplayName()); ListBoxModel charsets = desc.doFillCharsetItems(); assertTrue(charsets.size() > 1); // Log in for next set of tests... ConnectionHelper p4 = new ConnectionHelper(auth); p4.login(); StaticWorkspaceImpl.DescriptorImpl impl = (StaticWorkspaceImpl.DescriptorImpl) desc; FormValidation form = impl.doCheckName("test.ws"); assertEquals(FormValidation.Kind.OK, form.kind); AutoCompletionCandidates clients = impl.doAutoCompleteName("j"); assertTrue(clients.getValues().contains("jenkins.data.ws")); } @Test public void testFreeStyleProject_buildLabel() throws Exception { P4PasswordImpl auth = new P4PasswordImpl(CredentialsScope.SYSTEM, credential, "desc", P4PORT, null, "jenkins", "jenkins"); SystemCredentialsProvider.getInstance().getCredentials().add(auth); SystemCredentialsProvider.getInstance().save(); URL url = new URL("http://localhost"); P4WebBrowser browser = new P4WebBrowser(url); FreeStyleProject project = jenkins .createFreeStyleProject("Static-Change"); StaticWorkspaceImpl workspace = new StaticWorkspaceImpl("none", "test.ws"); Populate populate = new AutoCleanImpl(true, true, false, null); PerforceScm scm = new PerforceScm(credential, workspace, null, populate, browser); project.setScm(scm); project.save(); List<ParameterValue> list = new ArrayList<ParameterValue>(); list.add(new StringParameterValue(ReviewProp.STATUS.toString(), "committed")); list.add(new StringParameterValue(ReviewProp.LABEL.toString(), "auto15")); list.add(new StringParameterValue(ReviewProp.PASS.toString(), HTTP_URL + "/pass")); Action actions = new ParametersAction(list); FreeStyleBuild build; 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("SCM Task: syncing files at change: 15")); // Check web pages for changes HtmlPage page = jenkins.createWebClient().getPage(build); String text = page.asText(); assertTrue(text.contains("15 by jenkins@jenkins.data.ws")); page = jenkins.createWebClient().getPage(build, "changes"); text = page.asText(); assertTrue(text.contains("//depot/Main/file-14.txt #7")); page = jenkins.createWebClient().getPage(build, "tagBuild"); HtmlForm label = page.getFormByName("label"); label.submit(); page = jenkins.createWebClient().getPage(build, "tagBuild"); text = page.asText(); assertTrue(text.contains("Build-1\tJenkinsBuild: #1\tjenkins\t@15")); // Check browser Descriptor<RepositoryBrowser<?>> desc = browser.getDescriptor(); assertNotNull(desc); P4WebBrowser.DescriptorImpl impl = (P4WebBrowser.DescriptorImpl) desc; FormValidation form = impl.doCheck(url.toString()); assertEquals(FormValidation.Kind.OK, form.kind); } @Test public void testFreeStyleProject_buildShelf() throws Exception { P4PasswordImpl auth = new P4PasswordImpl(CredentialsScope.SYSTEM, credential, "desc", P4PORT, null, "jenkins", "jenkins"); SystemCredentialsProvider.getInstance().getCredentials().add(auth); SystemCredentialsProvider.getInstance().save(); URL url = new URL("http://localhost"); SwarmBrowser browser = new SwarmBrowser(url); FreeStyleProject project = jenkins .createFreeStyleProject("Static-Shelf"); Workspace workspace = new StaticWorkspaceImpl("none", "test.ws"); Populate populate = new AutoCleanImpl(true, true, false, null); PerforceScm scm = new PerforceScm(credential, workspace, null, populate, browser); 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")); list.add(new StringParameterValue(ReviewProp.PASS.toString(), HTTP_URL + "/pass")); Action actions = new ParametersAction(list); FreeStyleBuild build; 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("SCM Task: unshelve review: 19")); // Check web pages for changes HtmlPage page = jenkins.createWebClient().getPage(build); String text = page.asText(); assertTrue(text.contains("19 by admin@admin.ws")); page = jenkins.createWebClient().getPage(build, "changes"); text = page.asText(); assertTrue(text.contains("Shelved Files:")); // Check browser Descriptor<RepositoryBrowser<?>> desc = browser.getDescriptor(); assertNotNull(desc); SwarmBrowser.DescriptorImpl impl = (SwarmBrowser.DescriptorImpl) desc; FormValidation form = impl.doCheck(url.toString()); assertEquals(FormValidation.Kind.OK, form.kind); } @Test public void testFreeStyleProject_ManualWs() throws Exception { P4PasswordImpl auth = new P4PasswordImpl(CredentialsScope.SYSTEM, credential, "desc", P4PORT, null, "jenkins", "jenkins"); SystemCredentialsProvider.getInstance().getCredentials().add(auth); SystemCredentialsProvider.getInstance().save(); 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", client, spec); Populate populate = new AutoCleanImpl(true, true, false, null); PerforceScm scm = new PerforceScm(credential, workspace, populate); project.setScm(scm); project.save(); FreeStyleBuild build; 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 { P4PasswordImpl auth = new P4PasswordImpl(CredentialsScope.SYSTEM, credential, "desc", P4PORT, null, "jenkins", "jenkins"); SystemCredentialsProvider.getInstance().getCredentials().add(auth); SystemCredentialsProvider.getInstance().save(); String client = "test.ws"; String format = "jenkins-${node}-${project}.ws"; FreeStyleProject project = jenkins .createFreeStyleProject("Template-Head"); TemplateWorkspaceImpl workspace = new TemplateWorkspaceImpl("none", client, format); Populate populate = new AutoCleanImpl(true, true, false, null); PerforceScm scm = new PerforceScm(credential, workspace, populate); project.setScm(scm); project.save(); FreeStyleBuild build; 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 = impl.doAutoCompleteTemplateName("t"); assertTrue(list.getValues().contains("test.ws")); form = impl.doCheckFormat(format); assertEquals(FormValidation.Kind.OK, form.kind); } @Test public void testFreeStyleProject_StreamWs() throws Exception { P4PasswordImpl auth = new P4PasswordImpl(CredentialsScope.SYSTEM, credential, "desc", P4PORT, null, "jenkins", "jenkins"); SystemCredentialsProvider.getInstance().getCredentials().add(auth); SystemCredentialsProvider.getInstance().save(); String stream = "//stream/main"; String format = "jenkins-${node}-${project}.ws"; FreeStyleProject project = jenkins .createFreeStyleProject("Stream-Head"); StreamWorkspaceImpl workspace = new StreamWorkspaceImpl("none", stream, format); Populate populate = new AutoCleanImpl(true, true, false, null); PerforceScm scm = new PerforceScm(credential, workspace, populate); project.setScm(scm); project.save(); FreeStyleBuild build; 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(); StreamWorkspaceImpl.DescriptorImpl impl = (StreamWorkspaceImpl.DescriptorImpl) desc; FormValidation form = impl.doCheckStreamName("//stream/main"); assertEquals(FormValidation.Kind.OK, form.kind); AutoCompletionCandidates list = impl.doAutoCompleteStreamName("//"); assertTrue(list.getValues().contains("//stream/main")); form = impl.doCheckFormat(format); assertEquals(FormValidation.Kind.OK, form.kind); } @Test public void testTPI83() throws Exception { P4PasswordImpl auth = new P4PasswordImpl(CredentialsScope.SYSTEM, credential, "desc", P4PORT, null, "jenkins", "jenkins"); SystemCredentialsProvider.getInstance().getCredentials().add(auth); SystemCredentialsProvider.getInstance().save(); FreeStyleProject project = jenkins.createFreeStyleProject("TPI83"); Workspace workspace = new StaticWorkspaceImpl("none", "test.ws"); Populate populate = new AutoCleanImpl(true, true, false, null); PerforceScm scm = new PerforceScm(credential, workspace, populate); project.setScm(scm); project.save(); FreeStyleBuild build; UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause).get(); assertEquals(Result.SUCCESS, build.getResult()); String filename = "add_@%#$%^&().txt"; String path = build.getWorkspace() + "/" + filename; File add = new File(path); add.createNewFile(); build = project.scheduleBuild2(0, cause).get(); assertEquals(Result.SUCCESS, build.getResult()); } @Test public void testTPI95() throws Exception { P4PasswordImpl auth = new P4PasswordImpl(CredentialsScope.SYSTEM, credential, "desc", P4PORT, null, "jenkins", "jenkins"); SystemCredentialsProvider.getInstance().getCredentials().add(auth); SystemCredentialsProvider.getInstance().save(); String client = "test.ws"; String format = "jenkins-${node}-${project}.ws"; FreeStyleProject project = jenkins .createFreeStyleProject("Template-Head"); TemplateWorkspaceImpl workspace = new TemplateWorkspaceImpl("none", client, format); Populate populate = new AutoCleanImpl(true, true, false, null); 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 ParametersAction(list); FreeStyleBuild build; 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("SCM Task: unshelve review: 19")); // TPI-95 Second build with template ws build = project.scheduleBuild2(0, cause).get(); assertEquals(Result.SUCCESS, build.getResult()); } @Test public void testPolling_Pin() throws Exception { P4PasswordImpl auth = new P4PasswordImpl(CredentialsScope.SYSTEM, credential, "desc", P4PORT, null, "jenkins", "jenkins"); SystemCredentialsProvider.getInstance().getCredentials().add(auth); SystemCredentialsProvider.getInstance().save(); String client = "manual.ws"; String stream = null; String line = "LOCAL"; String view = "//depot/... //" + 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", client, spec); // Pin at label auto15 Populate populate = new AutoCleanImpl(true, true, false, "auto15"); PerforceScm scm = new PerforceScm(credential, workspace, populate); project.setScm(scm); project.save(); // Build at change 3 List<ParameterValue> list = new ArrayList<ParameterValue>(); list.add(new StringParameterValue(ReviewProp.STATUS.toString(), "submitted")); list.add(new StringParameterValue(ReviewProp.CHANGE.toString(), "3")); Action actions = new ParametersAction(list); FreeStyleBuild build; UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause, actions).get(); assertEquals(Result.SUCCESS, build.getResult()); // Poll for changes LogTaskListener listener = new LogTaskListener(logger, Level.INFO); project.poll(listener); List<Integer> buildList = scm.getChanges(); assertEquals(12, buildList.size()); } @Test public void testPolling_Inc() throws Exception { P4PasswordImpl auth = new P4PasswordImpl(CredentialsScope.SYSTEM, credential, "desc", P4PORT, null, "jenkins", "jenkins"); SystemCredentialsProvider.getInstance().getCredentials().add(auth); SystemCredentialsProvider.getInstance().save(); String client = "manual.ws"; String stream = null; String line = "LOCAL"; String view = "//depot/... //" + 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", client, spec); // Pin at label auto15 Populate populate = new AutoCleanImpl(true, true, false, "auto15"); List<Filter> filter = new ArrayList<Filter>(); FilterPerChangeImpl inc = new FilterPerChangeImpl(true); filter.add(inc); PerforceScm scm = new PerforceScm(credential, workspace, filter, populate, null); project.setScm(scm); project.save(); // Build at change 3 List<ParameterValue> list = new ArrayList<ParameterValue>(); list.add(new StringParameterValue(ReviewProp.STATUS.toString(), "submitted")); list.add(new StringParameterValue(ReviewProp.CHANGE.toString(), "3")); Action actions = new ParametersAction(list); FreeStyleBuild build; UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause, actions).get(); assertEquals(Result.SUCCESS, build.getResult()); // Poll for changes incrementally LogTaskListener listener = new LogTaskListener(logger, Level.INFO); project.poll(listener); List<Integer> buildList = scm.getChanges(); assertEquals(1, buildList.size()); int change = buildList.get(0); assertEquals(4, change); } @Test public void testManual_Modtime() throws Exception { P4PasswordImpl auth = new P4PasswordImpl(CredentialsScope.SYSTEM, credential, "desc", P4PORT, null, "jenkins", "jenkins"); SystemCredentialsProvider.getInstance().getCredentials().add(auth); SystemCredentialsProvider.getInstance().save(); String client = "modtime.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_Modtime"); ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", client, spec); boolean isModtime = true; Populate populate = new AutoCleanImpl(true, true, isModtime, null); PerforceScm scm = new PerforceScm(credential, workspace, populate); project.setScm(scm); project.save(); FreeStyleBuild build; UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause).get(); assertEquals(Result.SUCCESS, build.getResult()); // Log in for next set of tests... ClientHelper p4 = new ClientHelper(auth, null, client); boolean mod = p4.getClient().getOptions().isModtime(); assertEquals(true, mod); // Check file exists with the correct date String ws = build.getWorkspace().getRemote(); File file = new File(ws + "/file-0.dat"); assertEquals(true, file.exists()); String ver = Metadata.getP4JVersionString(); logger.info("P4Java Version: " + ver); long epoch = file.lastModified(); assertEquals(1397049803000L, epoch); } private static void startHttpServer(int port) throws Exception { DummyServer server = new DummyServer(port); new Thread(server).start(); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 11337 | Paul Allen | Merge down latest changes from MAIN | ||
#1 | 11053 | Paul Allen | Branching using p4-jenkins | ||
//guest/perforce_software/p4jenkins/main/src/test/java/org/jenkinsci/plugins/p4/client/ConnectionTest.java | |||||
#9 | 10841 | Paul Allen |
Support for 2014.1 reconcile by MODTIME Feature allows a user check the option ‘Sync with MODTIME for consistency check’ under the ‘Populate’ option to enable reconcile to check files based on MODTIME. Includes test case for MODTIME and minor fix for fetching a Label when there is no previous change. JENKINS-25341 |
||
#8 | 10802 | Paul Allen |
Test cases for SCM Polling Added test case for Polling with Limits (pinning) and Incremental. |
||
#7 | 10775 | Paul Allen |
Fix change detection when using a moving label If a build was pinned or built from a label, the label name was recorded <buildChange>. If the label is updated between builds then comparing against an earlier build will give you the wrong result. This fix stores the automatic label ‘Revision’ field and stores this in <buildChange>. NOTE: you will need to run a manual build to flush the label, so that the last build has a change number. JENKINS-25300 |
||
#6 | 10755 | Paul Allen |
Separate name space for 'label' parameter. Perforce Review endpoint added `label`, `change`, `status`, `pass`, and `fail` parameter into the environment, which is a shared name space. This clashed with the default `label` matrix name and causing users issues. The change prefixes the review parameters with `p4.` on addition to the environment. |
||
#5 | 10013 | Paul Allen |
Added Client support to sync check https://issues.jenkins-ci.org/browse/JENKINS-24055 |
||
#4 | 9980 | Paul Allen |
Changed error reporting to use AbortException. - Use direct access of scm attributes, not via build.getProject().getScm() - Improved logging around labels/changes. |
||
#3 | 9851 | Paul Allen | Merging using p4-jenkins | ||
#2 | 9803 | Paul Allen | Merging using p4-jenkins | ||
#1 | 9690 | Paul Allen |
[Branching using p4-jenkins] Release 1.0.1 |
||
//guest/paul_allen/dev/p4-jenkins/p4-client/src/test/java/org/jenkinsci/plugins/p4/client/ConnectionTest.java | |||||
#2 | 9683 | Paul Allen | Added P4D for win/mac/linux, so tests are ready to run. | ||
#1 | 9672 | Paul Allen | Refactor name from 'p4_client' to 'p4'. | ||
//guest/paul_allen/dev/p4-jenkins/p4-client/src/test/java/org/jenkinsci/plugins/p4_client/client/ConnectionTest.java | |||||
#20 | 9472 | Paul Allen |
Added support to pin build at a label in the populate configuration. - includes help and updates to tests. |
||
#19 | 9137 | Paul Allen | Functional tests for tabBuild endpoint (submitting Labels) and browser (P4Web/Swarm) dummy http server checks. | ||
#18 | 9115 | Paul Allen |
Initial implementation of workspace Cleanup and Sync options. - Includes 3 modes: Automatic Clean/Sync, Force Clean/Sync, Sync Only Automatic Clean/Sync Uses reconcile to clean up workspace and sync changes. Force Clean/Sync Force sync of all files (does not remove files yet...) Sync Only Normal sync with no cleanup TODO: - remove of files in Force Clean/Sync mode - Inline help - Update docs - Add unit/functional tests |
||
#17 | 9091 | Paul Allen |
Added Changelist build filtering for SCM polling: - Configuration uses 'repeatableHeteroProperty' - Filter on Perforce username - Filter on Perforce Depot path (no wildcard support) |
||
#16 | 9055 | Paul Allen |
Label support. Build at a label using the pram 'label'. This includes adding the label to the ChangeEntry, building the change reports and Browser links to Swarm. (TPI-102) |
||
#15 | 8969 | Paul Allen |
Adds all contributing change-lists for the build to the change log (using p4 cstat). - Includes exception logging for server connection to the Jenkins console. |
||
#14 | 8940 | Paul Allen |
Major refactor for the ConnectionHelper class to simplify serialisation. Fixed remote Jenkins JNLP slave connection issue. ClientHelper now extends ConnectionHelper and takes on all methods that require a client workspace. P4StandardCredentials is sent to the remote node instead of Credentials ID due to an issue accessing the Credentials store over a remote connection. For simplicity Client ID (workspace name) is serialised instead of the Workspace object. |
||
#13 | 8926 | Paul Allen |
Bug fix when unshelving files with the Template workspace option. p4-java was unable to switch the worksapce view (without the -f flag) if there were files open. - Improved logging (as this error was hidden) - Added test case for this condition. |
||
#12 | 8922 | Paul Allen | Repo Browser unit tests | ||
#11 | 8916 | Paul Allen | Unit tests for ChangeLog feature and minor fix when listing files if the change is Submitted or Shelved. | ||
#10 | 8915 | Paul Allen |
Support for ChangeLog and RepoBrowser. - Added RepoBrowser for Swarm (porting the others should be easy) - ChangeLog XML file now only stores the changelist number all other information is fetched from Perforce |
||
#9 | 8909 | Paul Allen |
[TPI-83] Clean Workspace that may contain files with wildcards. Added (-f) flag to reconcile and ignore warnings for empty files. |
||
#8 | 8908 | Paul Allen |
Test Workspace Spec used for Manual Workspace configuration. (Total coverage ~80%) |
||
#7 | 8902 | Paul Allen |
Updated test cases: Pushed Workspace 'charset' to abstract Workspace class. Minor bugfixes in Workspace AutoCompletionCandidates method. |
||
#6 | 8898 | Paul Allen | Removed Deprecated 'HudsonTestCase' for Jenkins @Rule | ||
#5 | 8888 | Paul Allen |
Extended test coverage for Workspace and Credentials. - Removed ununsed methods. |
||
#4 | 8865 | Paul Allen | System tests for Workspace behaviours (Static, Manual, Template, Stream). | ||
#3 | 8852 | Paul Allen |
Functional test for unshelve. Includes fix for reconcile and unshelve exclusive locked files. |
||
#2 | 8816 | Paul Allen | Functional tests for build @HEAD and @change; includes build console log check. | ||
#1 | 8815 | Paul Allen | P4D test harness. |