Commit 4bd2f591c73171cb7bee3d6631fdf60c6d07a37a

Authored by bernard
1 parent 1fa60124

Implemented login and searchIssueByProject tests.

@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4 <modelVersion>4.0.0</modelVersion> 4 <modelVersion>4.0.0</modelVersion>
5 5
6 - <groupId>pl.com.it-crowd.youtrack-rest-api</groupId> 6 + <groupId>pl.com.it-crowd</groupId>
7 <artifactId>youtrack-rest-api</artifactId> 7 <artifactId>youtrack-rest-api</artifactId>
8 <version>1.0.0-SNAPSHOT</version> 8 <version>1.0.0-SNAPSHOT</version>
9 9
@@ -60,6 +60,7 @@ @@ -60,6 +60,7 @@
60 <packageName>pl.com.it_crowd.youtrack.api.rest</packageName> 60 <packageName>pl.com.it_crowd.youtrack.api.rest</packageName>
61 <outputDirectory>${build.sourceDirectory}</outputDirectory> 61 <outputDirectory>${build.sourceDirectory}</outputDirectory>
62 <clearOutputDir>false</clearOutputDir> 62 <clearOutputDir>false</clearOutputDir>
  63 + <extension>false</extension>
63 </configuration> 64 </configuration>
64 </plugin> 65 </plugin>
65 </plugins> 66 </plugins>
@@ -74,4 +75,4 @@ @@ -74,4 +75,4 @@
74 <url>http://artifactory.it-crowd.com.pl/libs-snapshot-local</url> 75 <url>http://artifactory.it-crowd.com.pl/libs-snapshot-local</url>
75 </snapshotRepository> 76 </snapshotRepository>
76 </distributionManagement> 77 </distributionManagement>
77 -</project>  
  78 +</project>
  1 +package pl.com.it_crowd.youtrack.api;
  2 +
  3 +import org.apache.commons.logging.Log;
  4 +import org.apache.commons.logging.LogFactory;
  5 +import pl.com.it_crowd.youtrack.api.rest.Issues;
  6 +
  7 +import java.io.Serializable;
  8 +import java.util.ArrayList;
  9 +import java.util.HashMap;
  10 +import java.util.List;
  11 +import java.util.Map;
  12 +
  13 +public class Issue implements Serializable {
  14 +// ------------------------------ FIELDS ------------------------------
  15 +
  16 + private static final Log log = LogFactory.getLog(Issue.class);
  17 + private List<Issues.Issue.Comment> comments;
  18 + private Map<String, Issues.Issue.Field> fieldMap;
  19 +
  20 + private Issues.Issue issue;
  21 +
  22 +// --------------------------- CONSTRUCTORS ---------------------------
  23 +
  24 + public Issue(Issues.Issue issue) {
  25 + this.issue = issue;
  26 + fieldMap = new HashMap<String, Issues.Issue.Field>();
  27 + comments = new ArrayList<Issues.Issue.Comment>();
  28 + for (Object o : issue.getFieldOrComment()) {
  29 + if (o instanceof Issues.Issue.Field) {
  30 + Issues.Issue.Field field = (Issues.Issue.Field) o;
  31 + fieldMap.put(field.getName(), field);
  32 + } else if (o instanceof Issues.Issue.Comment) {
  33 + comments.add((Issues.Issue.Comment) o);
  34 + } else {
  35 + log.warn("Object " + o + " is not Field nor Coment");
  36 + }
  37 + }
  38 + }
  39 +
  40 +// -------------------------- OTHER METHODS --------------------------
  41 +
  42 + public Issues.Issue.Field getField(String field) {
  43 + return fieldMap.get(field);
  44 + }
  45 +
  46 + public String getFieldValue(String fieldName) {
  47 + Issues.Issue.Field field = fieldMap.get(fieldName);
  48 + if (field == null) {
  49 + return null;
  50 + }
  51 + List<Issues.Issue.Field.Value> values = field.getValues();
  52 + return values.isEmpty() ? null : values.get(0).getContent();
  53 + }
  54 +
  55 + public String getFieldValue(Fields fieldName) {
  56 + return getFieldValue(fieldName.name());
  57 + }
  58 +// -------------------------- ENUMERATIONS --------------------------
  59 +
  60 + public enum Fields {
  61 + summary
  62 + }
  63 +}
@@ -2,23 +2,19 @@ @@ -2,23 +2,19 @@
2 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 2 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833
3 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 3 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
4 // Any modifications to this file will be lost upon recompilation of the source schema. 4 // Any modifications to this file will be lost upon recompilation of the source schema.
5 -// Generated on: 2011.12.05 at 08:56:01 AM CET 5 +// Generated on: 2011.12.16 at 09:34:48 AM CET
6 // 6 //
7 7
8 package pl.com.it_crowd.youtrack.api.rest; 8 package pl.com.it_crowd.youtrack.api.rest;
9 9
10 -import javax.xml.bind.JAXBElement;  
11 import javax.xml.bind.annotation.XmlAccessType; 10 import javax.xml.bind.annotation.XmlAccessType;
12 import javax.xml.bind.annotation.XmlAccessorType; 11 import javax.xml.bind.annotation.XmlAccessorType;
13 import javax.xml.bind.annotation.XmlAttribute; 12 import javax.xml.bind.annotation.XmlAttribute;
14 import javax.xml.bind.annotation.XmlElement; 13 import javax.xml.bind.annotation.XmlElement;
15 -import javax.xml.bind.annotation.XmlElementRef;  
16 import javax.xml.bind.annotation.XmlElements; 14 import javax.xml.bind.annotation.XmlElements;
17 -import javax.xml.bind.annotation.XmlMixed;  
18 import javax.xml.bind.annotation.XmlRootElement; 15 import javax.xml.bind.annotation.XmlRootElement;
19 import javax.xml.bind.annotation.XmlType; 16 import javax.xml.bind.annotation.XmlType;
20 import javax.xml.bind.annotation.XmlValue; 17 import javax.xml.bind.annotation.XmlValue;
21 -import java.io.Serializable;  
22 import java.util.ArrayList; 18 import java.util.ArrayList;
23 import java.util.List; 19 import java.util.List;
24 20
@@ -100,7 +96,9 @@ import java.util.List; @@ -100,7 +96,9 @@ import java.util.List;
100 * </pre> 96 * </pre>
101 */ 97 */
102 @XmlAccessorType(XmlAccessType.FIELD) 98 @XmlAccessorType(XmlAccessType.FIELD)
103 -@XmlType(name = "", propOrder = {"issue"}) 99 +@XmlType(name = "", propOrder = {
  100 + "issue"
  101 +})
