Skip to content

Commit

Permalink
Merge pull request #100 from uphold/bugfix/refresh-bearer-token
Browse files Browse the repository at this point in the history
Fix update bearer token issue
  • Loading branch information
SandroMachado authored Dec 14, 2017
2 parents 78139d7 + 68f1470 commit 3fdcd32
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void completeAuthorizationShouldReturnUpholdClientExceptionStateMatchErro
UpholdClient.initialize(new MockSharedPreferencesContext());

String responseString = "{ \"access_token\": \"foo\", \"description\": \"bar\", \"expires\": null }";
MockRestAdapter<AuthenticationResponse> adapter = new MockRestAdapter<>("foobar", responseString, null);
MockRestAdapter<AuthenticationResponse> adapter = new MockRestAdapter<>(responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, AuthenticationResponse>() {
@Override
Expand Down Expand Up @@ -105,7 +105,7 @@ public void completeAuthorizationShouldReturnTheAuthenticationResponse() throws

ByteArrayOutputStream bodyOutput = new ByteArrayOutputStream();
String responseString = "{ \"access_token\": \"foo\", \"token_type\": \"bar\", \"expires_in\": 1234, \"scope\": \"foobar\"}";
MockRestAdapter<AuthenticationResponse> adapter = new MockRestAdapter<>("foobar", responseString, null);
MockRestAdapter<AuthenticationResponse> adapter = new MockRestAdapter<>(responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, AuthenticationResponse>() {
@Override
Expand Down Expand Up @@ -160,7 +160,7 @@ public void getTickersShouldReturnTheListOfRates() throws Exception {
"\"pair\": \"foo\"" +
"}" +
"]";
MockRestAdapter<List<Rate>> adapter = new MockRestAdapter<>("foobar", responseString, null);
MockRestAdapter<List<Rate>> adapter = new MockRestAdapter<>(responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, List<Rate>>() {
@Override
Expand Down Expand Up @@ -219,7 +219,7 @@ public void getTickersByCurrencyShouldReturnTheListOfRates() throws Exception {
"\"pair\": \"foo\"" +
"}" +
"]";
MockRestAdapter<List<Rate>> adapter = new MockRestAdapter<>("foobar", responseString, null);
MockRestAdapter<List<Rate>> adapter = new MockRestAdapter<>(responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, List<Rate>>() {
@Override
Expand Down Expand Up @@ -338,7 +338,7 @@ public void getUserShouldReturnTheUser() throws Exception {
"}" +
"}" +
"}";
MockRestAdapter<User> adapter = new MockRestAdapter<>("foobar", responseString, null);
MockRestAdapter<User> adapter = new MockRestAdapter<>(responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, User>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@
import com.darylteo.rx.promises.java.Promise;
import com.darylteo.rx.promises.java.functions.RepromiseFunction;
import com.uphold.uphold_android_sdk.BuildConfig;
import com.uphold.uphold_android_sdk.client.UpholdClient;
import com.uphold.uphold_android_sdk.client.errorhandling.UpholdRetrofitErrorHandling;
import com.uphold.uphold_android_sdk.client.restadapter.UpholdRestAdapter;
import com.uphold.uphold_android_sdk.client.session.SessionManager;
import com.uphold.uphold_android_sdk.model.Card;
import com.uphold.uphold_android_sdk.model.Token;
import com.uphold.uphold_android_sdk.model.User;
import com.uphold.uphold_android_sdk.test.util.Fixtures;
import com.uphold.uphold_android_sdk.test.util.MockRestAdapter;
import com.uphold.uphold_android_sdk.test.util.MockSharedPreferencesContext;

import junit.framework.Assert;

import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.HashMap;

import retrofit.RestAdapter;
import retrofit.client.Header;
import retrofit.client.Request;
Expand All @@ -35,7 +41,7 @@ public void setAdapterShouldSetTheAdapter() {
UpholdRestAdapter upholdRestAdapter = new UpholdRestAdapter();
RestAdapter adapter = new RestAdapter.Builder().setEndpoint(BuildConfig.API_SERVER_URL)
.setErrorHandler(new UpholdRetrofitErrorHandling())
.setRequestInterceptor(upholdRestAdapter.getUpholdRequestInterceptor("foobar"))
.setRequestInterceptor(upholdRestAdapter.getUpholdRequestInterceptor())
.build();

upholdRestAdapter.setAdapter(adapter);
Expand All @@ -45,7 +51,10 @@ public void setAdapterShouldSetTheAdapter() {

@Test
public void upholdRestAdapterWithTokenShoulSetTheUpholdCustomHeadersWithAuthenticationHeader() throws Exception {
MockRestAdapter<Card> adapter = new MockRestAdapter<>("fuz", null, null);
MockRestAdapter<Card> adapter = new MockRestAdapter<>(null, null);

UpholdClient.initialize(new MockSharedPreferencesContext(new HashMap<String, Object>()));
SessionManager.INSTANCE.setBearerToken(new Token("fuz"));

adapter.request(new RepromiseFunction<UpholdRestAdapter, Card>() {
@Override
Expand All @@ -67,7 +76,7 @@ public Promise<Card> call(UpholdRestAdapter adapter) {

@Test
public void setUpholdRequestInterceptorWithEmptyTokenShouldSetTheUpholdCustomHeadersWithoutAuthenticationHeader() throws Exception {
MockRestAdapter<Card> adapter = new MockRestAdapter<>("", null, null);
MockRestAdapter<Card> adapter = new MockRestAdapter<>(null, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, Card>() {
@Override
Expand All @@ -88,7 +97,7 @@ public Promise<Card> call(UpholdRestAdapter adapter) {

@Test
public void setUpholdRequestInterceptorWithNullTokenShouldSetTheUpholdCustomHeadersWithoutAuthenticationHeader() throws Exception{
MockRestAdapter<Card> adapter = new MockRestAdapter<>(null, null, null);
MockRestAdapter<Card> adapter = new MockRestAdapter<>(null, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, Card>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class CardTest {
@Test
public void createAddressShouldReturnTheAddress() throws Exception {
String responseString = "{ \"id\": \"foobar\", \"network\": \"foobiz\" }";
MockRestAdapter<Address> adapter = new MockRestAdapter<>("foobar", responseString, null);
MockRestAdapter<Address> adapter = new MockRestAdapter<>(responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, Address>() {
@Override
Expand Down Expand Up @@ -143,7 +143,7 @@ public void createTransactionShouldReturnTheTransaction() throws Exception {
"\"percentage\": \"2.75\"" +
"}]" +
"}";
MockRestAdapter<Transaction> adapter = new MockRestAdapter<>("foobar", responseString, null);
MockRestAdapter<Transaction> adapter = new MockRestAdapter<>(responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, Transaction>() {
@Override
Expand Down Expand Up @@ -229,7 +229,7 @@ public Promise<Transaction> call(UpholdRestAdapter adapter) {
@Test
public void createTransactionCardDepositShouldReturnTheTransactionCommitted() throws Exception {
String responseString = "{ \"id\": \"foobar\" }";
MockRestAdapter<Transaction> adapter = new MockRestAdapter<>("foobar", responseString, null);
MockRestAdapter<Transaction> adapter = new MockRestAdapter<>(responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, Transaction>() {
@Override
Expand All @@ -255,7 +255,7 @@ public Promise<Transaction> call(UpholdRestAdapter adapter) {
@Test
public void createTransactionDepositShouldReturnTheTransactionCommitted() throws Exception {
String responseString = "{ \"id\": \"foobar\" }";
MockRestAdapter<Transaction> adapter = new MockRestAdapter<>("foobar", responseString, null);
MockRestAdapter<Transaction> adapter = new MockRestAdapter<>(responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, Transaction>() {
@Override
Expand All @@ -281,7 +281,7 @@ public Promise<Transaction> call(UpholdRestAdapter adapter) {
@Test
public void createTransactionTransferShouldReturnTheTransactionCommitted() throws Exception {
String responseString = "{ \"id\": \"foobar\" }";
MockRestAdapter<Transaction> adapter = new MockRestAdapter<>("foobar", responseString, null);
MockRestAdapter<Transaction> adapter = new MockRestAdapter<>(responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, Transaction>() {
@Override
Expand Down Expand Up @@ -400,7 +400,7 @@ public void getSettingsShouldReturnSettings() {
@Test
public void getTransactionsShouldReturnThePaginatorCount() throws Exception {
String responseString = "[ { \"id\": \"FOOBAR\" }, { \"id\": \"FOOBIZ\" } ]";
MockRestAdapter<Integer> adapter = new MockRestAdapter<>("foobar", responseString, new HashMap<String, String>() {{
MockRestAdapter<Integer> adapter = new MockRestAdapter<>(responseString, new HashMap<String, String>() {{
put("Content-Range", "0-2/60");
}});

Expand Down Expand Up @@ -437,7 +437,7 @@ public Promise<Integer> call(List<Transaction> transactions) {
@Test
public void getTransactionsShouldReturnThePaginatorHasNext() throws Exception {
String responseString = "[ { \"id\": \"FOOBAR\" }, { \"id\": \"FOOBIZ\" } ]";
MockRestAdapter<Boolean> adapter = new MockRestAdapter<>("foobar", responseString, new HashMap<String, String>() {{
MockRestAdapter<Boolean> adapter = new MockRestAdapter<>(responseString, new HashMap<String, String>() {{
put("Content-Range", "0-49/51");
}});

Expand Down Expand Up @@ -474,7 +474,7 @@ public Promise<Boolean> call(List<Transaction> transactions) {
@Test
public void getTransactionsShouldReturnTheListOfTransactions() throws Exception {
String responseString = "[ { \"id\": \"FOOBAR\" }, { \"id\": \"FOOBIZ\" } ]";
MockRestAdapter<List<Transaction>> adapter = new MockRestAdapter<>("foobar", responseString, null);
MockRestAdapter<List<Transaction>> adapter = new MockRestAdapter<>(responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, List<Transaction>>() {
@Override
Expand Down Expand Up @@ -511,7 +511,7 @@ public Promise<List<Transaction>> call(List<Transaction> transactions) {
@Test
public void getTransactionsShouldReturnThePaginatorNextPage() throws Exception {
String responseString = "[ { \"id\": \"FOOBAR\" }, { \"id\": \"FOOBIZ\" } ]";
MockRestAdapter<List<Transaction>> adapter = new MockRestAdapter<>("foobar", responseString, null);
MockRestAdapter<List<Transaction>> adapter = new MockRestAdapter<>(responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, List<Transaction>>() {
@Override
Expand Down Expand Up @@ -544,7 +544,7 @@ public Promise<List<Transaction>> call(List<Transaction> transactions) {
@Test
public void updateShouldReturnPromiseWithCard() throws Exception {
String responseString = "{ \"id\": \"FOOBAR\" }";
MockRestAdapter<Card> adapter = new MockRestAdapter<>("foobar", responseString, null);
MockRestAdapter<Card> adapter = new MockRestAdapter<>(responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, Card>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ReserveTest {
@Test
public void getLedgerShouldReturnThePaginatorCount() throws Exception {
String responseString = "[ { \"type\": \"asset\" }, { \"type\": \"liability\" } ]";
MockRestAdapter<Integer> adapter = new MockRestAdapter<>("foobar", responseString, new HashMap<String, String>() {{
MockRestAdapter<Integer> adapter = new MockRestAdapter<>(responseString, new HashMap<String, String>() {{
put("Content-Range", "0-2/60");
}});

Expand Down Expand Up @@ -71,7 +71,7 @@ public Promise<Integer> call(List<Deposit> transactions) {
@Test
public void getLedgerShouldReturnThePaginatorHasNext() throws Exception {
String responseString = "[ { \"type\": \"asset\" }, { \"type\": \"liability\" } ]";
MockRestAdapter<Boolean> adapter = new MockRestAdapter<>("foobar", responseString, new HashMap<String, String>() {{
MockRestAdapter<Boolean> adapter = new MockRestAdapter<>(responseString, new HashMap<String, String>() {{
put("Content-Range", "0-49/51");
}});

Expand Down Expand Up @@ -129,7 +129,7 @@ public void getLedgerShouldReturnTheListWithDeposits() throws Exception {
"\"TransactionId\": \"foobar\"," +
"\"createdAt\": \"2015-04-20T14:57:12.398Z\"" +
"}]";
MockRestAdapter<List<Deposit>> adapter = new MockRestAdapter<>("foobar", responseString, null);
MockRestAdapter<List<Deposit>> adapter = new MockRestAdapter<>(responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, List<Deposit>>() {
@Override
Expand Down Expand Up @@ -176,7 +176,7 @@ public Promise<List<Deposit>> call(List<Deposit> transactions) {
@Test
public void getLedgerShouldReturnThePaginatorNextPage() throws Exception {
String responseString = "[ { \"type\": \"asset\" }, { \"type\": \"liability\" } ]";
MockRestAdapter<List<Deposit>> adapter = new MockRestAdapter<>("foobar", responseString, null);
MockRestAdapter<List<Deposit>> adapter = new MockRestAdapter<>(responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, List<Deposit>>() {
@Override
Expand Down Expand Up @@ -235,7 +235,7 @@ public void getStatisticsShouldReturnTheListWithReserveStatistics() throws Excep
"\"liabilities\": \"buz\"" +
"}" +
"}]";
MockRestAdapter<List<ReserveStatistics>> adapter = new MockRestAdapter<>("foobar", responseString, null);
MockRestAdapter<List<ReserveStatistics>> adapter = new MockRestAdapter<>(responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, List<ReserveStatistics>>() {
@Override
Expand Down Expand Up @@ -279,7 +279,7 @@ public Promise<List<ReserveStatistics>> call(UpholdRestAdapter adapter) {
@Test
public void getTransactionsByIdShouldReturnTheTransaction() throws Exception {
String responseString = "{ \"id\": \"FOOBAR\" }";
MockRestAdapter<Transaction> adapter = new MockRestAdapter<>("foobar", responseString, null);
MockRestAdapter<Transaction> adapter = new MockRestAdapter<>(responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, Transaction>() {
@Override
Expand All @@ -303,7 +303,7 @@ public Promise<Transaction> call(UpholdRestAdapter adapter) {
@Test
public void getTransactionsShouldReturnThePaginatorCount() throws Exception {
String responseString = "[ { \"id\": \"FOOBAR\" }, { \"id\": \"FOOBIZ\" } ]";
MockRestAdapter<Integer> adapter = new MockRestAdapter<>("foobar", responseString, new HashMap<String, String>() {{
MockRestAdapter<Integer> adapter = new MockRestAdapter<>(responseString, new HashMap<String, String>() {{
put("Content-Range", "0-2/60");
}});

Expand Down Expand Up @@ -338,7 +338,7 @@ public Promise<Integer> call(List<Transaction> transactions) {
@Test
public void getTransactionsShouldReturnThePaginatorHasNext() throws Exception {
String responseString = "[ { \"id\": \"FOOBAR\" }, { \"id\": \"FOOBIZ\" } ]";
MockRestAdapter<Boolean> adapter = new MockRestAdapter<>("foobar", responseString, new HashMap<String, String>() {{
MockRestAdapter<Boolean> adapter = new MockRestAdapter<>(responseString, new HashMap<String, String>() {{
put("Content-Range", "0-49/51");
}});

Expand Down Expand Up @@ -373,7 +373,7 @@ public Promise<Boolean> call(List<Transaction> transactions) {
@Test
public void getTransactionsShouldReturnTheListOfTransactions() throws Exception {
String responseString = "[ { \"id\": \"FOOBAR\" }, { \"id\": \"FOOBIZ\" } ]";
MockRestAdapter<List<Transaction>> adapter = new MockRestAdapter<>("foobar", responseString, null);
MockRestAdapter<List<Transaction>> adapter = new MockRestAdapter<>(responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, List<Transaction>>() {
@Override
Expand Down Expand Up @@ -408,7 +408,7 @@ public Promise<List<Transaction>> call(List<Transaction> transactions) {
@Test
public void getTransactionsShouldReturnThePaginatorNextPage() throws Exception {
String responseString = "[ { \"id\": \"FOOBAR\" }, { \"id\": \"FOOBIZ\" } ]";
MockRestAdapter<List<Transaction>> adapter = new MockRestAdapter<>("foobar", responseString, null);
MockRestAdapter<List<Transaction>> adapter = new MockRestAdapter<>(responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, List<Transaction>>() {
@Override
Expand Down
Loading

0 comments on commit 3fdcd32

Please sign in to comment.