Skip to content

Commit

Permalink
Update some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenc committed Jun 30, 2014
1 parent 79d5d89 commit da1d966
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.zendesk.client.v2;

import java.io.IOException;
import java.text.MessageFormat;

import com.ning.http.client.Response;

Expand All @@ -17,7 +18,7 @@ public ZendeskResponseException(Response resp) throws IOException {
}

public ZendeskResponseException(int statusCode, String statusText, String body) {
super(statusText);
super(MessageFormat.format("HTTP/{0}: {1}", statusCode, statusText));
this.statusCode = statusCode;
this.statusText = statusText;
this.body = body;
Expand Down
40 changes: 35 additions & 5 deletions src/test/java/org/zendesk/client/v2/RealSmokeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
import org.zendesk.client.v2.model.Identity;
import org.zendesk.client.v2.model.Organization;
import org.zendesk.client.v2.model.Request;
import org.zendesk.client.v2.model.Status;
import org.zendesk.client.v2.model.Ticket;
import org.zendesk.client.v2.model.User;
import org.zendesk.client.v2.model.events.Event;

import java.util.Collections;
import java.util.Properties;
import java.util.UUID;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
Expand Down Expand Up @@ -54,7 +56,8 @@ public void assumeHavePassword() {

public void assumeHaveTokenOrPassword() {
assumeThat("We have a username", config.getProperty("username"), notNullValue());
assumeThat("We have a token or password", config.getProperty("token") != null || config.getProperty("password") != null, is(true));
assumeThat("We have a token or password", config.getProperty("token") != null || config.getProperty("password") != null, is(
true));
}

@After
Expand Down Expand Up @@ -124,12 +127,12 @@ public void getRecentTickets() throws Exception {
public void getTicketsById() throws Exception {
createClientWithTokenOrPassword();
long count = 1;
for (Ticket t : instance.getTickets(1, 3, 5)) {
for (Ticket t : instance.getTickets(1, 6, 11)) {
assertThat(t.getSubject(), notNullValue());
assertThat(t.getId(), is(count));
count += 2;
count += 5;
}
assertThat(count, is(7L));
assertThat(count, is(16L));
}

@Test
Expand Down Expand Up @@ -174,7 +177,7 @@ public void createAnonymousClient() {
}

@Test
@Ignore("Don't spam the production zendesk")
@Ignore("Don't spam zendesk")
public void createDeleteTicket() throws Exception {
createClientWithTokenOrPassword();
assumeThat("Must have a requester email", config.getProperty("requester.email"), notNullValue());
Expand All @@ -198,6 +201,33 @@ public void createDeleteTicket() throws Exception {
assertThat(instance.getTicket(ticket.getId()), nullValue());
}

@Test
@Ignore("Don't spam zendesk")
public void createSolveTickets() throws Exception {
createClientWithTokenOrPassword();
assumeThat("Must have a requester email", config.getProperty("requester.email"), notNullValue());
Ticket ticket;
do {
Ticket t = new Ticket(
new Ticket.Requester(config.getProperty("requester.name"), config.getProperty("requester.email")),
"This is a test " + UUID.randomUUID().toString(), new Comment("Please ignore this ticket"));
ticket = instance.createTicket(t);
System.out.println(ticket.getId() + " -> " + ticket.getUrl());
assertThat(ticket.getId(), notNullValue());
Ticket t2 = instance.getTicket(ticket.getId());
assertThat(t2, notNullValue());
assertThat(t2.getId(), is(ticket.getId()));
t2.setAssigneeId(instance.getCurrentUser().getId());
t2.setStatus(Status.CLOSED);
instance.updateTicket(t2);
assertThat(ticket.getSubject(), is(t.getSubject()));
assertThat(ticket.getRequester(), nullValue());
assertThat(ticket.getRequesterId(), notNullValue());
assertThat(ticket.getDescription(), is(t.getComment().getBody()));
assertThat(instance.getTicket(ticket.getId()), notNullValue());
} while (ticket.getId() < 200L); // seed enough data for the paging tests
}

@Test
public void lookupUserByEmail() throws Exception {
createClientWithTokenOrPassword();
Expand Down

0 comments on commit da1d966

Please sign in to comment.