Skip to content

Commit

Permalink
Merge pull request #86 from tradingticket/gd/account_capabilities/153…
Browse files Browse the repository at this point in the history
…521995

Gd/account capabilities/153521995
  • Loading branch information
mitochondrion authored Dec 11, 2017
2 parents bf516fb + 3ba0ab9 commit d85fa62
Show file tree
Hide file tree
Showing 14 changed files with 346 additions and 178 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:1.1.0'
Expand All @@ -19,6 +20,7 @@ allprojects {
repositories {
jcenter()
mavenLocal() // to be able to use local snapshot
google()
}
}

Expand Down
2 changes: 1 addition & 1 deletion exampleApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion '25.0.2'
buildToolsVersion '26.0.2'

lintOptions {
disable 'InvalidPackage'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,6 @@ public void onClick(View view) {
Log.d(TAG, "Authenticate all linked brokers tapped!");
authenticateAllLinkedBrokers();
break;
case AUTHENTICATE_WITH_SECURITY_QUESTION_SIMPLE:
Log.d(TAG, "Simple security question was tapped!");
authenticateWithSimpleSecurityQuestion();
break;
case AUTHENTICATE_WITH_SECURITY_QUESTION_OPTIONS:
Log.d(TAG, "Security question with options was tapped!");
authenticateWithSecurityQuestionOptions();
break;
case REFRESH_ALL_BALANCES_FIRST_LINKED_BROKER:
Log.d(TAG, "Refresh all balances for first linked broker was tapped!");
refreshAllBalancesFirstLinkedBroker();
Expand Down Expand Up @@ -334,71 +326,6 @@ public void onError(TradeItErrorResult error) {
}
}

private void authenticateWithSimpleSecurityQuestion() {
authenticateWithSecurityQuestion("dummySecurity");
}

private void authenticateWithSecurityQuestionOptions() {
authenticateWithSecurityQuestion("dummyOption");
}

private void authenticateWithSecurityQuestion(String dummySecurityQuestionLogin) {
final MainActivity mainActivity = this;
final String dummyLogin = dummySecurityQuestionLogin;
linkedBrokerManager.linkBroker(dummyLogin, "Dummy", dummyLogin, "dummy", new TradeItCallback<TradeItLinkedBrokerParcelable>() {
@Override
public void onSuccess(final TradeItLinkedBrokerParcelable linkedBroker) {
linkedBroker.authenticate(new TradeItCallbackWithSecurityQuestionImpl<List<TradeItLinkedBrokerAccountParcelable>>() {
@Override
public void onSuccess(final List<TradeItLinkedBrokerAccountParcelable> accounts) {
showAlert("Dummy security", "Successfully Authenticate " + dummyLogin);
linkedBrokerManager.unlinkBroker(linkedBroker, new TradeItCallback() {
@Override
public void onSuccess(Object type) {
Log.d(TAG, "unlinking successfully " + dummyLogin);
}

@Override
public void onError(TradeItErrorResult error) {
Log.e(TAG, "ERROR unlinking " + dummyLogin);
}
});
}

@Override
public void onSecurityQuestion(TradeItSecurityQuestion securityQuestion) {
final EditText input = new EditText(mainActivity);
final TradeItCallbackWithSecurityQuestionImpl securityQuestionImpl = this;
showSecurityQuestion(securityQuestion, input,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
securityQuestionImpl.submitSecurityAnswer(input.getText().toString());
}
},
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
securityQuestionImpl.cancelSecurityQuestion();
}
}
);
}

@Override
public void onError(TradeItErrorResult error) {
showAlert("authenticate " + dummyLogin, "Error authenticating: " + error);
}
});
}

@Override
public void onError(TradeItErrorResult error) {
showAlert("authenticate " + dummyLogin, "Error linking " + dummyLogin + ": " + error);
}
});
}