104 @XmlRootElement(name = "issues") 102 @XmlRootElement(name = "issues")
105 public class Issues { 103 public class Issues {
106 104
@@ -126,8 +124,7 @@ public class Issues { @@ -126,8 +124,7 @@ public class Issues {
126 * Objects of the following type(s) are allowed in the list 124 * Objects of the following type(s) are allowed in the list
127 * {@link Issues.Issue } 125 * {@link Issues.Issue }
128 */ 126 */
129 - public List<Issues.Issue> getIssue()  
130 - { 127 + public List<Issues.Issue> getIssue() {
131 if (issue == null) { 128 if (issue == null) {
132 issue = new ArrayList<Issues.Issue>(); 129 issue = new ArrayList<Issues.Issue>();
133 } 130 }
@@ -202,12 +199,16 @@ public class Issues { @@ -202,12 +199,16 @@ public class Issues {
202 * </pre> 199 * </pre>
203 */ 200 */
204 @XmlAccessorType(XmlAccessType.FIELD) 201 @XmlAccessorType(XmlAccessType.FIELD)
205 - @XmlType(name = "", propOrder = {"fieldOrComment"}) 202 + @XmlType(name = "", propOrder = {
  203 + "fieldOrComment"
  204 + })
206 public static class Issue { 205 public static class Issue {
207 206
208 - @XmlElements({@XmlElement(name = "field", type = Issues.Issue.Field.class), @XmlElement(name = "comment", type = Issues.Issue.Comment.class)}) 207 + @XmlElements({
  208 + @XmlElement(name = "field", type = Issues.Issue.Field.class),
  209 + @XmlElement(name = "comment", type = Issues.Issue.Comment.class)
  210 + })
209 protected List<Object> fieldOrComment; 211 protected List<Object> fieldOrComment;
210 -  
211 @XmlAttribute 212 @XmlAttribute
212 protected String id; 213 protected String id;
213 214
@@ -232,8 +233,7 @@ public class Issues { @@ -232,8 +233,7 @@ public class Issues {
232 * {@link Issues.Issue.Field } 233 * {@link Issues.Issue.Field }
233 * {@link Issues.Issue.Comment } 234 * {@link Issues.Issue.Comment }
234 */ 235 */
235 - public List<Object> getFieldOrComment()  
236 - { 236 + public List<Object> getFieldOrComment() {
237 if (fieldOrComment == null) { 237 if (fieldOrComment == null) {
238 fieldOrComment = new ArrayList<Object>(); 238 fieldOrComment = new ArrayList<Object>();
239 } 239 }
@@ -246,8 +246,7 @@ public class Issues { @@ -246,8 +246,7 @@ public class Issues {
246 * @return possible object is 246 * @return possible object is
247 * {@link String } 247 * {@link String }
248 */ 248 */
249 - public String getId()  
250 - { 249 + public String getId() {
251 return id; 250 return id;
252 } 251 }
253 252
@@ -257,8 +256,7 @@ public class Issues { @@ -257,8 +256,7 @@ public class Issues {
257 * @param value allowed object is 256 * @param value allowed object is
258 * {@link String } 257 * {@link String }
259 */ 258 */
260 - public void setId(String value)  
261 - { 259 + public void setId(String value) {
262 this.id = value; 260 this.id = value;
263 } 261 }
264 262
@@ -298,34 +296,28 @@ public class Issues { @@ -298,34 +296,28 @@ public class Issues {
298 * </pre> 296 * </pre>
299 */ 297 */
300 @XmlAccessorType(XmlAccessType.FIELD) 298 @XmlAccessorType(XmlAccessType.FIELD)
301 - @XmlType(name = "", propOrder = {"replies", "value"}) 299 + @XmlType(name = "", propOrder = {
  300 + "replies",
  301 + "value"
  302 + })
302 public static class Comment { 303 public static class Comment {
303 304
304 protected String replies; 305 protected String replies;
305 -  
306 protected Issues.Issue.Comment.Value value; 306 protected Issues.Issue.Comment.Value value;
307 -  
308 @XmlAttribute 307 @XmlAttribute
309 protected String id; 308 protected String id;
310 -  
311 @XmlAttribute 309 @XmlAttribute
312 protected String author; 310 protected String author;
313 -  
314 @XmlAttribute 311 @XmlAttribute
315 protected String issueId; 312 protected String issueId;
316 -  
317 @XmlAttribute 313 @XmlAttribute
318 protected String deleted; 314 protected String deleted;
319 -  
320 @XmlAttribute 315 @XmlAttribute
321 protected String text; 316 protected String text;
322 -  
323 @XmlAttribute 317 @XmlAttribute
324 protected String shownForIssueAuthor; 318 protected String shownForIssueAuthor;
325 -  
326 @XmlAttribute 319 @XmlAttribute
327 protected String created; 320 protected String created;
328 -  
329 @XmlAttribute 321 @XmlAttribute
330 protected String name; 322 protected String name;
331 323
@@ -335,8 +327,7 @@ public class Issues { @@ -335,8 +327,7 @@ public class Issues {
335 * @return possible object is 327 * @return possible object is
336 * {@link String } 328 * {@link String }
337 */ 329 */
338 - public String getReplies()  
339 - { 330 + public String getReplies() {
340 return replies; 331 return replies;
341 } 332 }
342 333
@@ -346,8 +337,7 @@ public class Issues { @@ -346,8 +337,7 @@ public class Issues {
346 * @param value allowed object is 337 * @param value allowed object is
347 * {@link String } 338 * {@link String }
348 */ 339 */
349 - public void setReplies(String value)  
350 - { 340 + public void setReplies(String value) {
351 this.replies = value; 341 this.replies = value;
352 } 342 }
353 343
@@ -357,8 +347,7 @@ public class Issues { @@ -357,8 +347,7 @@ public class Issues {
357 * @return possible object is 347 * @return possible object is
358 * {@link Issues.Issue.Comment.Value } 348 * {@link Issues.Issue.Comment.Value }
359 */ 349 */
360 - public Issues.Issue.Comment.Value getValue()  
361 - { 350 + public Issues.Issue.Comment.Value getValue() {
362 return value; 351 return value;
363 } 352 }
364 353
@@ -368,8 +357,7 @@ public class Issues { @@ -368,8 +357,7 @@ public class Issues {
368 * @param value allowed object is 357 * @param value allowed object is
369 * {@link Issues.Issue.Comment.Value } 358 * {@link Issues.Issue.Comment.Value }
370 */ 359 */
371 - public void setValue(Issues.Issue.Comment.Value value)  
372 - { 360 + public void setValue(Issues.Issue.Comment.Value value) {
373 this.value = value; 361 this.value = value;
374 } 362 }
375 363
@@ -379,8 +367,7 @@ public class Issues { @@ -379,8 +367,7 @@ public class Issues {
379 * @return possible object is 367 * @return possible object is
380 * {@link String } 368 * {@link String }
381 */ 369 */
382 - public String getId()  
383 - { 370 + public String getId() {
384 return id; 371 return id;
385 } 372 }
386 373
@@ -390,8 +377,7 @@ public class Issues { @@ -390,8 +377,7 @@ public class Issues {
390 * @param value allowed object is 377 * @param value allowed object is
391 * {@link String } 378 * {@link String }
392 */ 379 */
393 - public void setId(String value)  
394 - { 380 + public void setId(String value) {
395 this.id = value; 381 this.id = value;
396 } 382 }
397 383
@@ -401,8 +387,7 @@ public class Issues { @@ -401,8 +387,7 @@ public class Issues {
401 * @return possible object is 387 * @return possible object is
402 * {@link String } 388 * {@link String }
403 */ 389 */
404 - public String getAuthor()  
405 - { 390 + public String getAuthor() {
406 return author; 391 return author;
407 } 392 }
408 393
@@ -412,8 +397,7 @@ public class Issues { @@ -412,8 +397,7 @@ public class Issues {
412 * @param value allowed object is 397 * @param value allowed object is
413 * {@link String } 398 * {@link String }
414 */ 399 */
415 - public void setAuthor(String value)  
416 - { 400 + public void setAuthor(String value) {
417 this.author = value; 401 this.author = value;
418 } 402 }
419 403
@@ -423,8 +407,7 @@ public class Issues { @@ -423,8 +407,7 @@ public class Issues {
423 * @return possible object is 407 * @return possible object is
424 * {@link String } 408 * {@link String }
425 */ 409 */
426 - public String getIssueId()  
427 - { 410 + public String getIssueId() {
428 return issueId; 411 return issueId;
429 } 412 }
430 413
@@ -434,8 +417,7 @@ public class Issues { @@ -434,8 +417,7 @@ public class Issues {
434 * @param value allowed object is 417 * @param value allowed object is
435 * {@link String } 418 * {@link String }
436 */ 419 */
437 - public void setIssueId(String value)  
438 - { 420 + public void setIssueId(String value) {
439 this.issueId = value; 421 this.issueId = value;
440 } 422 }
441 423
@@ -445,8 +427,7 @@ public class Issues { @@ -445,8 +427,7 @@ public class Issues {
445 * @return possible object is 427 * @return possible object is
446 * {@link String } 428 * {@link String }
447 */ 429 */
448 - public String getDeleted()  
449 - { 430 + public String getDeleted() {
450 return deleted; 431 return deleted;
451 } 432 }
452 433
@@ -456,8 +437,7 @@ public class Issues { @@ -456,8 +437,7 @@ public class Issues {
456 * @param value allowed object is 437 * @param value allowed object is
457 * {@link String } 438 * {@link String }
458 */ 439 */
459 - public void setDeleted(String value)  
460 - { 440 + public void setDeleted(String value) {
461 this.deleted = value; 441 this.deleted = value;
462 } 442 }
463 443
@@ -467,8 +447,7 @@ public class Issues { @@ -467,8 +447,7 @@ public class Issues {
467 * @return possible object is 447 * @return possible object is
468 * {@link String } 448 * {@link String }
469 */ 449 */
470 - public String getText()  
471 - { 450 + public String getText() {
472 return text; 451 return text;
473 } 452 }
474 453
@@ -478,8 +457,7 @@ public class Issues { @@ -478,8 +457,7 @@ public class Issues {
478 * @param value allowed object is 457 * @param value allowed object is
479 * {@link String } 458 * {@link String }
480 */ 459 */
481 - public void setText(String value)  
482 - { 460 + public void setText(String value) {
483 this.text = value; 461 this.text = value;
484 } 462 }
485 463
@@ -489,8 +467,7 @@ public class Issues { @@ -489,8 +467,7 @@ public class Issues {
489 * @return possible object is 467 * @return possible object is
490 * {@link String } 468 * {@link String }
491 */ 469 */
492 - public String getShownForIssueAuthor()  
493 - { 470 + public String getShownForIssueAuthor() {
494 return shownForIssueAuthor; 471 return shownForIssueAuthor;
495 } 472 }
496 473
@@ -500,8 +477,7 @@ public class Issues { @@ -500,8 +477,7 @@ public class Issues {
500 * @param value allowed object is 477 * @param value allowed object is
501 * {@link String } 478 * {@link String }
502 */ 479 */
503 - public void setShownForIssueAuthor(String value)  
504 - { 480 + public void setShownForIssueAuthor(String value) {
505 this.shownForIssueAuthor = value; 481 this.shownForIssueAuthor = value;
506 } 482 }
507 483
@@ -511,8 +487,7 @@ public class Issues { @@ -511,8 +487,7 @@ public class Issues {
511 * @return possible object is 487 * @return possible object is
512 * {@link String } 488 * {@link String }
513 */ 489 */
514 - public String getCreated()  
515 - { 490 + public String getCreated() {
516 return created; 491 return created;
517 } 492 }
518 493
@@ -522,8 +497,7 @@ public class Issues { @@ -522,8 +497,7 @@ public class Issues {
522 * @param value allowed object is 497 * @param value allowed object is
523 * {@link String } 498 * {@link String }
524 */ 499 */
525 - public void setCreated(String value)  
526 - { 500 + public void setCreated(String value) {
527 this.created = value; 501 this.created = value;
528 } 502 }
529 503
@@ -533,8 +507,7 @@ public class Issues { @@ -533,8 +507,7 @@ public class Issues {
533 * @return possible object is 507 * @return possible object is
534 * {@link String } 508 * {@link String }
535 */ 509 */
536 - public String getName()  
537 - { 510 + public String getName() {
538 return name; 511 return name;
539 } 512 }
540 513
@@ -544,8 +517,7 @@ public class Issues { @@ -544,8 +517,7 @@ public class Issues {
544 * @param value allowed object is 517 * @param value allowed object is
545 * {@link String } 518 * {@link String }
546 */ 519 */
547 - public void setName(String value)  
548 - { 520 + public void setName(String value) {
549 this.name = value; 521 this.name = value;
550 } 522 }
551 523
@@ -566,15 +538,15 @@ public class Issues { @@ -566,15 +538,15 @@ public class Issues {
566 * </pre> 538 * </pre>
567 */ 539 */
568 @XmlAccessorType(XmlAccessType.FIELD) 540 @XmlAccessorType(XmlAccessType.FIELD)
569 - @XmlType(name = "", propOrder = {"value"}) 541 + @XmlType(name = "", propOrder = {
  542 + "value"
  543 + })
570 public static class Value { 544 public static class Value {
571 545
572 @XmlValue 546 @XmlValue
573 protected String value; 547 protected String value;
574 -  
575 @XmlAttribute 548 @XmlAttribute
576 protected String type; 549 protected String type;
577 -  
578 @XmlAttribute 550 @XmlAttribute
579 protected String role; 551 protected String role;
580 552
@@ -584,8 +556,7 @@ public class Issues { @@ -584,8 +556,7 @@ public class Issues {
584 * @return possible object is 556 * @return possible object is
585 * {@link String } 557 * {@link String }
586 */ 558 */
587 - public String getValue()  
588 - { 559 + public String getValue() {
589 return value; 560 return value;
590 } 561 }
591 562
@@ -595,8 +566,7 @@ public class Issues { @@ -595,8 +566,7 @@ public class Issues {
595 * @param value allowed object is 566 * @param value allowed object is
596 * {@link String } 567 * {@link String }
597 */ 568 */
598 - public void setValue(String value)  
599 - { 569 + public void setValue(String value) {
600 this.value = value; 570 this.value = value;
601 } 571 }
602 572
@@ -606,8 +576,7 @@ public class Issues { @@ -606,8 +576,7 @@ public class Issues {
606 * @return possible object is 576 * @return possible object is
607 * {@link String } 577 * {@link String }
608 */ 578 */
609 - public String getType()  
610 - { 579 + public String getType() {
611 return type; 580 return type;
612 } 581 }
613 582
@@ -617,8 +586,7 @@ public class Issues { @@ -617,8 +586,7 @@ public class Issues {
617 * @param value allowed object is 586 * @param value allowed object is
618 * {@link String } 587 * {@link String }
619 */ 588 */
620 - public void setType(String value)  
621 - { 589 + public void setType(String value) {
622 this.type = value; 590 this.type = value;
623 } 591 }
624 592
@@ -628,8 +596,7 @@ public class Issues { @@ -628,8 +596,7 @@ public class Issues {
628 * @return possible object is 596 * @return possible object is
629 * {@link String } 597 * {@link String }
630 */ 598 */
631 - public String getRole()  
632 - { 599 + public String getRole() {
633 return role; 600 return role;
634 } 601 }
635 602
@@ -639,11 +606,12 @@ public class Issues { @@ -639,11 +606,12 @@ public class Issues {
639 * @param value allowed object is 606 * @param value allowed object is
640 * {@link String } 607 * {@link String }
641 */ 608 */
642 - public void setRole(String value)  
643 - { 609 + public void setRole(String value) {
644 this.role = value; 610 this.role = value;
645 } 611 }
  612 +
646 } 613 }
  614 +
647 } 615 }
648 616
649 /** 617 /**
@@ -674,43 +642,41 @@ public class Issues { @@ -674,43 +642,41 @@ public class Issues {
674 * </pre> 642 * </pre>
675 */ 643 */
676 @XmlAccessorType(XmlAccessType.FIELD) 644 @XmlAccessorType(XmlAccessType.FIELD)
677 - @XmlType(name = "", propOrder = {"content"}) 645 + @XmlType(name = "", propOrder = {
  646 + "values"
  647 + })
678 public static class Field { 648 public static class Field {
679 649
680 - @XmlElementRef(name = "value", type = JAXBElement.class)  
681 - @XmlMixed  
682 - protected List<Serializable> content;  
683 - 650 + @XmlElement(name = "value")
  651 + protected List<Issues.Issue.Field.Value> values;
684 @XmlAttribute 652 @XmlAttribute
685 protected String name; 653 protected String name;
686 654
687 /** 655 /**
688 - * Gets the value of the content property. 656 + * Gets the value of the values property.
689 * <p/> 657 * <p/>
690 * <p/> 658 * <p/>
691 * This accessor method returns a reference to the live list, 659 * This accessor method returns a reference to the live list,
692 * not a snapshot. Therefore any modification you make to the 660 * not a snapshot. Therefore any modification you make to the
693 * returned list will be present inside the JAXB object. 661 * returned list will be present inside the JAXB object.
694 - * This is why there is not a <CODE>set</CODE> method for the content property. 662 + * This is why there is not a <CODE>set</CODE> method for the values property.
695 * <p/> 663 * <p/>
696 * <p/> 664 * <p/>
697 * For example, to add a new item, do as follows: 665 * For example, to add a new item, do as follows:
698 * <pre> 666 * <pre>
699 - * getContent().add(newItem); 667 + * getValues().add(newItem);
700 * </pre> 668 * </pre>
701 * <p/> 669 * <p/>
702 * <p/> 670 * <p/>
703 * <p/> 671 * <p/>
704 * Objects of the following type(s) are allowed in the list 672 * Objects of the following type(s) are allowed in the list
705 - * {@link String }  
706 - * {@link JAXBElement }{@code <}{@link Issues.Issue.Field.Value }{@code >} 673 + * {@link Issues.Issue.Field.Value }
707 */ 674 */
708 - public List<Serializable> getContent()  
709 - {  
710 - if (content == null) {  
711 - content = new ArrayList<Serializable>(); 675 + public List<Issues.Issue.Field.Value> getValues() {
  676 + if (values == null) {
  677 + values = new ArrayList<Issues.Issue.Field.Value>();
712 } 678 }
713 - return this.content; 679 + return this.values;
714 } 680 }
715 681
716 /** 682 /**
@@ -719,8 +685,7 @@ public class Issues { @@ -719,8 +685,7 @@ public class Issues {
719 * @return possible object is 685 * @return possible object is
720 * {@link String } 686 * {@link String }
721 */ 687 */
722 - public String getName()  
723 - { 688 + public String getName() {
724 return name; 689 return name;
725 } 690 }
726 691
@@ -730,8 +695,7 @@ public class Issues { @@ -730,8 +695,7 @@ public class Issues {
730 * @param value allowed object is 695 * @param value allowed object is
731 * {@link String } 696 * {@link String }
732 */ 697 */
733 - public void setName(String value)  
734 - { 698 + public void setName(String value) {
735 this.name = value; 699 this.name = value;
736 } 700 }
737 701
@@ -752,23 +716,45 @@ public class Issues { @@ -752,23 +716,45 @@ public class Issues {
752 * </pre> 716 * </pre>
753 */ 717 */
754 @XmlAccessorType(XmlAccessType.FIELD) 718 @XmlAccessorType(XmlAccessType.FIELD)
755 - @XmlType(name = "") 719 + @XmlType(name = "", propOrder = {
  720 + "content"
  721 + })
756 public static class Value { 722 public static class Value {
757 723
  724 + @XmlValue
  725 + protected String content;
758 @XmlAttribute 726 @XmlAttribute
759 protected String type; 727 protected String type;
760 -  
761 @XmlAttribute 728 @XmlAttribute
762 protected String role; 729 protected String role;
763 730
764 /** 731 /**
  732 + * Gets the value of the content property.
  733 + *
  734 + * @return possible object is
  735 + * {@link String }
  736 + */
  737 + public String getContent() {
  738 + return content;
  739 + }
  740 +
  741 + /**
  742 + * Sets the value of the content property.
  743 + *
  744 + * @param value allowed object is
  745 + * {@link String }
  746 + */
  747 + public void setContent(String value) {
  748 + this.content = value;
  749 + }
  750 +
  751 + /**
765 * Gets the value of the type property. 752 * Gets the value of the type property.
766 * 753 *
767 * @return possible object is 754 * @return possible object is
768 * {@link String } 755 * {@link String }
769 */ 756 */
770 - public String getType()  
771 - { 757 + public String getType() {
772 return type; 758 return type;
773 } 759 }
774 760
@@ -778,8 +764,7 @@ public class Issues { @@ -778,8 +764,7 @@ public class Issues {
778 * @param value allowed object is 764 * @param value allowed object is
779 * {@link String } 765 * {@link String }
780 */ 766 */
781 - public void setType(String value)  
782 - { 767 + public void setType(String value) {
783 this.type = value; 768 this.type = value;
784 } 769 }
785 770
@@ -789,8 +774,7 @@ public class Issues { @@ -789,8 +774,7 @@ public class Issues {
789 * @return possible object is 774 * @return possible object is
790 * {@link String } 775 * {@link String }
791 */ 776 */
792 - public String getRole()  
793 - { 777 + public String getRole() {
794 return role; 778 return role;
795 } 779 }
796 780
@@ -800,11 +784,14 @@ public class Issues { @@ -800,11 +784,14 @@ public class Issues {
800 * @param value allowed object is 784 * @param value allowed object is
801 * {@link String } 785 * {@link String }
802 */ 786 */
803 - public void setRole(String value)  
804 - { 787 + public void setRole(String value) {
805 this.role = value; 788 this.role = value;
806 } 789 }
  790 +
807 } 791 }
  792 +
808 } 793 }
  794 +
809 } 795 }
  796 +
810 } 797 }
@@ -2,15 +2,12 @@ @@ -2,15 +2,12 @@
2 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 2 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833
3 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 3 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
4 // Any modifications to this file will be lost upon recompilation of the source schema. 4 // Any modifications to this file will be lost upon recompilation of the source schema.
5 -// Generated on: 2011.12.05 at 08:56:01 AM CET 5 +// Generated on: 2011.12.16 at 09:34:48 AM CET
6 // 6 //
7 7
8 package pl.com.it_crowd.youtrack.api.rest; 8 package pl.com.it_crowd.youtrack.api.rest;
9 9
10 -import javax.xml.bind.JAXBElement;  
11 -import javax.xml.bind.annotation.XmlElementDecl;  
12 import javax.xml.bind.annotation.XmlRegistry; 10 import javax.xml.bind.annotation.XmlRegistry;
13 -import javax.xml.namespace.QName;  
14 11
15 /** 12 /**
16 * This object contains factory methods for each 13 * This object contains factory methods for each
@@ -28,69 +25,52 @@ import javax.xml.namespace.QName; @@ -28,69 +25,52 @@ import javax.xml.namespace.QName;
28 @XmlRegistry 25 @XmlRegistry
29 public class ObjectFactory { 26 public class ObjectFactory {
30 27
31 - private final static QName _IssuesIssueFieldValue_QNAME = new QName("", "value");  
32 -  
33 /** 28 /**
34 * 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 29 * 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
35 */ 30 */
36 - public ObjectFactory()  
37 - { 31 + public ObjectFactory() {
38 } 32 }
39 33
40 /** 34 /**
41 * Create an instance of {@link Issues.Issue.Comment.Value } 35 * Create an instance of {@link Issues.Issue.Comment.Value }
42 */ 36 */
43 - public Issues.Issue.Comment.Value createIssuesIssueCommentValue()  
44 - { 37 + public Issues.Issue.Comment.Value createIssuesIssueCommentValue() {
45 return new Issues.Issue.Comment.Value(); 38 return new Issues.Issue.Comment.Value();
46 } 39 }
47 40
48 /** 41 /**
49 - * Create an instance of {@link Issues.Issue.Comment }  
50 - */  
51 - public Issues.Issue.Comment createIssuesIssueComment()  
52 - {  
53 - return new Issues.Issue.Comment();  
54 - }  
55 -  
56 - /**  
57 * Create an instance of {@link Issues.Issue.Field } 42 * Create an instance of {@link Issues.Issue.Field }
58 */ 43 */
59 - public Issues.Issue.Field createIssuesIssueField()  
60 - { 44 + public Issues.Issue.Field createIssuesIssueField() {
61 return new Issues.Issue.Field(); 45 return new Issues.Issue.Field();
62 } 46 }
63 47
64 /** 48 /**
65 * Create an instance of {@link Issues } 49 * Create an instance of {@link Issues }
66 */ 50 */
67 - public Issues createIssues()  
68 - { 51 + public Issues createIssues() {
69 return new Issues(); 52 return new Issues();
70 } 53 }
71 54
72 /** 55 /**
73 - * Create an instance of {@link Issues.Issue } 56 + * Create an instance of {@link Issues.Issue.Field.Value }
74 */ 57 */
75 - public Issues.Issue createIssuesIssue()  
76 - {  
77 - return new Issues.Issue(); 58 + public Issues.Issue.Field.Value createIssuesIssueFieldValue() {
  59 + return new Issues.Issue.Field.Value();
78 } 60 }
79 61
80 /** 62 /**
81 - * Create an instance of {@link Issues.Issue.Field.Value } 63 + * Create an instance of {@link Issues.Issue.Comment }
82 */ 64 */
83 - public Issues.Issue.Field.Value createIssuesIssueFieldValue()  
84 - {  
85 - return new Issues.Issue.Field.Value(); 65 + public Issues.Issue.Comment createIssuesIssueComment() {
  66 + return new Issues.Issue.Comment();
86 } 67 }
87 68
88 /** 69 /**
89 - * Create an instance of {@link JAXBElement }{@code <}{@link Issues.Issue.Field.Value }{@code >}} 70 + * Create an instance of {@link Issues.Issue }
90 */ 71 */
91 - @XmlElementDecl(namespace = "", name = "value", scope = Issues.Issue.Field.class)  
92 - public JAXBElement<Issues.Issue.Field.Value> createIssuesIssueFieldValue(Issues.Issue.Field.Value value)  
93 - {  
94 - return new JAXBElement<Issues.Issue.Field.Value>(_IssuesIssueFieldValue_QNAME, Issues.Issue.Field.Value.class, Issues.Issue.Field.class, value); 72 + public Issues.Issue createIssuesIssue() {
  73 + return new Issues.Issue();
95 } 74 }
  75 +
96 } 76 }
1 package pl.com.it_crowd.youtrack.api.rest; 1 package pl.com.it_crowd.youtrack.api.rest;
2 2
3 import com.gargoylesoftware.htmlunit.BrowserVersion; 3 import com.gargoylesoftware.htmlunit.BrowserVersion;
  4 +import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
4 import com.gargoylesoftware.htmlunit.HttpMethod; 5 import com.gargoylesoftware.htmlunit.HttpMethod;
5 import com.gargoylesoftware.htmlunit.Page; 6 import com.gargoylesoftware.htmlunit.Page;
6 import com.gargoylesoftware.htmlunit.WebClient; 7 import com.gargoylesoftware.htmlunit.WebClient;
7 import com.gargoylesoftware.htmlunit.WebRequest; 8 import com.gargoylesoftware.htmlunit.WebRequest;
8 import com.gargoylesoftware.htmlunit.WebResponse; 9 import com.gargoylesoftware.htmlunit.WebResponse;
  10 +import com.gargoylesoftware.htmlunit.html.DomNode;
9 import com.gargoylesoftware.htmlunit.util.NameValuePair; 11 import com.gargoylesoftware.htmlunit.util.NameValuePair;
  12 +import com.gargoylesoftware.htmlunit.xml.XmlPage;
  13 +import org.apache.http.auth.AuthenticationException;
  14 +import pl.com.it_crowd.youtrack.api.Issue;
10 import pl.com.it_crowd.youtrack.api.IssuesUnmarshaller; 15 import pl.com.it_crowd.youtrack.api.IssuesUnmarshaller;
11 16
12 import javax.xml.bind.JAXBException; 17 import javax.xml.bind.JAXBException;
13 import java.io.IOException; 18 import java.io.IOException;
14 import java.net.URL; 19 import java.net.URL;
15 import java.util.ArrayList; 20 import java.util.ArrayList;
  21 +import java.util.List;
16 22
17 public class YoutrackAPI { 23 public class YoutrackAPI {
  24 +// ------------------------------ FIELDS ------------------------------
18 25
19 private String serviceLocation; 26 private String serviceLocation;
20 27
21 private WebClient webClient; 28 private WebClient webClient;
22 29
23 - public String getServiceLocation()  
24 - {  
25 - return serviceLocation;  
26 - } 30 +// --------------------------- CONSTRUCTORS ---------------------------
27 31
28 - public YoutrackAPI(String serviceLocation)  
29 - { 32 + public YoutrackAPI(String serviceLocation) {
30 this.serviceLocation = serviceLocation; 33 this.serviceLocation = serviceLocation;
31 this.webClient = new WebClient(BrowserVersion.FIREFOX_3_6); 34 this.webClient = new WebClient(BrowserVersion.FIREFOX_3_6);
32 this.webClient.setJavaScriptEnabled(false); 35 this.webClient.setJavaScriptEnabled(false);
33 this.webClient.setCssEnabled(false); 36 this.webClient.setCssEnabled(false);
34 } 37 }
35 38
36 - public YoutrackAPI(String serviceLocation, String username, String password) throws IOException  
37 - { 39 + public YoutrackAPI(String serviceLocation, String username, String password) throws IOException, AuthenticationException {
38 this(serviceLocation); 40 this(serviceLocation);
39 login(username, password); 41 login(username, password);
40 } 42 }
41 43
42 - public void login(String username, String password) throws IOException  
43 - { 44 +// --------------------- GETTER / SETTER METHODS ---------------------
  45 +
  46 + public String getServiceLocation() {
  47 + return serviceLocation;
  48 + }
  49 +
  50 +// -------------------------- OTHER METHODS --------------------------
  51 +
  52 + public void login(String username, String password) throws IOException, AuthenticationException {
44 ArrayList<NameValuePair> requestParameters = new ArrayList<NameValuePair>(); 53 ArrayList<NameValuePair> requestParameters = new ArrayList<NameValuePair>();
45 requestParameters.add(new NameValuePair("login", username)); 54 requestParameters.add(new NameValuePair("login", username));
46 requestParameters.add(new NameValuePair("password", password)); 55 requestParameters.add(new NameValuePair("password", password));
47 WebRequest request = new WebRequest(new URL(serviceLocation + "/rest/user/login"), HttpMethod.POST); 56 WebRequest request = new WebRequest(new URL(serviceLocation + "/rest/user/login"), HttpMethod.POST);
48 request.setRequestParameters(requestParameters); 57 request.setRequestParameters(requestParameters);
49 - WebResponse response = webClient.getPage(request).getWebResponse();  
50 - System.out.println(response);  
51 - System.out.println(response.getContentAsString()); 58 + try {
  59 + webClient.getPage(request);
  60 + } catch (FailingHttpStatusCodeException e) {
  61 + if (e.getStatusCode() == 403) {
  62 + DomNode error = ((XmlPage) webClient.getCurrentWindow().getEnclosedPage()).getFirstChild();
  63 + if (error != null) {
  64 + throw new AuthenticationException(error.getTextContent());
  65 + }
  66 + }
  67 + throw e;
  68 + }
52 } 69 }
53 70
54 - public Issues searchIssuesByProject(String project, String filter) throws JAXBException, IOException  
55 - { 71 + public List<Issue> searchIssuesByProject(String project, String filter) throws JAXBException, IOException {
56 String url = serviceLocation + "/rest/issue/byproject/" + project + "?filter=" + filter; 72 String url = serviceLocation + "/rest/issue/byproject/" + project + "?filter=" + filter;
57 - return IssuesUnmarshaller.unmarshal(webClient.<Page>getPage(url).getWebResponse().getContentAsStream()); 73 + WebResponse webResponse = webClient.<Page>getPage(url).getWebResponse();
  74 +// System.out.println(webResponse.getContentAsString());
  75 + List<Issues.Issue> issues = IssuesUnmarshaller.unmarshal(webResponse.getContentAsStream()).getIssue();
  76 + List<Issue> result = new ArrayList<Issue>();
  77 + for (Issues.Issue issue : issues) {
  78 + result.add(new Issue(issue));
  79 + }
  80 + return result;
58 } 81 }
59 } 82 }
  1 +<jxb:bindings version="1.0"
  2 + xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
  3 + xmlns:xs="http://www.w3.org/2001/XMLSchema"
  4 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5 + xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
  6 + >
  7 + <jxb:bindings schemaLocation="../xsd/issuesByProject.xsd" node="/xs:schema">
  8 +
  9 + <jxb:globalBindings localScoping="nested"/>
  10 + <jxb:bindings node="//xs:element[@name='issues']">
  11 + <jxb:bindings node=".//xs:element[@name='field']">
  12 + <jxb:bindings node=".//xs:element[@name='value']">
  13 + <jxb:property name="values"/>
  14 + </jxb:bindings>
  15 + </jxb:bindings>
  16 + </jxb:bindings>
  17 + </jxb:bindings>
  18 +</jxb:bindings>
1 <?xml version="1.0" encoding="UTF-8"?> 1 <?xml version="1.0" encoding="UTF-8"?>
2 -<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 2 +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3 <xs:element name="issues"> 3 <xs:element name="issues">
4 <xs:complexType> 4 <xs:complexType>
5 <xs:sequence> 5 <xs:sequence>
@@ -7,10 +7,10 @@ @@ -7,10 +7,10 @@
7 <xs:complexType> 7 <xs:complexType>
8 <xs:choice maxOccurs="unbounded" minOccurs="0"> 8 <xs:choice maxOccurs="unbounded" minOccurs="0">
9 <xs:element name="field"> 9 <xs:element name="field">
10 - <xs:complexType mixed="true"> 10 + <xs:complexType>
11 <xs:sequence> 11 <xs:sequence>
12 <xs:element name="value" maxOccurs="unbounded" minOccurs="0"> 12 <xs:element name="value" maxOccurs="unbounded" minOccurs="0">
13 - <xs:complexType> 13 + <xs:complexType mixed="true">
14 <xs:attribute type="xs:string" name="type" use="optional"/> 14 <xs:attribute type="xs:string" name="type" use="optional"/>
15 <xs:attribute type="xs:string" name="role" use="optional"/> 15 <xs:attribute type="xs:string" name="role" use="optional"/>
16 </xs:complexType> 16 </xs:complexType>
  1 +package pl.com.it_crowd.youtrack.api.rest;
  2 +
  3 +import junit.framework.Assert;
  4 +import org.apache.http.auth.AuthenticationException;
  5 +import org.junit.Test;
  6 +import pl.com.it_crowd.youtrack.api.Issue;
  7 +
  8 +import javax.xml.bind.JAXBException;
  9 +import java.io.IOException;
  10 +import java.util.List;
  11 +
  12 +/**
  13 + * This test requires setting JVM params youtrackUsername and youtrackPassword.
  14 + */
  15 +public class YoutrackAPITest {
  16 +// -------------------------- OTHER METHODS --------------------------
  17 +
  18 + @Test(expected = AuthenticationException.class)
  19 + public void loginFailureTest() throws IOException, AuthenticationException {
  20 + final String username = "someFakeLogin";
  21 + final String password = "someFakePassword";
  22 + new YoutrackAPI("http://youtrack.it-crowd.com.pl", username, password);
  23 + }
  24 +
  25 + @Test
  26 + public void loginTest() throws IOException, AuthenticationException {
  27 + final String username = getUsername();
  28 + final String password = getPassword();
  29 + new YoutrackAPI("http://youtrack.it-crowd.com.pl", username, password);
  30 + YoutrackAPI api = new YoutrackAPI("http://youtrack.it-crowd.com.pl");
  31 + api.login(username, password);
  32 + }
  33 +
  34 + @Test
  35 + public void searchIssuesByProjectTest() throws IOException, AuthenticationException, JAXBException {
  36 + YoutrackAPI api = new YoutrackAPI("http://youtrack.it-crowd.com.pl", getUsername(), getPassword());
  37 + List<Issue> issues = api.searchIssuesByProject("SM", null);
  38 + Assert.assertTrue(!issues.isEmpty());
  39 + for (Issue issue : issues) {
  40 + String summary = issue.getFieldValue(Issue.Fields.summary);
  41 + Assert.assertNotNull(summary);
  42 + Assert.assertTrue(!"".equals(summary.trim()));
  43 + }
  44 + }
  45 +
  46 + private String getPassword() {
  47 + return System.getProperty("youtrackPassword");
  48 + }
  49 +
  50 + private String getUsername() {
  51 + return System.getProperty("youtrackUsername");
  52 + }
  53 +}
Please register or login to post a comment