|
52 | 52 | import static org.hamcrest.CoreMatchers.nullValue;
|
53 | 53 | import static org.hamcrest.Matchers.greaterThan;
|
54 | 54 | import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
| 55 | +import static org.hamcrest.core.StringContains.containsString; |
55 | 56 | import static org.junit.Assert.assertEquals;
|
56 | 57 | import static org.junit.Assert.assertNotEquals;
|
57 | 58 | import static org.junit.Assert.assertNotNull;
|
@@ -1106,4 +1107,54 @@ public void createTicketForm() throws Exception {
|
1106 | 1107 | assertEquals(givenName, createdForm.getRawName());
|
1107 | 1108 | assertEquals(givenName, createdForm.getRawDisplayName());
|
1108 | 1109 | }
|
| 1110 | + |
| 1111 | + @Test |
| 1112 | + public void getTicketCommentsShouldBeAscending() throws Exception { |
| 1113 | + createClientWithTokenOrPassword(); |
| 1114 | + |
| 1115 | + Ticket t = new Ticket( |
| 1116 | + new Ticket.Requester(config.getProperty("requester.name"), config.getProperty("requester.email")), |
| 1117 | + "This is an automated test ticket", new Comment("1")); |
| 1118 | + Ticket ticket = null; |
| 1119 | + try { |
| 1120 | + ticket = instance.createTicket(t); |
| 1121 | + instance.createComment(ticket.getId(), new Comment("2")); |
| 1122 | + Iterable<Comment> ticketCommentsIt = instance.getTicketComments(ticket.getId()); |
| 1123 | + List<Comment> comments = new ArrayList<>(); |
| 1124 | + ticketCommentsIt.forEach(comments::add); |
| 1125 | + |
| 1126 | + assertThat(comments.size(), is(2)); |
| 1127 | + assertThat(comments.get(0).getBody(), containsString("1")); |
| 1128 | + assertThat(comments.get(1).getBody(), containsString("2")); |
| 1129 | + } finally { |
| 1130 | + if (ticket != null) { |
| 1131 | + instance.deleteTicket(ticket.getId()); |
| 1132 | + } |
| 1133 | + } |
| 1134 | + } |
| 1135 | + |
| 1136 | + @Test |
| 1137 | + public void getTicketCommentsDescending() throws Exception { |
| 1138 | + createClientWithTokenOrPassword(); |
| 1139 | + |
| 1140 | + Ticket t = new Ticket( |
| 1141 | + new Ticket.Requester(config.getProperty("requester.name"), config.getProperty("requester.email")), |
| 1142 | + "This is an automated test ticket", new Comment("1")); |
| 1143 | + Ticket ticket = null; |
| 1144 | + try { |
| 1145 | + ticket = instance.createTicket(t); |
| 1146 | + instance.createComment(ticket.getId(), new Comment("2")); |
| 1147 | + Iterable<Comment> ticketCommentsIt = instance.getTicketComments(ticket.getId(), SortOrder.DESCENDING); |
| 1148 | + List<Comment> comments = new ArrayList<>(); |
| 1149 | + ticketCommentsIt.forEach(comments::add); |
| 1150 | + |
| 1151 | + assertThat(comments.size(), is(2)); |
| 1152 | + assertThat(comments.get(0).getBody(), containsString("2")); |
| 1153 | + assertThat(comments.get(1).getBody(), containsString("1")); |
| 1154 | + } finally { |
| 1155 | + if (ticket != null) { |
| 1156 | + instance.deleteTicket(ticket.getId()); |
| 1157 | + } |
| 1158 | + } |
| 1159 | + } |
1109 | 1160 | }
|
0 commit comments