private void parcelFirstLinkedBrokerAccount() {
final MainActivity mainActivity = this;
List<TradeItLinkedBrokerParcelable> linkedBrokers = linkedBrokerManager.getLinkedBrokers();
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Apr 06 19:53:47 EDT 2017
#Fri Dec 08 15:52:06 EST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
2 changes: 1 addition & 1 deletion tradeit-android-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ext {

android {
compileSdkVersion 23
buildToolsVersion '25.0.2'
buildToolsVersion '26.0.2'

lintOptions {
abortOnError false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,6 @@ public void onError(TradeItErrorResult error) {
assertThat("The call to getAvailableBrokers is not expired", notExpired, is(true));
}

// @Test TODO This should be tested in the UI tests if possible
// public void testCacheIsCorrect() throws InterruptedException {
// linkBrokerOldMethodAndAuthenticationAndRefreshBalanceAndPositions();
// List<TradeItLinkedBrokerParcelable> linkedBrokers = linkedBrokerManager.getLinkedBrokers();
// List<TradeItLinkedBrokerAccountParcelable> accounts = linkedBrokers.get(0).getAccounts();
// TradeItLinkedBrokerAccountParcelable account = accounts.get(0);
//
// //reset to reload from cache
// createTradeItLinkedBrokerManager();
//
// List<TradeItLinkedBrokerParcelable> linkedBrokerParcelables = linkedBrokerManager.getLinkedBrokers();
// assertThat("The number of linked brokers loaded from cache is correct", linkedBrokerParcelables.size() , is(linkedBrokers.size()));
//
// TradeItLinkedBrokerParcelable linkedBrokerParcelable = linkedBrokerParcelables.get(0);
// assertTrue("The error is set to session expired", linkedBrokerParcelable.isUnauthenticated());
// assertThat("There number of linked broker accounts loaded from cache is correct", linkedBrokerParcelable.getAccounts().size() , is(accounts.size()));
//
// TradeItLinkedBrokerAccountParcelable linkedBrokerAccountParcelable = linkedBrokerParcelable.getAccounts().get(0);
// assertThat("The balance loaded from cache is correct", linkedBrokerAccountParcelable.getBalance() , is(account.getBalance()));
// assertThat("The fx balance loaded from cache is correct", linkedBrokerAccountParcelable.getFxBalance() , is(account.getFxBalance()));
// }

@Test
public void getOAuthLoginPopupUrlForMobile() throws InterruptedException {
linkedBrokerManager.getOAuthLoginPopupUrl("Dummy", "myinternalappcallback", new TradeItCallback<String>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
import org.junit.runner.RunWith;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import it.trade.android.sdk.TradeItConfigurationBuilder;
import it.trade.android.sdk.TradeItSDK;
import it.trade.api.TradeItApiClient;
import it.trade.model.reponse.DisplayLabelValue;
import it.trade.model.reponse.Instrument;
import it.trade.model.reponse.OrderCapability;
import it.trade.model.reponse.TradeItBrokerAccount;
import it.trade.model.reponse.TradeItOAuthAccessTokenResponse;
import it.trade.model.request.TradeItEnvironment;
Expand Down Expand Up @@ -54,6 +58,13 @@ public void createTradeItLinkedBrokerAccount() {
account.accountBaseCurrency = "MyAccountBaseCurrency";
account.name = "MyAccountName";
account.userCanDisableMargin = true;

OrderCapability orderCapability = new OrderCapability();
DisplayLabelValue action = new DisplayLabelValue("Buy", "buy");
orderCapability.actions = Arrays.asList(action);
orderCapability.setInstrument(Instrument.EQUITIES);
account.orderCapabilities = Arrays.asList(orderCapability);

linkedBrokerAccount = new TradeItLinkedBrokerAccountParcelable(linkedBroker, account);
}

Expand Down Expand Up @@ -94,6 +105,9 @@ public void linkedBrokerAccount_ParcelableWriteRead() {
boolean userCanDisableMargin = createdFromParcel.userCanDisableMargin;
TradeItBalanceParcelable createdBalance = createdFromParcel.getBalance();
List<TradeItPositionParcelable> createdPositions = createdFromParcel.getPositions();
List<TradeItOrderCapabilityParcelable> orderCapabilities = createdFromParcel.orderCapabilities;

DisplayLabelValueParcelable displayLabelValueParcelable = orderCapabilities.get(0).getActions().get(0);

// Verify that the received data is correct.
assertThat(apiClient, notNullValue());
Expand All @@ -106,5 +120,8 @@ public void linkedBrokerAccount_ParcelableWriteRead() {

assertThat(createdBalance, is(balance));
assertThat(createdPositions, is(positions));
assertThat(orderCapabilities.isEmpty(), is(false));
assertThat(displayLabelValueParcelable.getDisplayLabel(), is("Buy"));
assertThat(displayLabelValueParcelable.getValue(), is("buy"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package it.trade.android.sdk.model;

import android.os.Parcel;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;

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

import java.util.Arrays;
import java.util.List;

import it.trade.model.reponse.DisplayLabelValue;
import it.trade.model.reponse.Instrument;
import it.trade.model.reponse.OrderCapability;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;

@RunWith(AndroidJUnit4.class)
@SmallTest
public class TradeItOrderCapabilityParcelableTest {

private TradeItOrderCapabilityParcelable orderCapabilityParcelable;
private DisplayLabelValue action;
private DisplayLabelValue priceType;
private DisplayLabelValue expirationType;

@Before
public void createTradeItOrderCapabilityParcelable() {
OrderCapability orderCapability = new OrderCapability();
action = new DisplayLabelValue("Buy", "buy");
priceType = new DisplayLabelValue("Market", "market");
expirationType = new DisplayLabelValue("Good for day", "day");
orderCapability.setInstrument(Instrument.EQUITIES);
orderCapability.actions = Arrays.asList(action);
orderCapability.priceTypes = Arrays.asList(priceType);
orderCapability.expirationTypes = Arrays.asList(expirationType);
orderCapabilityParcelable = new TradeItOrderCapabilityParcelable(orderCapability);
}

@Test
public void orderCapabilities_ParcelableWriteRead() {


// Write the data.
Parcel parcel = Parcel.obtain();
orderCapabilityParcelable.writeToParcel(parcel, orderCapabilityParcelable.describeContents());

// After you're done with writing, you need to reset the parcel for reading.
parcel.setDataPosition(0);

// Read the data.
TradeItOrderCapabilityParcelable createdFromParcel = TradeItOrderCapabilityParcelable.CREATOR.createFromParcel(parcel);
Instrument instrument = createdFromParcel.getInstrument();
List<DisplayLabelValueParcelable> actions = createdFromParcel.getActions();
List<DisplayLabelValueParcelable> expirationTypes = createdFromParcel.getExpirationTypes();
List<DisplayLabelValueParcelable> priceTypes = createdFromParcel.getPriceTypes();

// Verify that the received data is correct.
assertThat(instrument, is(Instrument.EQUITIES));
assertFalse(actions.isEmpty());
assertThat(actions.get(0).getValue(), is(action.value));
assertThat(actions.get(0).getDisplayLabel(), is(action.displayLabel));
assertFalse(expirationTypes.isEmpty());
assertThat(expirationTypes.get(0).getValue(), is(expirationType.value));
assertThat(expirationTypes.get(0).getDisplayLabel(), is(expirationType.displayLabel));
assertFalse(priceTypes.isEmpty());
assertThat(priceTypes.get(0).getValue(), is(priceType.value));
assertThat(priceTypes.get(0).getDisplayLabel(), is(priceType.displayLabel));

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package it.trade.android.sdk.model;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.ArrayList;
import java.util.List;

import it.trade.model.reponse.DisplayLabelValue;

public class DisplayLabelValueParcelable implements Parcelable {

private String displayLabel;
private String value;


public DisplayLabelValueParcelable(DisplayLabelValue displayLabelValue) {
this.displayLabel = displayLabelValue.displayLabel;
this.value = displayLabelValue.value;
}

public static List<DisplayLabelValueParcelable> mapDisplayLabelValuesToDisplayLabelValueParcelables(List<DisplayLabelValue> displayLabelValues) {
List<DisplayLabelValueParcelable> displayLabelValueParcelables = new ArrayList<>();
if (displayLabelValues != null) {
for (DisplayLabelValue displayLabelValue: displayLabelValues) {
displayLabelValueParcelables.add(new DisplayLabelValueParcelable(displayLabelValue));
}
}
return displayLabelValueParcelables;
}

@Override
public String toString() {
return "DisplayLabelValueParcelable{" +
"displayLabel='" + displayLabel + '\'' +
", value='" + value + '\'' +
'}';
}

public String getDisplayLabel() {
return displayLabel;
}

public String getValue() {
return value;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

DisplayLabelValueParcelable that = (DisplayLabelValueParcelable) o;

if (displayLabel != null ? !displayLabel.equals(that.displayLabel) : that.displayLabel != null)
return false;
return value != null ? value.equals(that.value) : that.value == null;
}

@Override
public int hashCode() {
int result = displayLabel != null ? displayLabel.hashCode() : 0;
result = 31 * result + (value != null ? value.hashCode() : 0);
return result;
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.displayLabel);
dest.writeString(this.value);
}

protected DisplayLabelValueParcelable(Parcel in) {
this.displayLabel = in.readString();
this.value = in.readString();
}

public static final Parcelable.Creator<DisplayLabelValueParcelable> CREATOR = new Parcelable.Creator<DisplayLabelValueParcelable>() {
@Override
public DisplayLabelValueParcelable createFromParcel(Parcel source) {
return new DisplayLabelValueParcelable(source);
}

@Override
public DisplayLabelValueParcelable[] newArray(int size) {
return new DisplayLabelValueParcelable[size];
}
};
}
Loading

0 comments on commit d85fa62

Please sign in to comment.