Permalink
Browse files

Merge remote-tracking branch 'imk/master'

* added test for changesets
  • Loading branch information...
2 parents 72ee5a3 + ba27eca commit 0c0f767f45c1eef87af51e1aad83099324044b63 @maxkar committed May 21, 2012
@@ -45,7 +45,7 @@
// these values MUST BE exactly as they are written here,
// can't use capital letters or rename.
// they are provided in "?include=..." HTTP request
- journals, relations, attachments
+ journals, relations, attachments, changesets
}
private final Transport transport;
@@ -0,0 +1,116 @@
+package org.redmine.ta.beans;
+
+import java.util.Date;
+
+/**
+ * Repository Change for a Redmine issue
+ * @author Martin Kurz
+ */
+public class Changeset {
+ private String revision;
+ private User user;
+ private String comments;
+ private Date commitedOn;
+
+ public String getRevision() {
+ return revision;
+ }
+
+ public void setRevision(String revision) {
+ this.revision = revision;
+ }
+
+ public User getUser() {
+ return user;
+ }
+
+ public void setUser(User user) {
+ this.user = user;
+ }
+
+ public String getComments() {
+ return comments;
+ }
+
+ public void setComments(String comments) {
+ this.comments = comments;
+ }
+
+ public Date getCommitedOn() {
+ return commitedOn;
+ }
+
+ public void setCommitedOn(Date commitedOn) {
+ this.commitedOn = commitedOn;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((comments == null) ? 0 : comments.hashCode());
+ result = prime * result + ((commitedOn == null) ? 0 : commitedOn.hashCode());
+ result = prime * result + ((revision == null) ? 0 : revision.hashCode());
+ result = prime * result + ((user == null) ? 0 : user.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ Changeset other = (Changeset) obj;
+ if (comments == null) {
+ if (other.comments != null) {
+ return false;
+ }
+ } else if (!comments.equals(other.comments)) {
+ return false;
+ }
+ if (commitedOn == null) {
+ if (other.commitedOn != null) {
+ return false;
+ }
+ } else if (!commitedOn.equals(other.commitedOn)) {
+ return false;
+ }
+ if (revision == null) {
+ if (other.revision != null) {
+ return false;
+ }
+ } else if (!revision.equals(other.revision)) {
+ return false;
+ }
+ if (user == null) {
+ if (other.user != null) {
+ return false;
+ }
+ } else if (!user.equals(other.user)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("Changeset [revision=");
+ builder.append(revision);
+ builder.append(", user=");
+ builder.append(user);
+ builder.append(", comments=");
+ builder.append(comments);
+ builder.append(", commitedOn=");
+ builder.append(commitedOn);
+ builder.append("]");
+ return builder.toString();
+ }
+
+}
@@ -41,6 +41,7 @@
private List<Journal> journals = new ArrayList<Journal>();
private List<IssueRelation> relations = new ArrayList<IssueRelation>();
private List<Attachment> attachments = new ArrayList<Attachment>();
+ private List<Changeset> changesets = new ArrayList<Changeset>();
public Project getProject() {
return project;
@@ -235,6 +236,14 @@ public void setJournals(List<Journal> journals) {
this.journals = journals;
}
+ public List<Changeset> getChangesets() {
+ return changesets;
+ }
+
+ public void setChangesets(List<Changeset> changesets) {
+ this.changesets = changesets;
+ }
+
@Override
public int hashCode() {
final int prime = 31;
@@ -278,6 +287,8 @@ public int hashCode() {
result = prime * result + ((tracker == null) ? 0 : tracker.hashCode());
result = prime * result
+ ((updatedOn == null) ? 0 : updatedOn.hashCode());
+ result = prime * result
+ + ((changesets == null) ? 0 : changesets.hashCode());
return result;
}
@@ -461,6 +472,13 @@ public boolean equals(Object obj) {
} else if (!attachments.equals(other.attachments)) {
return false;
}
+ if (changesets == null) {
+ if (other.changesets != null) {
+ return false;
+ }
+ } else if (!changesets.equals(other.changesets)) {
+ return false;
+ }
return true;
}
@@ -7,6 +7,7 @@
import org.redmine.ta.RedmineFormatException;
import org.redmine.ta.beans.Attachment;
+import org.redmine.ta.beans.Changeset;
import org.redmine.ta.beans.CustomField;
import org.redmine.ta.beans.Issue;
import org.redmine.ta.beans.IssueCategory;
@@ -170,6 +171,13 @@ public String parse(JSONObject input) throws JSONException {
}
};
+ public static final JsonObjectParser<Changeset> CHANGESET_PARSER = new JsonObjectParser<Changeset>() {
+ @Override
+ public Changeset parse(JSONObject input) throws JSONException {
+ return parseChangeset(input);
+ }
+ };
+
/**
* Parses a tracker.
*
@@ -374,6 +382,8 @@ public static Issue parseIssue(JSONObject content) throws JSONException {
"fixed_version", VERSION_PARSER));
result.setCategory(JsonInput.getObjectOrNull(content, "category",
CATEGORY_PARSER));
+ result.setChangesets(JsonInput.getListOrEmpty(content, "changesets",
+ CHANGESET_PARSER));
return result;
}
@@ -448,6 +458,16 @@ public static Journal parseJournal(JSONObject content) throws JSONException {
return result;
}
+ public static Changeset parseChangeset(JSONObject content)
+ throws JSONException {
+ final Changeset result = new Changeset();
+ result.setRevision(JsonInput.getStringOrNull(content, "revision"));
+ result.setUser(JsonInput.getObjectOrNull(content, "user", USER_PARSER));
+ result.setComments(JsonInput.getStringOrNull(content, "comments"));
+ result.setCommitedOn(getDateOrNull(content, "committed_on"));
+ return result;
+ }
+
public static User parseUser(JSONObject content) throws JSONException {
final User result = new User();
result.setId(JsonInput.getIntOrNull(content, "id"));
@@ -2021,4 +2021,13 @@ public void testUnknownHostException() throws RedmineException, IOException {
Assert.assertTrue(e1.getCause() instanceof UnknownHostException);
}
}
+
+ @Ignore
+ @Test
+ public void testChangesets() throws RedmineException {
+ final Issue issue = mgr.getIssueById(89, INCLUDE.changesets);
+ Assert.assertEquals(2, issue.getChangesets().size());
+ final Changeset firstChange = issue.getChangesets().get(0);
+ Assert.assertNotNull(firstChange.getComments());
+ }
}

0 comments on commit 0c0f767

Please sign in to comment.