diff --git a/pom.xml b/pom.xml index 7a8f793..df2edd4 100644 --- a/pom.xml +++ b/pom.xml @@ -24,6 +24,12 @@ commons-io 2.3 + + org.mockito + mockito-all + 1.9.0-rc1 + test + diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/YoutrackAPI.java b/src/main/java/pl/com/it_crowd/youtrack/api/YoutrackAPI.java index 6ffae40..cf279b7 100644 --- a/src/main/java/pl/com/it_crowd/youtrack/api/YoutrackAPI.java +++ b/src/main/java/pl/com/it_crowd/youtrack/api/YoutrackAPI.java @@ -31,6 +31,7 @@ import pl.com.it_crowd.youtrack.api.exceptions.NoResultFoundException; import pl.com.it_crowd.youtrack.api.exceptions.YoutrackAPIException; import pl.com.it_crowd.youtrack.api.exceptions.YoutrackErrorException; import pl.com.it_crowd.youtrack.api.rest.AssigneeList; +import pl.com.it_crowd.youtrack.api.rest.Enumeration; import pl.com.it_crowd.youtrack.api.rest.Issue; import pl.com.it_crowd.youtrack.api.rest.Issues; import pl.com.it_crowd.youtrack.api.rest.User; @@ -61,6 +62,8 @@ import java.util.regex.Pattern; public class YoutrackAPI { // ------------------------------ FIELDS ------------------------------ + private final static QName Enumeration_QNAME = new QName("", "enumeration"); + private final static QName Issue_QNAME = new QName("", "issue"); private HttpClient httpClient; @@ -241,6 +244,29 @@ public class YoutrackAPI { } } + public Enumeration getBundle(String customField) throws IOException, JAXBException + { + final URI uri; + try { + uri = new URIBuilder(serviceLocation + "/rest/admin/customfield/bundle/" + customField).build(); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + final Object result = YoutrackUnmarshaller.unmarshall(execute(new HttpGet(uri))); + if (result instanceof Enumeration) { + return (Enumeration) result; + } else if (result instanceof JAXBElement) { + final JAXBElement jaxbElement = (JAXBElement) result; + if (Enumeration_QNAME.equals(jaxbElement.getName())) { + return (Enumeration) ((JAXBElement) result).getValue(); + } else { + throw new YoutrackAPIException("Unexpected type: " + jaxbElement.getValue()); + } + } else { + throw new YoutrackAPIException("Unexpected type: " + result); + } + } + public List getIndividualAssignees(String project) throws IOException, JAXBException { final URI uri; diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/rest/Enumeration.java b/src/main/java/pl/com/it_crowd/youtrack/api/rest/Enumeration.java new file mode 100644 index 0000000..9913204 --- /dev/null +++ b/src/main/java/pl/com/it_crowd/youtrack/api/rest/Enumeration.java @@ -0,0 +1,96 @@ +// +// 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. +// +package pl.com.it_crowd.youtrack.api.rest; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; +import java.util.ArrayList; +import java.util.List; + +/** + *

Java class for enumerationType complex type. + *

+ *

The following schema fragment specifies the expected content contained within this class. + *

+ *

+ * <complexType name="enumerationType">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="value" type="{}enumerationValueType" maxOccurs="unbounded" minOccurs="0"/>
+ *       </sequence>
+ *       <attribute name="name" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "enumerationType", propOrder = {"values"}) +public class Enumeration { +// ------------------------------ FIELDS ------------------------------ + + @XmlAttribute + protected String name; + + @XmlElement(name = "value") + protected List values; + +// --------------------- GETTER / SETTER METHODS --------------------- + + /** + * Gets the value of the name property. + * + * @return possible object is + * {@link String } + */ + public String getName() + { + return name; + } + + /** + * Sets the value of the name property. + * + * @param value allowed object is + * {@link String } + */ + public void setName(String value) + { + this.name = value; + } + + /** + * Gets the value of the values property. + *

+ *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the values property. + *

+ *

+ * For example, to add a new item, do as follows: + *

+     *    getValues().add(newItem);
+     * 
+ *

+ *

+ *

+ * Objects of the following type(s) are allowed in the list + * {@link EnumerationValue } + */ + public List getValues() + { + if (values == null) { + values = new ArrayList(); + } + return this.values; + } +} diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/rest/EnumerationValue.java b/src/main/java/pl/com/it_crowd/youtrack/api/rest/EnumerationValue.java new file mode 100644 index 0000000..cea1aba --- /dev/null +++ b/src/main/java/pl/com/it_crowd/youtrack/api/rest/EnumerationValue.java @@ -0,0 +1,85 @@ +// +// 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. +// +package pl.com.it_crowd.youtrack.api.rest; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.XmlValue; + +/** + *

Java class for enumerationValueType complex type. + *

+ *

The following schema fragment specifies the expected content contained within this class. + *

+ *

