diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/Issue.java b/src/main/java/pl/com/it_crowd/youtrack/api/Issue.java index f60862f..f90bb35 100644 --- a/src/main/java/pl/com/it_crowd/youtrack/api/Issue.java +++ b/src/main/java/pl/com/it_crowd/youtrack/api/Issue.java @@ -14,14 +14,17 @@ public class Issue implements Serializable { // ------------------------------ FIELDS ------------------------------ private static final Log log = LogFactory.getLog(Issue.class); + private List comments; + private Map fieldMap; private Issues.Issue issue; // --------------------------- CONSTRUCTORS --------------------------- - public Issue(Issues.Issue issue) { + public Issue(Issues.Issue issue) + { this.issue = issue; fieldMap = new HashMap(); comments = new ArrayList(); @@ -39,11 +42,13 @@ public class Issue implements Serializable { // -------------------------- OTHER METHODS -------------------------- - public Issues.Issue.Field getField(String field) { + public Issues.Issue.Field getField(String field) + { return fieldMap.get(field); } - public String getFieldValue(String fieldName) { + public String getFieldValue(String fieldName) + { Issues.Issue.Field field = fieldMap.get(fieldName); if (field == null) { return null; @@ -52,9 +57,11 @@ public class Issue implements Serializable { return values.isEmpty() ? null : values.get(0).getContent(); } - public String getFieldValue(Fields fieldName) { + public String getFieldValue(Fields fieldName) + { return getFieldValue(fieldName.name()); } + // -------------------------- ENUMERATIONS -------------------------- public enum Fields { diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/rest/YoutrackAPI.java b/src/main/java/pl/com/it_crowd/youtrack/api/YoutrackAPI.java index 75b49c7..9ef02d5 100644 --- a/src/main/java/pl/com/it_crowd/youtrack/api/rest/YoutrackAPI.java +++ b/src/main/java/pl/com/it_crowd/youtrack/api/YoutrackAPI.java @@ -1,4 +1,4 @@ -package pl.com.it_crowd.youtrack.api.rest; +package pl.com.it_crowd.youtrack.api; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; @@ -11,8 +11,7 @@ import com.gargoylesoftware.htmlunit.html.DomNode; import com.gargoylesoftware.htmlunit.util.NameValuePair; import com.gargoylesoftware.htmlunit.xml.XmlPage; import org.apache.http.auth.AuthenticationException; -import pl.com.it_crowd.youtrack.api.Issue; -import pl.com.it_crowd.youtrack.api.IssuesUnmarshaller; +import pl.com.it_crowd.youtrack.api.rest.Issues; import javax.xml.bind.JAXBException; import java.io.IOException; @@ -29,27 +28,31 @@ public class YoutrackAPI { // --------------------------- CONSTRUCTORS --------------------------- - public YoutrackAPI(String serviceLocation) { + public YoutrackAPI(String serviceLocation) + { this.serviceLocation = serviceLocation; this.webClient = new WebClient(BrowserVersion.FIREFOX_3_6); this.webClient.setJavaScriptEnabled(false); this.webClient.setCssEnabled(false); } - public YoutrackAPI(String serviceLocation, String username, String password) throws IOException, AuthenticationException { + public YoutrackAPI(String serviceLocation, String username, String password) throws IOException, AuthenticationException + { this(serviceLocation); login(username, password); } // --------------------- GETTER / SETTER METHODS --------------------- - public String getServiceLocation() { + public String getServiceLocation() + { return serviceLocation; } // -------------------------- OTHER METHODS -------------------------- - public void login(String username, String password) throws IOException, AuthenticationException { + public void login(String username, String password) throws IOException, AuthenticationException + { ArrayList requestParameters = new ArrayList(); requestParameters.add(new NameValuePair("login", username)); requestParameters.add(new NameValuePair("password", password)); @@ -68,7 +71,8 @@ public class YoutrackAPI { } } - public List searchIssuesByProject(String project, String filter) throws JAXBException, IOException { + public List searchIssuesByProject(String project, String filter) throws JAXBException, IOException + { String url = serviceLocation + "/rest/issue/byproject/" + project + "?filter=" + filter; WebResponse webResponse = webClient.getPage(url).getWebResponse(); // System.out.println(webResponse.getContentAsString()); diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/rest/Issues.java b/src/main/java/pl/com/it_crowd/youtrack/api/rest/Issues.java index 549ee8e..9e02507 100644 --- a/src/main/java/pl/com/it_crowd/youtrack/api/rest/Issues.java +++ b/src/main/java/pl/com/it_crowd/youtrack/api/rest/Issues.java @@ -2,7 +2,7 @@ // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 // See http://java.sun.com/xml/jaxb // Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2011.12.16 at 09:34:48 AM CET +// Generated on: 2011.12.16 at 10:06:20 AM CET // package pl.com.it_crowd.youtrack.api.rest; @@ -96,9 +96,7 @@ import java.util.List; * */ @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "", propOrder = { - "issue" -}) +@XmlType(name = "", propOrder = {"issue"}) @XmlRootElement(name = "issues") public class Issues { @@ -124,7 +122,8 @@ public class Issues { * Objects of the following type(s) are allowed in the list * {@link Issues.Issue } */ - public List getIssue() { + public List getIssue() + { if (issue == null) { issue = new ArrayList(); } @@ -199,16 +198,12 @@ public class Issues { * */ @XmlAccessorType(XmlAccessType.FIELD) - @XmlType(name = "", propOrder = { - "fieldOrComment" - }) + @XmlType(name = "", propOrder = {"fieldOrComment"}) public static class Issue { - @XmlElements({ - @XmlElement(name = "field", type = Issues.Issue.Field.class), - @XmlElement(name = "comment", type = Issues.Issue.Comment.class) - }) + @XmlElements({@XmlElement(name = "field", type = Issues.Issue.Field.class), @XmlElement(name = "comment", type = Issues.Issue.Comment.class)}) protected List fieldOrComment; + @XmlAttribute protected String id; @@ -233,7 +228,8 @@ public class Issues { * {@link Issues.Issue.Field } * {@link Issues.Issue.Comment } */ - public List getFieldOrComment() { + public List getFieldOrComment() + { if (fieldOrComment == null) { fieldOrComment = new ArrayList(); } @@ -246,7 +242,8 @@ public class Issues { * @return possible object is * {@link String } */ - public String getId() { + public String getId() + { return id; } @@ -256,7 +253,8 @@ public class Issues { * @param value allowed object is * {@link String } */ - public void setId(String value) { + public void setId(String value) + { this.id = value; } @@ -296,28 +294,34 @@ public class Issues { * */ @XmlAccessorType(XmlAccessType.FIELD) - @XmlType(name = "", propOrder = { - "replies", - "value" - }) + @XmlType(name = "", propOrder = {"replies", "value"}) public static class Comment { protected String replies; + protected Issues.Issue.Comment.Value value; + @XmlAttribute protected String id; + @XmlAttribute protected String author; + @XmlAttribute protected String issueId; + @XmlAttribute protected String deleted; + @XmlAttribute protected String text; + @XmlAttribute protected String shownForIssueAuthor; + @XmlAttribute protected String created; + @XmlAttribute protected String name; @@ -327,7 +331,8 @@ public class Issues { * @return possible object is * {@link String } */ - public String getReplies() { + public String getReplies() + { return replies; } @@ -337,7 +342,8 @@ public class Issues { * @param value allowed object is * {@link String } */ - public void setReplies(String value) { + public void setReplies(String value) + { this.replies = value; } @@ -347,7 +353,8 @@ public class Issues { * @return possible object is * {@link Issues.Issue.Comment.Value } */ - public Issues.Issue.Comment.Value getValue() { + public Issues.Issue.Comment.Value getValue() + { return value; } @@ -357,7 +364,8 @@ public class Issues { * @param value allowed object is * {@link Issues.Issue.Comment.Value } */ - public void setValue(Issues.Issue.Comment.Value value) { + public void setValue(Issues.Issue.Comment.Value value) + { this.value = value; } @@ -367,7 +375,8 @@ public class Issues { * @return possible object is * {@link String } */ - public String getId() { + public String getId() + { return id; } @@ -377,7 +386,8 @@ public class Issues { * @param value allowed object is * {@link String } */ - public void setId(String value) { + public void setId(String value) + { this.id = value; } @@ -387,7 +397,8 @@ public class Issues { * @return possible object is * {@link String } */ - public String getAuthor() { + public String getAuthor() + { return author; } @@ -397,7 +408,8 @@ public class Issues { * @param value allowed object is * {@link String } */ - public void setAuthor(String value) { + public void setAuthor(String value) + { this.author = value; } @@ -407,7 +419,8 @@ public class Issues { * @return possible object is * {@link String } */ - public String getIssueId() { + public String getIssueId() + { return issueId; } @@ -417,7 +430,8 @@ public class Issues { * @param value allowed object is * {@link String } */ - public void setIssueId(String value) { + public void setIssueId(String value) + { this.issueId = value; } @@ -427,7 +441,8 @@ public class Issues { * @return possible object is * {@link String } */ - public String getDeleted() { + public String getDeleted() + { return deleted; } @@ -437,7 +452,8 @@ public class Issues { * @param value allowed object is * {@link String } */ - public void setDeleted(String value) { + public void setDeleted(String value) + { this.deleted = value; } @@ -447,7 +463,8 @@ public class Issues { * @return possible object is * {@link String } */ - public String getText() { + public String getText() + { return text; } @@ -457,7 +474,8 @@ public class Issues { * @param value allowed object is * {@link String } */ - public void setText(String value) { + public void setText(String value) + { this.text = value; } @@ -467,7 +485,8 @@ public class Issues { * @return possible object is * {@link String } */ - public String getShownForIssueAuthor() { + public String getShownForIssueAuthor() + { return shownForIssueAuthor; } @@ -477,7 +496,8 @@ public class Issues { * @param value allowed object is * {@link String } */ - public void setShownForIssueAuthor(String value) { + public void setShownForIssueAuthor(String value) + { this.shownForIssueAuthor = value; } @@ -487,7 +507,8 @@ public class Issues { * @return possible object is * {@link String } */ - public String getCreated() { + public String getCreated() + { return created; } @@ -497,7 +518,8 @@ public class Issues { * @param value allowed object is * {@link String } */ - public void setCreated(String value) { + public void setCreated(String value) + { this.created = value; } @@ -507,7 +529,8 @@ public class Issues { * @return possible object is * {@link String } */ - public String getName() { + public String getName() + { return name; } @@ -517,7 +540,8 @@ public class Issues { * @param value allowed object is * {@link String } */ - public void setName(String value) { + public void setName(String value) + { this.name = value; } @@ -538,15 +562,15 @@ public class Issues { * */ @XmlAccessorType(XmlAccessType.FIELD) - @XmlType(name = "", propOrder = { - "value" - }) + @XmlType(name = "", propOrder = {"value"}) public static class Value { @XmlValue protected String value; + @XmlAttribute protected String type; + @XmlAttribute protected String role; @@ -556,7 +580,8 @@ public class Issues { * @return possible object is * {@link String } */ - public String getValue() { + public String getValue() + { return value; } @@ -566,7 +591,8 @@ public class Issues { * @param value allowed object is * {@link String } */ - public void setValue(String value) { + public void setValue(String value) + { this.value = value; } @@ -576,7 +602,8 @@ public class Issues { * @return possible object is * {@link String } */ - public String getType() { + public String getType() + { return type; } @@ -586,7 +613,8 @@ public class Issues { * @param value allowed object is * {@link String } */ - public void setType(String value) { + public void setType(String value) + { this.type = value; } @@ -596,7 +624,8 @@ public class Issues { * @return possible object is * {@link String } */ - public String getRole() { + public String getRole() + { return role; } @@ -606,12 +635,11 @@ public class Issues { * @param value allowed object is * {@link String } */ - public void setRole(String value) { + public void setRole(String value) + { this.role = value; } - } - } /** @@ -642,13 +670,12 @@ public class Issues { * */ @XmlAccessorType(XmlAccessType.FIELD) - @XmlType(name = "", propOrder = { - "values" - }) + @XmlType(name = "", propOrder = {"values"}) public static class Field { @XmlElement(name = "value") protected List values; + @XmlAttribute protected String name; @@ -672,7 +699,8 @@ public class Issues { * Objects of the following type(s) are allowed in the list * {@link Issues.Issue.Field.Value } */ - public List getValues() { + public List getValues() + { if (values == null) { values = new ArrayList(); } @@ -685,7 +713,8 @@ public class Issues { * @return possible object is * {@link String } */ - public String getName() { + public String getName() + { return name; } @@ -695,7 +724,8 @@ public class Issues { * @param value allowed object is * {@link String } */ - public void setName(String value) { + public void setName(String value) + { this.name = value; } @@ -716,15 +746,15 @@ public class Issues { * */ @XmlAccessorType(XmlAccessType.FIELD) - @XmlType(name = "", propOrder = { - "content" - }) + @XmlType(name = "", propOrder = {"content"}) public static class Value { @XmlValue protected String content; + @XmlAttribute protected String type; + @XmlAttribute protected String role; @@ -734,7 +764,8 @@ public class Issues { * @return possible object is * {@link String } */ - public String getContent() { + public String getContent() + { return content; } @@ -744,7 +775,8 @@ public class Issues { * @param value allowed object is * {@link String } */ - public void setContent(String value) { + public void setContent(String value) + { this.content = value; } @@ -754,7 +786,8 @@ public class Issues { * @return possible object is * {@link String } */ - public String getType() { + public String getType() + { return type; } @@ -764,7 +797,8 @@ public class Issues { * @param value allowed object is * {@link String } */ - public void setType(String value) { + public void setType(String value) + { this.type = value; } @@ -774,7 +808,8 @@ public class Issues { * @return possible object is * {@link String } */ - public String getRole() { + public String getRole() + { return role; } @@ -784,14 +819,11 @@ public class Issues { * @param value allowed object is * {@link String } */ - public void setRole(String value) { + public void setRole(String value) + { this.role = value; } - } - } - } - } diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/rest/ObjectFactory.java b/src/main/java/pl/com/it_crowd/youtrack/api/rest/ObjectFactory.java index b10762e..2bb77c5 100644 --- a/src/main/java/pl/com/it_crowd/youtrack/api/rest/ObjectFactory.java +++ b/src/main/java/pl/com/it_crowd/youtrack/api/rest/ObjectFactory.java @@ -2,7 +2,7 @@ // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 // See http://java.sun.com/xml/jaxb // Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2011.12.16 at 09:34:48 AM CET +// Generated on: 2011.12.16 at 10:06:20 AM CET // package pl.com.it_crowd.youtrack.api.rest; @@ -28,49 +28,55 @@ public class ObjectFactory { /** * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: pl.com.it_crowd.youtrack.api.rest */ - public ObjectFactory() { + public ObjectFactory() + { } /** - * Create an instance of {@link Issues.Issue.Comment.Value } + * Create an instance of {@link Issues.Issue } */ - public Issues.Issue.Comment.Value createIssuesIssueCommentValue() { - return new Issues.Issue.Comment.Value(); + public Issues.Issue createIssuesIssue() + { + return new Issues.Issue(); } /** - * Create an instance of {@link Issues.Issue.Field } + * Create an instance of {@link Issues.Issue.Comment } */ - public Issues.Issue.Field createIssuesIssueField() { - return new Issues.Issue.Field(); + public Issues.Issue.Comment createIssuesIssueComment() + { + return new Issues.Issue.Comment(); } /** * Create an instance of {@link Issues } */ - public Issues createIssues() { + public Issues createIssues() + { return new Issues(); } /** - * Create an instance of {@link Issues.Issue.Field.Value } + * Create an instance of {@link Issues.Issue.Comment.Value } */ - public Issues.Issue.Field.Value createIssuesIssueFieldValue() { - return new Issues.Issue.Field.Value(); + public Issues.Issue.Comment.Value createIssuesIssueCommentValue() + { + return new Issues.Issue.Comment.Value(); } /** - * Create an instance of {@link Issues.Issue.Comment } + * Create an instance of {@link Issues.Issue.Field.Value } */ - public Issues.Issue.Comment createIssuesIssueComment() { - return new Issues.Issue.Comment(); + public Issues.Issue.Field.Value createIssuesIssueFieldValue() + { + return new Issues.Issue.Field.Value(); } /** - * Create an instance of {@link Issues.Issue } + * Create an instance of {@link Issues.Issue.Field } */ - public Issues.Issue createIssuesIssue() { - return new Issues.Issue(); + public Issues.Issue.Field createIssuesIssueField() + { + return new Issues.Issue.Field(); } - } diff --git a/src/test/java/pl/com/it_crowd/youtrack/api/rest/YoutrackAPITest.java b/src/test/java/pl/com/it_crowd/youtrack/api/rest/YoutrackAPITest.java index fa86ee8..81fd2fa 100644 --- a/src/test/java/pl/com/it_crowd/youtrack/api/rest/YoutrackAPITest.java +++ b/src/test/java/pl/com/it_crowd/youtrack/api/rest/YoutrackAPITest.java @@ -4,6 +4,7 @@ import junit.framework.Assert; import org.apache.http.auth.AuthenticationException; import org.junit.Test; import pl.com.it_crowd.youtrack.api.Issue; +import pl.com.it_crowd.youtrack.api.YoutrackAPI; import javax.xml.bind.JAXBException; import java.io.IOException; @@ -16,14 +17,16 @@ public class YoutrackAPITest { // -------------------------- OTHER METHODS -------------------------- @Test(expected = AuthenticationException.class) - public void loginFailureTest() throws IOException, AuthenticationException { + public void loginFailureTest() throws IOException, AuthenticationException + { final String username = "someFakeLogin"; final String password = "someFakePassword"; new YoutrackAPI("http://youtrack.it-crowd.com.pl", username, password); } @Test - public void loginTest() throws IOException, AuthenticationException { + public void loginTest() throws IOException, AuthenticationException + { final String username = getUsername(); final String password = getPassword(); new YoutrackAPI("http://youtrack.it-crowd.com.pl", username, password); @@ -32,7 +35,8 @@ public class YoutrackAPITest { } @Test - public void searchIssuesByProjectTest() throws IOException, AuthenticationException, JAXBException { + public void searchIssuesByProjectTest() throws IOException, AuthenticationException, JAXBException + { YoutrackAPI api = new YoutrackAPI("http://youtrack.it-crowd.com.pl", getUsername(), getPassword()); List issues = api.searchIssuesByProject("SM", null); Assert.assertTrue(!issues.isEmpty()); @@ -43,11 +47,13 @@ public class YoutrackAPITest { } } - private String getPassword() { + private String getPassword() + { return System.getProperty("youtrackPassword"); } - private String getUsername() { + private String getUsername() + { return System.getProperty("youtrackUsername"); } }