Commit 4bd2f591c73171cb7bee3d6631fdf60c6d07a37a
1 parent
1fa60124
Implemented login and searchIssueByProject tests.
Showing
8 changed files
with
292 additions
and
167 deletions
... | ... | @@ -3,7 +3,7 @@ |
3 | 3 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
4 | 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 | 7 | <artifactId>youtrack-rest-api</artifactId> |
8 | 8 | <version>1.0.0-SNAPSHOT</version> |
9 | 9 | |
... | ... | @@ -60,6 +60,7 @@ |
60 | 60 | <packageName>pl.com.it_crowd.youtrack.api.rest</packageName> |
61 | 61 | <outputDirectory>${build.sourceDirectory}</outputDirectory> |
62 | 62 | <clearOutputDir>false</clearOutputDir> |
63 | + <extension>false</extension> | |
63 | 64 | </configuration> |
64 | 65 | </plugin> |
65 | 66 | </plugins> |
... | ... | @@ -74,4 +75,4 @@ |
74 | 75 | <url>http://artifactory.it-crowd.com.pl/libs-snapshot-local</url> |
75 | 76 | </snapshotRepository> |
76 | 77 | </distributionManagement> |
77 | -</project> | |
\ No newline at end of file | ||
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 | 2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 |
3 | 3 | // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> |
4 | 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 | 8 | package pl.com.it_crowd.youtrack.api.rest; |
9 | 9 | |
10 | -import javax.xml.bind.JAXBElement; | |
11 | 10 | import javax.xml.bind.annotation.XmlAccessType; |
12 | 11 | import javax.xml.bind.annotation.XmlAccessorType; |
13 | 12 | import javax.xml.bind.annotation.XmlAttribute; |
14 | 13 | import javax.xml.bind.annotation.XmlElement; |
15 | -import javax.xml.bind.annotation.XmlElementRef; | |
16 | 14 | import javax.xml.bind.annotation.XmlElements; |
17 | -import javax.xml.bind.annotation.XmlMixed; | |
18 | 15 | import javax.xml.bind.annotation.XmlRootElement; |
19 | 16 | import javax.xml.bind.annotation.XmlType; |
20 | 17 | import javax.xml.bind.annotation.XmlValue; |
21 | -import java.io.Serializable; | |
22 | 18 | import java.util.ArrayList; |
23 | 19 | import java.util.List; |
24 | 20 | |
... | ... | @@ -100,7 +96,9 @@ import java.util.List; |
100 | 96 | * </pre> |
101 | 97 | */ |
102 | 98 | @XmlAccessorType(XmlAccessType.FIELD) |
103 | -@XmlType(name = "", propOrder = {"issue"}) | |
99 | +@XmlType(name = "", propOrder = { | |
100 | + "issue" | |
101 | +}) | |
104 | 102 | @XmlRootElement(name = "issues") |
105 | 103 | public class Issues { |
106 | 104 | |
... | ... | @@ -126,8 +124,7 @@ public class Issues { |
126 | 124 | * Objects of the following type(s) are allowed in the list |
127 | 125 | * {@link Issues.Issue } |
128 | 126 | */ |
129 | - public List<Issues.Issue> getIssue() | |
130 | - { | |
127 | + public List<Issues.Issue> getIssue() { | |
131 | 128 | if (issue == null) { |
132 | 129 | issue = new ArrayList<Issues.Issue>(); |
133 | 130 | } |
... | ... | @@ -202,12 +199,16 @@ public class Issues { |
202 | 199 | * </pre> |
203 | 200 | */ |
204 | 201 | @XmlAccessorType(XmlAccessType.FIELD) |
205 | - @XmlType(name = "", propOrder = {"fieldOrComment"}) | |
202 | + @XmlType(name = "", propOrder = { | |
203 | + "fieldOrComment" | |
204 | + }) | |
206 | 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 | 211 | protected List<Object> fieldOrComment; |
210 | - | |
211 | 212 | @XmlAttribute |
212 | 213 | protected String id; |
213 | 214 | |
... | ... | @@ -232,8 +233,7 @@ public class Issues { |
232 | 233 | * {@link Issues.Issue.Field } |
233 | 234 | * {@link Issues.Issue.Comment } |
234 | 235 | */ |
235 | - public List<Object> getFieldOrComment() | |
236 | - { | |
236 | + public List<Object> getFieldOrComment() { | |
237 | 237 | if (fieldOrComment == null) { |
238 | 238 | fieldOrComment = new ArrayList<Object>(); |
239 | 239 | } |
... | ... | @@ -246,8 +246,7 @@ public class Issues { |
246 | 246 | * @return possible object is |
247 | 247 | * {@link String } |
248 | 248 | */ |
249 | - public String getId() | |
250 | - { | |
249 | + public String getId() { | |
251 | 250 | return id; |
252 | 251 | } |
253 | 252 | |
... | ... | @@ -257,8 +256,7 @@ public class Issues { |
257 | 256 | * @param value allowed object is |
258 | 257 | * {@link String } |
259 | 258 | */ |
260 | - public void setId(String value) | |
261 | - { | |
259 | + public void setId(String value) { | |
262 | 260 | this.id = value; |
263 | 261 | } |
264 | 262 | |
... | ... | @@ -298,34 +296,28 @@ public class Issues { |
298 | 296 | * </pre> |
299 | 297 | */ |
300 | 298 | @XmlAccessorType(XmlAccessType.FIELD) |
301 | - @XmlType(name = "", propOrder = {"replies", "value"}) | |
299 | + @XmlType(name = "", propOrder = { | |
300 | + "replies", | |
301 | + "value" | |
302 | + }) | |
302 | 303 | public static class Comment { |
303 | 304 | |
304 | 305 | protected String replies; |
305 | - | |
306 | 306 | protected Issues.Issue.Comment.Value value; |
307 | - | |
308 | 307 | @XmlAttribute |
309 | 308 | protected String id; |
310 | - | |
311 | 309 | @XmlAttribute |
312 | 310 | protected String author; |
313 | - | |
314 | 311 | @XmlAttribute |
315 | 312 | protected String issueId; |
316 | - | |
317 | 313 | @XmlAttribute |
318 | 314 | protected String deleted; |
319 | - | |
320 | 315 | @XmlAttribute |
321 | 316 | protected String text; |
322 | - | |
323 | 317 | @XmlAttribute |
324 | 318 | protected String shownForIssueAuthor; |
325 | - | |
326 | 319 | @XmlAttribute |
327 | 320 | protected String created; |
328 | - | |
329 | 321 | @XmlAttribute |
330 | 322 | protected String name; |
331 | 323 | |
... | ... | @@ -335,8 +327,7 @@ public class Issues { |
335 | 327 | * @return possible object is |
336 | 328 | * {@link String } |
337 | 329 | */ |
338 | - public String getReplies() | |
339 | - { | |
330 | + public String getReplies() { | |
340 | 331 | return replies; |
341 | 332 | } |
342 | 333 | |
... | ... | @@ -346,8 +337,7 @@ public class Issues { |
346 | 337 | * @param value allowed object is |
347 | 338 | * {@link String } |
348 | 339 | */ |
349 | - public void setReplies(String value) | |
350 | - { | |
340 | + public void setReplies(String value) { | |
351 | 341 | this.replies = value; |
352 | 342 | } |
353 | 343 | |
... | ... | @@ -357,8 +347,7 @@ public class Issues { |
357 | 347 | * @return possible object is |
358 | 348 | * {@link Issues.Issue.Comment.Value } |
359 | 349 | */ |
360 | - public Issues.Issue.Comment.Value getValue() | |
361 | - { | |
350 | + public Issues.Issue.Comment.Value getValue() { | |
362 | 351 | return value; |
363 | 352 | } |
364 | 353 | |
... | ... | @@ -368,8 +357,7 @@ public class Issues { |
368 | 357 | * @param value allowed object is |
369 | 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 | 361 | this.value = value; |
374 | 362 | } |
375 | 363 | |
... | ... | @@ -379,8 +367,7 @@ public class Issues { |
379 | 367 | * @return possible object is |
380 | 368 | * {@link String } |
381 | 369 | */ |
382 | - public String getId() | |
383 | - { | |
370 | + public String getId() { | |
384 | 371 | return id; |
385 | 372 | } |
386 | 373 | |
... | ... | @@ -390,8 +377,7 @@ public class Issues { |
390 | 377 | * @param value allowed object is |
391 | 378 | * {@link String } |
392 | 379 | */ |
393 | - public void setId(String value) | |
394 | - { | |
380 | + public void setId(String value) { | |
395 | 381 | this.id = value; |
396 | 382 | } |
397 | 383 | |
... | ... | @@ -401,8 +387,7 @@ public class Issues { |
401 | 387 | * @return possible object is |
402 | 388 | * {@link String } |
403 | 389 | */ |
404 | - public String getAuthor() | |
405 | - { | |
390 | + public String getAuthor() { | |
406 | 391 | return author; |
407 | 392 | } |
408 | 393 | |
... | ... | @@ -412,8 +397,7 @@ public class Issues { |
412 | 397 | * @param value allowed object is |
413 | 398 | * {@link String } |
414 | 399 | */ |
415 | - public void setAuthor(String value) | |
416 | - { | |
400 | + public void setAuthor(String value) { | |
417 | 401 | this.author = value; |
418 | 402 | } |
419 | 403 | |
... | ... | @@ -423,8 +407,7 @@ public class Issues { |
423 | 407 | * @return possible object is |
424 | 408 | * {@link String } |
425 | 409 | */ |
426 | - public String getIssueId() | |
427 | - { | |
410 | + public String getIssueId() { | |
428 | 411 | return issueId; |
429 | 412 | } |
430 | 413 | |
... | ... | @@ -434,8 +417,7 @@ public class Issues { |
434 | 417 | * @param value allowed object is |
435 | 418 | * {@link String } |
436 | 419 | */ |
437 | - public void setIssueId(String value) | |
438 | - { | |
420 | + public void setIssueId(String value) { | |
439 | 421 | this.issueId = value; |
440 | 422 | } |
441 | 423 | |
... | ... | @@ -445,8 +427,7 @@ public class Issues { |
445 | 427 | * @return possible object is |
446 | 428 | * {@link String } |
447 | 429 | */ |
448 | - public String getDeleted() | |
449 | - { | |
430 | + public String getDeleted() { | |
450 | 431 | return deleted; |
451 | 432 | } |
452 | 433 | |
... | ... | @@ -456,8 +437,7 @@ public class Issues { |
456 | 437 | * @param value allowed object is |
457 | 438 | * {@link String } |
458 | 439 | */ |
459 | - public void setDeleted(String value) | |
460 | - { | |
440 | + public void setDeleted(String value) { | |
461 | 441 | this.deleted = value; |
462 | 442 | } |
463 | 443 | |
... | ... | @@ -467,8 +447,7 @@ public class Issues { |
467 | 447 | * @return possible object is |
468 | 448 | * {@link String } |
469 | 449 | */ |
470 | - public String getText() | |
471 | - { | |
450 | + public String getText() { | |
472 | 451 | return text; |
473 | 452 | } |
474 | 453 | |
... | ... | @@ -478,8 +457,7 @@ public class Issues { |
478 | 457 | * @param value allowed object is |
479 | 458 | * {@link String } |
480 | 459 | */ |
481 | - public void setText(String value) | |
482 | - { | |
460 | + public void setText(String value) { | |
483 | 461 | this.text = value; |
484 | 462 | } |
485 | 463 | |
... | ... | @@ -489,8 +467,7 @@ public class Issues { |
489 | 467 | * @return possible object is |
490 | 468 | * {@link String } |
491 | 469 | */ |
492 | - public String getShownForIssueAuthor() | |
493 | - { | |
470 | + public String getShownForIssueAuthor() { | |
494 | 471 | return shownForIssueAuthor; |
495 | 472 | } |
496 | 473 | |
... | ... | @@ -500,8 +477,7 @@ public class Issues { |
500 | 477 | * @param value allowed object is |
501 | 478 | * {@link String } |
502 | 479 | */ |
503 | - public void setShownForIssueAuthor(String value) | |
504 | - { | |
480 | + public void setShownForIssueAuthor(String value) { | |
505 | 481 | this.shownForIssueAuthor = value; |
506 | 482 | } |
507 | 483 | |
... | ... | @@ -511,8 +487,7 @@ public class Issues { |
511 | 487 | * @return possible object is |
512 | 488 | * {@link String } |
513 | 489 | */ |
514 | - public String getCreated() | |
515 | - { | |
490 | + public String getCreated() { | |
516 | 491 | return created; |
517 | 492 | } |
518 | 493 | |
... | ... | @@ -522,8 +497,7 @@ public class Issues { |
522 | 497 | * @param value allowed object is |
523 | 498 | * {@link String } |
524 | 499 | */ |
525 | - public void setCreated(String value) | |
526 | - { | |
500 | + public void setCreated(String value) { | |
527 | 501 | this.created = value; |
528 | 502 | } |
529 | 503 | |
... | ... | @@ -533,8 +507,7 @@ public class Issues { |
533 | 507 | * @return possible object is |
534 | 508 | * {@link String } |
535 | 509 | */ |
536 | - public String getName() | |
537 | - { | |
510 | + public String getName() { | |
538 | 511 | return name; |
539 | 512 | } |
540 | 513 | |
... | ... | @@ -544,8 +517,7 @@ public class Issues { |
544 | 517 | * @param value allowed object is |
545 | 518 | * {@link String } |
546 | 519 | */ |
547 | - public void setName(String value) | |
548 | - { | |
520 | + public void setName(String value) { | |
549 | 521 | this.name = value; |
550 | 522 | } |
551 | 523 | |
... | ... | @@ -566,15 +538,15 @@ public class Issues { |
566 | 538 | * </pre> |
567 | 539 | */ |
568 | 540 | @XmlAccessorType(XmlAccessType.FIELD) |
569 | - @XmlType(name = "", propOrder = {"value"}) | |
541 | + @XmlType(name = "", propOrder = { | |
542 | + "value" | |
543 | + }) | |
570 | 544 | public static class Value { |
571 | 545 | |
572 | 546 | @XmlValue |
573 | 547 | protected String value; |
574 | - | |
575 | 548 | @XmlAttribute |
576 | 549 | protected String type; |
577 | - | |
578 | 550 | @XmlAttribute |
579 | 551 | protected String role; |
580 | 552 | |
... | ... | @@ -584,8 +556,7 @@ public class Issues { |
584 | 556 | * @return possible object is |
585 | 557 | * {@link String } |
586 | 558 | */ |
587 | - public String getValue() | |
588 | - { | |
559 | + public String getValue() { | |
589 | 560 | return value; |
590 | 561 | } |
591 | 562 | |
... | ... | @@ -595,8 +566,7 @@ public class Issues { |
595 | 566 | * @param value allowed object is |
596 | 567 | * {@link String } |
597 | 568 | */ |
598 | - public void setValue(String value) | |
599 | - { | |
569 | + public void setValue(String value) { | |
600 | 570 | this.value = value; |
601 | 571 | } |
602 | 572 | |
... | ... | @@ -606,8 +576,7 @@ public class Issues { |
606 | 576 | * @return possible object is |
607 | 577 | * {@link String } |
608 | 578 | */ |
609 | - public String getType() | |
610 | - { | |
579 | + public String getType() { | |
611 | 580 | return type; |
612 | 581 | } |
613 | 582 | |
... | ... | @@ -617,8 +586,7 @@ public class Issues { |
617 | 586 | * @param value allowed object is |
618 | 587 | * {@link String } |
619 | 588 | */ |
620 | - public void setType(String value) | |
621 | - { | |
589 | + public void setType(String value) { | |
622 | 590 | this.type = value; |
623 | 591 | } |
624 | 592 | |
... | ... | @@ -628,8 +596,7 @@ public class Issues { |
628 | 596 | * @return possible object is |
629 | 597 | * {@link String } |
630 | 598 | */ |
631 | - public String getRole() | |
632 | - { | |
599 | + public String getRole() { | |
633 | 600 | return role; |
634 | 601 | } |
635 | 602 | |
... | ... | @@ -639,11 +606,12 @@ public class Issues { |
639 | 606 | * @param value allowed object is |
640 | 607 | * {@link String } |
641 | 608 | */ |
642 | - public void setRole(String value) | |
643 | - { | |
609 | + public void setRole(String value) { | |
644 | 610 | this.role = value; |
645 | 611 | } |
612 | + | |
646 | 613 | } |
614 | + | |
647 | 615 | } |
648 | 616 | |
649 | 617 | /** |
... | ... | @@ -674,43 +642,41 @@ public class Issues { |
674 | 642 | * </pre> |
675 | 643 | */ |
676 | 644 | @XmlAccessorType(XmlAccessType.FIELD) |
677 | - @XmlType(name = "", propOrder = {"content"}) | |
645 | + @XmlType(name = "", propOrder = { | |
646 | + "values" | |
647 | + }) | |
678 | 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 | 652 | @XmlAttribute |
685 | 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 | 657 | * <p/> |
690 | 658 | * <p/> |
691 | 659 | * This accessor method returns a reference to the live list, |
692 | 660 | * not a snapshot. Therefore any modification you make to the |
693 | 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 | 663 | * <p/> |
696 | 664 | * <p/> |
697 | 665 | * For example, to add a new item, do as follows: |
698 | 666 | * <pre> |
699 | - * getContent().add(newItem); | |
667 | + * getValues().add(newItem); | |
700 | 668 | * </pre> |
701 | 669 | * <p/> |
702 | 670 | * <p/> |
703 | 671 | * <p/> |
704 | 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 | 685 | * @return possible object is |
720 | 686 | * {@link String } |
721 | 687 | */ |
722 | - public String getName() | |
723 | - { | |
688 | + public String getName() { | |
724 | 689 | return name; |
725 | 690 | } |
726 | 691 | |
... | ... | @@ -730,8 +695,7 @@ public class Issues { |
730 | 695 | * @param value allowed object is |
731 | 696 | * {@link String } |
732 | 697 | */ |
733 | - public void setName(String value) | |
734 | - { | |
698 | + public void setName(String value) { | |
735 | 699 | this.name = value; |
736 | 700 | } |
737 | 701 | |
... | ... | @@ -752,23 +716,45 @@ public class Issues { |
752 | 716 | * </pre> |
753 | 717 | */ |
754 | 718 | @XmlAccessorType(XmlAccessType.FIELD) |
755 | - @XmlType(name = "") | |
719 | + @XmlType(name = "", propOrder = { | |
720 | + "content" | |
721 | + }) | |
756 | 722 | public static class Value { |
757 | 723 | |
724 | + @XmlValue | |
725 | + protected String content; | |
758 | 726 | @XmlAttribute |
759 | 727 | protected String type; |
760 | - | |
761 | 728 | @XmlAttribute |
762 | 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 | 752 | * Gets the value of the type property. |
766 | 753 | * |
767 | 754 | * @return possible object is |
768 | 755 | * {@link String } |
769 | 756 | */ |
770 | - public String getType() | |
771 | - { | |
757 | + public String getType() { | |
772 | 758 | return type; |
773 | 759 | } |
774 | 760 | |
... | ... | @@ -778,8 +764,7 @@ public class Issues { |
778 | 764 | * @param value allowed object is |
779 | 765 | * {@link String } |
780 | 766 | */ |
781 | - public void setType(String value) | |
782 | - { | |
767 | + public void setType(String value) { | |
783 | 768 | this.type = value; |
784 | 769 | } |
785 | 770 | |
... | ... | @@ -789,8 +774,7 @@ public class Issues { |
789 | 774 | * @return possible object is |
790 | 775 | * {@link String } |
791 | 776 | */ |
792 | - public String getRole() | |
793 | - { | |
777 | + public String getRole() { | |
794 | 778 | return role; |
795 | 779 | } |
796 | 780 | |
... | ... | @@ -800,11 +784,14 @@ public class Issues { |
800 | 784 | * @param value allowed object is |
801 | 785 | * {@link String } |
802 | 786 | */ |
803 | - public void setRole(String value) | |
804 | - { | |
787 | + public void setRole(String value) { | |
805 | 788 | this.role = value; |
806 | 789 | } |
790 | + | |
807 | 791 | } |
792 | + | |
808 | 793 | } |
794 | + | |
809 | 795 | } |
796 | + | |
810 | 797 | } | ... | ... |
... | ... | @@ -2,15 +2,12 @@ |
2 | 2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 |
3 | 3 | // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> |
4 | 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 | 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 | 10 | import javax.xml.bind.annotation.XmlRegistry; |
13 | -import javax.xml.namespace.QName; | |
14 | 11 | |
15 | 12 | /** |
16 | 13 | * This object contains factory methods for each |
... | ... | @@ -28,69 +25,52 @@ import javax.xml.namespace.QName; |
28 | 25 | @XmlRegistry |
29 | 26 | public class ObjectFactory { |
30 | 27 | |
31 | - private final static QName _IssuesIssueFieldValue_QNAME = new QName("", "value"); | |
32 | - | |
33 | 28 | /** |
34 | 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 | 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 | 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 | 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 | 45 | return new Issues.Issue.Field(); |
62 | 46 | } |
63 | 47 | |
64 | 48 | /** |
65 | 49 | * Create an instance of {@link Issues } |
66 | 50 | */ |
67 | - public Issues createIssues() | |
68 | - { | |
51 | + public Issues createIssues() { | |
69 | 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 | 1 | package pl.com.it_crowd.youtrack.api.rest; |
2 | 2 | |
3 | 3 | import com.gargoylesoftware.htmlunit.BrowserVersion; |
4 | +import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; | |
4 | 5 | import com.gargoylesoftware.htmlunit.HttpMethod; |
5 | 6 | import com.gargoylesoftware.htmlunit.Page; |
6 | 7 | import com.gargoylesoftware.htmlunit.WebClient; |
7 | 8 | import com.gargoylesoftware.htmlunit.WebRequest; |
8 | 9 | import com.gargoylesoftware.htmlunit.WebResponse; |
10 | +import com.gargoylesoftware.htmlunit.html.DomNode; | |
9 | 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 | 15 | import pl.com.it_crowd.youtrack.api.IssuesUnmarshaller; |
11 | 16 | |
12 | 17 | import javax.xml.bind.JAXBException; |
13 | 18 | import java.io.IOException; |
14 | 19 | import java.net.URL; |
15 | 20 | import java.util.ArrayList; |
21 | +import java.util.List; | |
16 | 22 | |
17 | 23 | public class YoutrackAPI { |
24 | +// ------------------------------ FIELDS ------------------------------ | |
18 | 25 | |
19 | 26 | private String serviceLocation; |
20 | 27 | |
21 | 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 | 33 | this.serviceLocation = serviceLocation; |
31 | 34 | this.webClient = new WebClient(BrowserVersion.FIREFOX_3_6); |
32 | 35 | this.webClient.setJavaScriptEnabled(false); |
33 | 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 | 40 | this(serviceLocation); |
39 | 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 | 53 | ArrayList<NameValuePair> requestParameters = new ArrayList<NameValuePair>(); |
45 | 54 | requestParameters.add(new NameValuePair("login", username)); |
46 | 55 | requestParameters.add(new NameValuePair("password", password)); |
47 | 56 | WebRequest request = new WebRequest(new URL(serviceLocation + "/rest/user/login"), HttpMethod.POST); |
48 | 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 | 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 | } | ... | ... |
src/main/xjb/bindings.xjb
0 → 100644
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> | |
\ No newline at end of file | ... | ... |
1 | 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 | 3 | <xs:element name="issues"> |
4 | 4 | <xs:complexType> |
5 | 5 | <xs:sequence> |
... | ... | @@ -7,10 +7,10 @@ |
7 | 7 | <xs:complexType> |
8 | 8 | <xs:choice maxOccurs="unbounded" minOccurs="0"> |
9 | 9 | <xs:element name="field"> |
10 | - <xs:complexType mixed="true"> | |
10 | + <xs:complexType> | |
11 | 11 | <xs:sequence> |
12 | 12 | <xs:element name="value" maxOccurs="unbounded" minOccurs="0"> |
13 | - <xs:complexType> | |
13 | + <xs:complexType mixed="true"> | |
14 | 14 | <xs:attribute type="xs:string" name="type" use="optional"/> |
15 | 15 | <xs:attribute type="xs:string" name="role" use="optional"/> |
16 | 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