Skip to content

Commit

Permalink
Convert TFS's Changeset and Change to our ChangeSet and Item, respect…
Browse files Browse the repository at this point in the history
…ively.
  • Loading branch information
olivierdagenais committed Oct 4, 2013
1 parent 6efa14d commit 77bd362
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main/java/hudson/plugins/tfs/model/Project.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
import hudson.plugins.tfs.commands.GetFilesToWorkFolderCommand;
import hudson.plugins.tfs.commands.RemoteChangesetVersionCommand;
import hudson.plugins.tfs.commands.WorkspaceChangesetVersionCommand;
import hudson.plugins.tfs.model.ChangeSet.Item;

import java.io.IOException;
import java.io.Reader;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

import com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Change;

public class Project {

private final String projectPath;
Expand All @@ -30,6 +34,30 @@ public String getProjectPath() {
return projectPath;
}

static hudson.plugins.tfs.model.ChangeSet.Item convertServerChange
(com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Change serverChange) {
final String path = serverChange.getItem().getServerItem();
final String action = serverChange.getChangeType().toUIString(true);
final Item result = new Item(path, action);
return result;
}

static hudson.plugins.tfs.model.ChangeSet convertServerChangeset
(com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Changeset serverChangeset) {
final String version = Integer.toString(serverChangeset.getChangesetID(), 10);
final Date date = serverChangeset.getDate().getTime();
final String author = serverChangeset.getCommitter();
final String comment = serverChangeset.getComment();

final ChangeSet result = new ChangeSet(version, date, author, comment);
final Change[] serverChanges = serverChangeset.getChanges();
for (final Change serverChange : serverChanges) {
final Item item = convertServerChange(serverChange);
result.add(item);
}
return result;
}

/**
* Returns a list of change sets containing modified items.
* @param fromTimestamp the timestamp to get history from
Expand Down
54 changes: 54 additions & 0 deletions src/test/java/hudson/plugins/tfs/model/ProjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,70 @@

import java.io.Reader;
import java.io.StringReader;
import java.util.Calendar;
import java.util.List;

import hudson.plugins.tfs.SwedishLocaleTestCase;
import hudson.plugins.tfs.Util;
import hudson.plugins.tfs.model.ChangeSet.Item;
import hudson.plugins.tfs.util.MaskedArgumentListBuilder;

import org.junit.Test;

import com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Change;
import com.microsoft.tfs.core.clients.versioncontrol.soapextensions.ChangeType;
import com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Changeset;
import com.microsoft.tfs.core.clients.versioncontrol.soapextensions.ItemType;

public class ProjectTest extends SwedishLocaleTestCase {

private com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Change createServerChange() {
final com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Item serverItem
= new com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Item();
serverItem.setItemType(ItemType.FILE);
serverItem.setServerItem("$/tfsandbox");
final com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Change serverChange
= new Change(serverItem, ChangeType.ADD, null);
return serverChange;
}

@Test
public void assertConvertServerChange() throws Exception {
final com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Change serverChange = createServerChange();

final Item actual = Project.convertServerChange(serverChange);

assertEquals("$/tfsandbox", actual.getPath());
assertEquals("add", actual.getAction());
}

@Test
public void assertConvertServerChangeset() throws Exception {
final com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Change serverChange = createServerChange();
final String comment = "Created team project folder $/tfsandbox via the Team Project Creation Wizard";
final Calendar juneTwentySeventh = Util.getCalendar(2008, 06, 27, 11, 16, 06);
final String userString = "RNO\\_MCLWEB";
Changeset serverChangeset = new Changeset(userString, comment, null, null);
serverChangeset.setChangesetID(12472);
serverChangeset.setCommitter(userString);
serverChangeset.setDate(juneTwentySeventh);
final Change[] changes = new Change[] { serverChange };
serverChangeset.setChanges(changes);

hudson.plugins.tfs.model.ChangeSet actual = Project.convertServerChangeset(serverChangeset);

assertEquals("The version was incorrect", "12472", actual.getVersion());
assertEquals("The user was incorrect", "_MCLWEB", actual.getUser());
assertEquals("The user was incorrect", "RNO", actual.getDomain());
assertEquals("The date was incorrect", juneTwentySeventh.getTime(), actual.getDate());
assertEquals("The comment was incorrect", comment, actual.getComment());

Item item = actual.getItems().get(0);
assertEquals("The item path was incorrect", "$/tfsandbox", item.getPath());
assertEquals("The item action was incorrect", "add", item.getAction());

}

@Test
public void assertGetDetailedHistory() throws Exception {
Server server = mock(Server.class);
Expand Down

0 comments on commit 77bd362

Please sign in to comment.