public List<Workspace> call() throws Exception { final Server server = createServer(); final MockableVersionControlClient vcc = server.getVersionControlClient(); final TaskListener listener = server.getListener(); final PrintStream logger = listener.getLogger(); final String listWorkspacesMessage = String.format(ListingWorkspacesTemplate, server.getUrl()); logger.println(listWorkspacesMessage); final com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Workspace[] sdkWorkspaces = vcc.queryWorkspaces( null, null, Util.fixEmpty(computer), WorkspacePermissions.NONE_OR_NOT_SUPPORTED); final List<Workspace> result = new ArrayList<Workspace>(sdkWorkspaces.length); for (final com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Workspace sdkWorkspace : sdkWorkspaces) { final String name = sdkWorkspace.getName(); final String computer = sdkWorkspace.getComputer(); final String ownerName = sdkWorkspace.getOwnerName(); final String comment = Util.fixNull(sdkWorkspace.getComment()); final Workspace workspace = new Workspace(name, computer, ownerName, comment); result.add(workspace); } log(result, logger); return result; }
@Override public void setup(JenkinsRule jenkinsRule, EndToEndTfs recipe) throws Exception { final Description testDescription = jenkinsRule.getTestDescription(); final Class clazz = testDescription.getTestClass(); testClassName = clazz.getSimpleName(); testCaseName = testDescription.getMethodName(); final String hostName = IntegrationTestHelper.tryToDetermineHostName(); final File currentFolder = new File("").getAbsoluteFile(); final File workspaces = new File(currentFolder, "workspaces"); // TODO: Consider NOT using the Server class server = new Server(null, null, serverUrl, helper.getUserName(), helper.getUserPassword()); final MockableVersionControlClient vcc = server.getVersionControlClient(); // workspaceName MUST be unique across computers hitting the same server workspaceName = hostName + "-" + testCaseName; workspace = createWorkspace(vcc, workspaceName); pathInTfvc = IntegrationTestHelper.determinePathInTfvcForTestCase(testDescription); final File localTestClassFolder = new File(workspaces, testClassName); localBaseFolderFile = new File(localTestClassFolder, testCaseName); //noinspection ResultOfMethodCallIgnored localBaseFolderFile.mkdirs(); final String localBaseFolder = localBaseFolderFile.getAbsolutePath(); final WorkingFolder workingFolder = new WorkingFolder(pathInTfvc, localBaseFolder); workspace.createWorkingFolder(workingFolder); // TODO: Is this necessary if we're about to delete it, anyway? workspace.get(GetOptions.NONE); // Delete the folder associated with this test in TFVC workspace.pendDelete( new String[] {pathInTfvc}, RecursionType.FULL, LockLevel.UNCHANGED, GetOptions.NONE, PendChangesOptions.NONE); checkIn("Cleaning up for the " + testCaseName + " test."); // we don't need to verify this check-in, because a first run on a server will be a no-op // create the folder in TFVC workspace.pendAdd( new String[] {localBaseFolder}, false, null, LockLevel.UNCHANGED, GetOptions.NONE, PendChangesOptions.NONE); final int changeSet = checkIn("Setting up for the " + testCaseName + " test."); Assert.assertTrue(changeSet >= 0); final Class<? extends StubRunner> runnerClass = recipe.value(); if (runnerClass != null) { runner = runnerClass.newInstance(); runner.setParent(this); runner.setHelper(this.helper); runner.setup(jenkinsRule, recipe); } }
@Override public void tearDown(JenkinsRule jenkinsRule, EndToEndTfs recipe) throws Exception { if (runner != null) { runner.tearDown(jenkinsRule, recipe); } final MockableVersionControlClient vcc = server.getVersionControlClient(); deleteWorkspace(vcc, workspaceName); if (server != null) { server.close(); } }