|
| 1 | +package org.whispersystems.bithub.tests.controllers; |
| 2 | + |
| 3 | +import static com.yammer.dropwizard.testing.JsonHelpers.fromJson; |
| 4 | +import static com.yammer.dropwizard.testing.JsonHelpers.jsonFixture; |
| 5 | +import static org.fest.assertions.api.Assertions.assertThat; |
| 6 | +import static org.mockito.Mockito.mock; |
| 7 | +import static org.mockito.Mockito.when; |
| 8 | + |
| 9 | +import java.math.BigDecimal; |
| 10 | + |
| 11 | +import javax.ws.rs.core.MediaType; |
| 12 | + |
| 13 | +import org.junit.Test; |
| 14 | +import org.whispersystems.bithub.client.CoinbaseClient; |
| 15 | +import org.whispersystems.bithub.controllers.StatusController; |
| 16 | +import org.whispersystems.bithub.entities.RecentTransactionsResponse; |
| 17 | + |
| 18 | +import com.sun.jersey.api.client.ClientResponse; |
| 19 | +import com.yammer.dropwizard.testing.ResourceTest; |
| 20 | +import com.yammer.dropwizard.views.ViewMessageBodyWriter; |
| 21 | + |
| 22 | +public class StatusControllerTest extends ResourceTest { |
| 23 | + |
| 24 | + private static final BigDecimal PAYOUT_RATE = new BigDecimal(0.02); |
| 25 | + private static final BigDecimal BALANCE = new BigDecimal(10.01); |
| 26 | + private static final BigDecimal EXCHANGE_RATE = new BigDecimal(1.0); |
| 27 | + |
| 28 | + private final CoinbaseClient coinbaseClient = mock(CoinbaseClient.class); |
| 29 | + |
| 30 | + @Override |
| 31 | + protected void setUpResources() throws Exception { |
| 32 | + |
| 33 | + when(coinbaseClient.getRecentTransactions()).thenReturn(fromJson(jsonFixture("payloads/transactions.json"), RecentTransactionsResponse.class).getTransactions()); |
| 34 | + when(coinbaseClient.getAccountBalance()).thenReturn(BALANCE); |
| 35 | + when(coinbaseClient.getExchangeRate()).thenReturn(EXCHANGE_RATE); |
| 36 | + addResource(new StatusController(coinbaseClient, PAYOUT_RATE)); |
| 37 | + |
| 38 | + addProvider(ViewMessageBodyWriter.class); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void testTransactionsHtml() throws Exception { |
| 43 | + ClientResponse response = client().resource("/v1/status/transactions/") |
| 44 | + .get(ClientResponse.class); |
| 45 | + |
| 46 | + assertThat(response.getStatus()).isEqualTo(200); |
| 47 | + assertThat(response.getType()).isEqualTo(MediaType.TEXT_HTML_TYPE); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void testTransactionsJson() throws Exception { |
| 52 | + ClientResponse response = client().resource("/v1/status/transactions/").queryParam("format", "json") |
| 53 | + .get(ClientResponse.class); |
| 54 | + |
| 55 | + assertThat(response.getStatus()).isEqualTo(200); |
| 56 | + assertThat(response.getType()).isEqualTo(MediaType.APPLICATION_JSON_TYPE); |
| 57 | + } |
| 58 | + |
| 59 | +} |
0 commit comments