-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate test suite to end-to-end tests (#35)
* Fix interaction between assertions and server thread We can't throw assertion errors without affecting the server's stability, which means we need to move the expectations outside the stubbing of the fixtures. This commit does all changes necessary and adapts all tests by first setting the server's behavior and then providing means to ask about what's happened. Everything related to the expected request that the API should have done is made through a new object of type RecordedRequest that the server provides. Everything related to the response must be tested through the actual output of the client call, which supports the idea of these tests being end-to-end.
- Loading branch information
Showing
151 changed files
with
1,921 additions
and
2,380 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,30 @@ | ||
package com.dnsimple; | ||
|
||
import static com.dnsimple.tools.HttpMethod.GET; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import com.dnsimple.data.Account; | ||
import com.dnsimple.response.ListAccountsResponse; | ||
import com.dnsimple.exception.DnsimpleException; | ||
|
||
import com.dnsimple.response.ListAccountsResponse; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.junit.Test; | ||
|
||
import com.google.api.client.http.HttpHeaders; | ||
import com.google.api.client.http.HttpMethods; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class AccountsTest extends DnsimpleTestBase { | ||
|
||
@Test | ||
public void testListAccounts() throws DnsimpleException, IOException { | ||
Client client = mockAndExpectClient("https://api.dnsimple.com/v2/accounts", HttpMethods.GET, resource("listAccounts/success-account.http")); | ||
server.stubFixtureAt("listAccounts/success-account.http"); | ||
|
||
ListAccountsResponse response = client.accounts.listAccounts(); | ||
assertThat(server.getRecordedRequest().getMethod(), is(GET)); | ||
assertThat(server.getRecordedRequest().getPath(), is("/v2/accounts")); | ||
|
||
List<Account> accounts = response.getData(); | ||
assertEquals(1, accounts.size()); | ||
assertEquals(123, accounts.get(0).getId().intValue()); | ||
assertThat(accounts, hasSize(1)); | ||
assertThat(accounts.get(0).getId(), is(1324)); | ||
} | ||
|
||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,37 @@ | ||
package com.dnsimple; | ||
|
||
import com.dnsimple.exception.DnsimpleException; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import com.google.api.client.http.HttpHeaders; | ||
import com.google.api.client.http.HttpMethods; | ||
import static com.dnsimple.tools.HttpMethod.*; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.hasEntry; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import com.dnsimple.exception.DnsimpleException; | ||
import com.dnsimple.tools.HttpMethod; | ||
import java.io.IOException; | ||
import org.junit.Test; | ||
|
||
public class ClientTest extends DnsimpleTestBase { | ||
@Test | ||
public void testNewClient() { | ||
Client client = new Client(); | ||
} | ||
private static final String TEST_ACCESS_TOKEN = "test-access-token"; | ||
|
||
@Test | ||
public void testAuthorizationHeader() throws DnsimpleException, IOException { | ||
HttpHeaders headers = getDefaultHeaders(); | ||
headers.setAuthorization("Bearer " + TEST_ACCESS_TOKEN); | ||
server.stubFixtureAt("listAccounts/success-account.http"); | ||
client.setAccessToken(TEST_ACCESS_TOKEN); | ||
|
||
Client client = mockAndExpectClient("https://api.dnsimple.com/v2/accounts", HttpMethods.GET, headers, null, resource("listAccounts/success-account.http")); | ||
client.accounts.listAccounts(); | ||
assertThat(server.getRecordedRequest().getMethod(), is(GET)); | ||
assertThat(server.getRecordedRequest().getPath(), is("/v2/accounts")); | ||
assertThat(server.getRecordedRequest().getHeaders(), hasEntry("Authorization", "Bearer " + TEST_ACCESS_TOKEN)); | ||
} | ||
|
||
@Test | ||
public void testUserAgentHeader() throws DnsimpleException, IOException { | ||
HttpHeaders headers = getDefaultHeaders(); | ||
headers.setUserAgent("my-user-agent dnsimple-java/" + Dnsimple.VERSION + " Google-HTTP-Java-Client/1.35.0 (gzip)"); | ||
|
||
Client client = mockAndExpectClient("https://api.dnsimple.com/v2/accounts", HttpMethods.GET, headers, null, resource("listAccounts/success-account.http")); | ||
server.stubFixtureAt("listAccounts/success-account.http"); | ||
client.setUserAgent("my-user-agent"); | ||
|
||
client.accounts.listAccounts(); | ||
assertThat(server.getRecordedRequest().getMethod(), is(GET)); | ||
assertThat(server.getRecordedRequest().getPath(), is("/v2/accounts")); | ||
assertThat(server.getRecordedRequest().getHeaders(), hasEntry("User-Agent", "my-user-agent dnsimple-java/" + Dnsimple.VERSION + " Google-HTTP-Java-Client/1.35.0 (gzip)")); | ||
} | ||
} |
Oops, something went wrong.