+ * <complexType name="enumerationValueType">
+ *   <simpleContent>
+ *     <extension base="<http://www.w3.org/2001/XMLSchema>string">
+ *       <attribute name="colorIndex" type="{http://www.w3.org/2001/XMLSchema}long" />
+ *     </extension>
+ *   </simpleContent>
+ * </complexType>
+ * 
+ */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "enumerationValueType", propOrder = {"value"}) +public class EnumerationValue { +// ------------------------------ FIELDS ------------------------------ + + @XmlAttribute + protected Long colorIndex; + + @XmlValue + protected String value; + +// --------------------- GETTER / SETTER METHODS --------------------- + + /** + * Gets the value of the colorIndex property. + * + * @return possible object is + * {@link Long } + */ + public Long getColorIndex() + { + return colorIndex; + } + + /** + * Sets the value of the colorIndex property. + * + * @param value allowed object is + * {@link Long } + */ + public void setColorIndex(Long value) + { + this.colorIndex = value; + } + + /** + * Gets the value of the value property. + * + * @return possible object is + * {@link String } + */ + public String getValue() + { + return value; + } + + /** + * Sets the value of the value property. + * + * @param value allowed object is + * {@link String } + */ + public void setValue(String value) + { + this.value = 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 e7abba1..f0a10a1 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 @@ -31,6 +31,8 @@ public class ObjectFactory { private final static QName _CommentValue_QNAME = new QName("", "value"); + private final static QName _Enumeration_QNAME = new QName("", "enumeration"); + private final static QName _Error_QNAME = new QName("", "error"); private final static QName _Int_QNAME = new QName("", "int"); @@ -115,6 +117,31 @@ public class ObjectFactory { } /** + * Create an instance of {@link Enumeration } + */ + public Enumeration createEnumeration() + { + return new Enumeration(); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link Enumeration }{@code >}} + */ + @XmlElementDecl(namespace = "", name = "enumeration") + public JAXBElement createEnumeration(Enumeration value) + { + return new JAXBElement(_Enumeration_QNAME, Enumeration.class, null, value); + } + + /** + * Create an instance of {@link EnumerationValue } + */ + public EnumerationValue createEnumerationValue() + { + return new EnumerationValue(); + } + + /** * Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >}} */ @XmlElementDecl(namespace = "", name = "error") diff --git a/src/main/xjb/bindings.xjb b/src/main/xjb/bindings.xjb index 9c40975..fb0e0d9 100644 --- a/src/main/xjb/bindings.xjb +++ b/src/main/xjb/bindings.xjb @@ -1,5 +1,4 @@ - @@ -25,6 +24,17 @@ + + + + + + + + + + + diff --git a/src/main/xsd/bundle.xml b/src/main/xsd/bundle.xml new file mode 100644 index 0000000..71e797b --- /dev/null +++ b/src/main/xsd/bundle.xml @@ -0,0 +1,7 @@ + + Show-stopper + Critical + Major + Normal + Minor + \ No newline at end of file diff --git a/src/main/xsd/bundle.xsd b/src/main/xsd/bundle.xsd new file mode 100644 index 0000000..af63b10 --- /dev/null +++ b/src/main/xsd/bundle.xsd @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/xsd/types.xsd b/src/main/xsd/types.xsd index 243dc9c..1d2cf11 100644 --- a/src/main/xsd/types.xsd +++ b/src/main/xsd/types.xsd @@ -15,6 +15,21 @@ + + + + + + + + + + + + + + + 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 90812e8..67f748f 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 @@ -1,8 +1,14 @@ package pl.com.it_crowd.youtrack.api.rest; import junit.framework.Assert; +import org.apache.commons.io.input.ReaderInputStream; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; +import org.apache.http.StatusLine; import org.apache.http.auth.AuthenticationException; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpUriRequest; import org.junit.Test; import pl.com.it_crowd.youtrack.api.Command; import pl.com.it_crowd.youtrack.api.Filter; @@ -15,8 +21,15 @@ import pl.com.it_crowd.youtrack.api.exceptions.YoutrackErrorException; import javax.xml.bind.JAXBException; import java.io.IOException; +import java.io.StringReader; import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * This test requires Youtrack instance with "Test(TST)" project to be running and expects following JVM params: * youtrackLocation, youtrackUsername and youtrackPassword. @@ -104,6 +117,43 @@ public class YoutrackAPITest { } @Test + public void getBundle() throws Exception + { +// Given + final HttpResponse httpResponse = mock(HttpResponse.class); + final HttpEntity httpEntity = mock(HttpEntity.class); + final String response = "Show-stopperCriticalMajorNormalMinor"; + when(httpEntity.getContent()).thenReturn(new ReaderInputStream(new StringReader(response))); + when(httpEntity.getContentLength()).thenReturn((long) response.getBytes().length); + when(httpResponse.getEntity()).thenReturn(httpEntity); + final StatusLine statusLine = mock(StatusLine.class); + when(statusLine.getStatusCode()).thenReturn(200); + when(httpResponse.getStatusLine()).thenReturn(statusLine); + final HttpClient httpClient = mock(HttpClient.class); + when(httpClient.execute(any(HttpUriRequest.class))).thenReturn(httpResponse); + final YoutrackAPI youtrackAPI = new YoutrackAPI("zonk", httpClient); + +// When + final Enumeration priorities = youtrackAPI.getBundle("Priorities"); + +// Then + assertNotNull(priorities); + assertEquals("Priorities", priorities.getName()); + assertNotNull(priorities.getValues()); + assertEquals(5, priorities.getValues().size()); + assertEquals("Show-stopper", priorities.getValues().get(0).getValue()); + assertEquals(new Long(20), priorities.getValues().get(0).getColorIndex()); + assertEquals("Critical", priorities.getValues().get(1).getValue()); + assertEquals(new Long(19), priorities.getValues().get(1).getColorIndex()); + assertEquals("Major", priorities.getValues().get(2).getValue()); + assertEquals(new Long(18), priorities.getValues().get(2).getColorIndex()); + assertEquals("Normal", priorities.getValues().get(3).getValue()); + assertEquals(new Long(17), priorities.getValues().get(3).getColorIndex()); + assertEquals("Minor", priorities.getValues().get(4).getValue()); + assertEquals(new Long(16), priorities.getValues().get(4).getColorIndex()); + } + + @Test public void getIndividualAssignees() throws IOException, JAXBException { final YoutrackAPI api = new YoutrackAPI(getServiceLocation(), getUsername(), getPassword());