package org.jenkinsci.plugins.p4_client.client; 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.FreeStyleProject; import hudson.model.ParametersAction; import hudson.model.StringParameterValue; import hudson.util.FormValidation; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import net.sf.json.JSONObject; import org.jenkinsci.plugins.p4_client.P4Server; import org.jenkinsci.plugins.p4_client.PerforceScm; import org.jenkinsci.plugins.p4_client.credentials.P4PasswordImpl; import org.jenkinsci.plugins.p4_client.workspace.ManualWorkspaceImpl; import org.jenkinsci.plugins.p4_client.workspace.StaticWorkspaceImpl; import org.jenkinsci.plugins.p4_client.workspace.StreamWorkspaceImpl; import org.jenkinsci.plugins.p4_client.workspace.TemplateWorkspaceImpl; import org.jenkinsci.plugins.p4_client.workspace.Workspace; import org.jenkinsci.plugins.p4_client.workspace.WorkspaceDescriptor; import org.jenkinsci.plugins.p4_client.workspace.WorkspaceSpec; import org.junit.Test; import org.jvnet.hudson.test.HudsonTestCase; import com.cloudbees.plugins.credentials.CredentialsDescriptor; import com.cloudbees.plugins.credentials.CredentialsScope; import com.cloudbees.plugins.credentials.SystemCredentialsProvider; import com.perforce.p4java.server.IOptionsServer; public class ConnectionTest extends HudsonTestCase { private final String credential = "id"; private final static String P4ROOT = "tmp-p4root"; private final static String P4PORT = "localhost:1999"; private final int LOG_LIMIT = 1000; private final static P4Server p4d = new P4Server("p4d", P4ROOT, P4PORT); static { 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()); try { p4d.clean(); } catch (IOException e) { fail("P4ROOT still exists, please clean up. " + P4ROOT); } File root = new File(P4ROOT); assertTrue(root.exists()); try { p4d.restore(ckp); } catch (Exception e) { fail("P4D failed to restore checkpoint"); } try { p4d.upgrade(); } catch (Exception e) { fail("P4D failed to upgrade server"); } try { p4d.extract(depot); } catch (Exception e) { fail("P4D failed to extract depot: " + depot.getName()); } } @Test public void testCheckP4d() { try { int ver = p4d.getVersion(); assertTrue(ver >= 20121); } catch (Exception e) { fail("Perforce Server P4D was not found"); } } @Test public void testStartStopServer() { try { p4d.start(); } catch (Exception e) { fail("P4D failed to start server"); } finally { try { p4d.stop(); } catch (Exception e) { fail("P4D failed to stop server"); } } } @Test public void testFreeStyleProject_buildHead() throws Exception { try { p4d.start(); P4PasswordImpl auth = new P4PasswordImpl(CredentialsScope.SYSTEM, credential, "desc", P4PORT, null, "jenkins", "jenkins"); SystemCredentialsProvider.getInstance().getCredentials().add(auth); SystemCredentialsProvider.getInstance().save(); FreeStyleProject project = createFreeStyleProject("Static-Head"); Workspace workspace = new StaticWorkspaceImpl("none", "test.ws"); PerforceScm scm = new PerforceScm(credential, workspace); project.setScm(scm); project.save(); FreeStyleBuild build; UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause).get(); assertBuildStatus(Result.SUCCESS, build); List<String> log = build.getLog(LOG_LIMIT); assertTrue(log.contains("SCM Task: syncing files at HEAD")); 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); } catch (Exception e) { fail("Failed to run FreeStyleProject: " + e.getCause()); e.printStackTrace(); } finally { try { p4d.stop(); } catch (Exception e) { fail("P4D failed to stop server"); } } } @Test public void testFreeStyleProject_buildChange() throws Exception { try { p4d.start(); P4PasswordImpl auth = new P4PasswordImpl(CredentialsScope.SYSTEM, credential, "desc", P4PORT, null, "jenkins", "jenkins"); SystemCredentialsProvider.getInstance().getCredentials().add(auth); SystemCredentialsProvider.getInstance().save(); FreeStyleProject project = createFreeStyleProject("Static-Change"); Workspace workspace = new StaticWorkspaceImpl("none", "test.ws"); PerforceScm scm = new PerforceScm(credential, workspace); project.setScm(scm); project.save(); List<ParameterValue> list = new ArrayList<ParameterValue>(); list.add(new StringParameterValue("status", "committed")); list.add(new StringParameterValue("change", "9")); Action actions = new ParametersAction(list); FreeStyleBuild build; UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause, actions).get(); assertBuildStatus(Result.SUCCESS, build); List<String> log = build.getLog(LOG_LIMIT); assertTrue(log.contains("SCM Task: syncing files at change: 9")); } catch (Exception e) { fail("Failed to run FreeStyleProject: " + e.getCause()); e.printStackTrace(); } finally { try { p4d.stop(); } catch (Exception e) { fail("P4D failed to stop server"); } } } @Test public void testFreeStyleProject_buildShelf() throws Exception { try { p4d.start(); P4PasswordImpl auth = new P4PasswordImpl(CredentialsScope.SYSTEM, credential, "desc", P4PORT, null, "jenkins", "jenkins"); SystemCredentialsProvider.getInstance().getCredentials().add(auth); SystemCredentialsProvider.getInstance().save(); FreeStyleProject project = createFreeStyleProject("Static-Shelf"); Workspace workspace = new StaticWorkspaceImpl("none", "test.ws"); PerforceScm scm = new PerforceScm(credential, workspace); project.setScm(scm); project.save(); List<ParameterValue> list = new ArrayList<ParameterValue>(); list.add(new StringParameterValue("status", "shelved")); list.add(new StringParameterValue("review", "19")); Action actions = new ParametersAction(list); FreeStyleBuild build; UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause, actions).get(); assertBuildStatus(Result.SUCCESS, build); List<String> log = build.getLog(LOG_LIMIT); assertTrue(log.contains("SCM Task: unshelve review: 19")); } catch (Exception e) { fail("Failed to run FreeStyleProject: " + e.getCause()); e.printStackTrace(); } finally { try { p4d.stop(); } catch (Exception e) { fail("P4D failed to stop server"); } } } @Test public void testFreeStyleProject_ManualWs() throws Exception { try { p4d.start(); 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 = createFreeStyleProject("Manual-Head"); Workspace workspace = new ManualWorkspaceImpl("none", client, spec); PerforceScm scm = new PerforceScm(credential, workspace); project.setScm(scm); project.save(); FreeStyleBuild build; UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause).get(); assertBuildStatus(Result.SUCCESS, build); } catch (Exception e) { fail("Failed to run FreeStyleProject: " + e.getCause()); e.printStackTrace(); } finally { try { p4d.stop(); } catch (Exception e) { fail("P4D failed to stop server"); } } } @Test public void testFreeStyleProject_TemplateWs() throws Exception { try { p4d.start(); 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 = createFreeStyleProject("Template-Head"); Workspace workspace = new TemplateWorkspaceImpl("none", client, format); PerforceScm scm = new PerforceScm(credential, workspace); project.setScm(scm); project.save(); FreeStyleBuild build; UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause).get(); assertBuildStatus(Result.SUCCESS, build); } catch (Exception e) { fail("Failed to run FreeStyleProject: " + e.getCause()); e.printStackTrace(); } finally { try { p4d.stop(); } catch (Exception e) { fail("P4D failed to stop server"); } } } @Test public void testFreeStyleProject_StreamWs() throws Exception { try { p4d.start(); 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 = createFreeStyleProject("Stream-Head"); Workspace workspace = new StreamWorkspaceImpl("none", stream, format); PerforceScm scm = new PerforceScm(credential, workspace); project.setScm(scm); project.save(); FreeStyleBuild build; UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause).get(); assertBuildStatus(Result.SUCCESS, build); } catch (Exception e) { fail("Failed to run FreeStyleProject: " + e.getCause()); e.printStackTrace(); } finally { try { p4d.stop(); } catch (Exception e) { fail("P4D failed to stop server"); } } } public void testManualWorkspaceImpl() throws Exception { try { p4d.start(); 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 = createFreeStyleProject("Manual"); ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", client, spec); PerforceScm scm = new PerforceScm(credential, workspace); project.setScm(scm); project.save(); WorkspaceDescriptor desc = workspace.getDescriptor(); assertNotNull(desc); assertEquals("Manual (custom view)", desc.getDisplayName()); ManualWorkspaceImpl.DescriptorImpl impl = (ManualWorkspaceImpl.DescriptorImpl) desc; FormValidation form = impl.doCheckName("test.ws"); assertEquals(FormValidation.Kind.OK, form.kind); AutoCompletionCandidates list = impl.doAutoCompleteName("t"); assertTrue(list.getValues().contains("test.ws")); JSONObject json = workspace.getSpecJSON("test.ws"); assertEquals("//depot/... //test.ws/...\n", json.getString("view")); IOptionsServer p4 = ConnectionFactory.getConnection(); p4.disconnect(); json = workspace.getSpecJSON("test.ws"); assertEquals("please define view...", json.getString("view")); } catch (Exception e) { fail("Failed to run FreeStyleProject: " + e.getCause()); e.printStackTrace(); } finally { try { p4d.stop(); } catch (Exception e) { fail("P4D failed to stop server"); } } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#21 | 9672 | Paul Allen | Refactor name from 'p4_client' to 'p4'. | ||
#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. |