Skip to content

Commit d85fa62

Browse files
Merge pull request #86 from tradingticket/gd/account_capabilities/153521995
Gd/account capabilities/153521995
2 parents bf516fb + 3ba0ab9 commit d85fa62

File tree

14 files changed

+346
-178
lines changed

14 files changed

+346
-178
lines changed

build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
buildscript {
44
repositories {
55
jcenter()
6+
google()
67
}
78
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.3.3'
9+
classpath 'com.android.tools.build:gradle:3.0.0'
910
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1'
1011
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
1112
classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:1.1.0'
@@ -19,6 +20,7 @@ allprojects {
1920
repositories {
2021
jcenter()
2122
mavenLocal() // to be able to use local snapshot
23+
google()
2224
}
2325
}
2426

exampleApp/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
22

33
android {
44
compileSdkVersion 23
5-
buildToolsVersion '25.0.2'
5+
buildToolsVersion '26.0.2'
66

77
lintOptions {
88
disable 'InvalidPackage'

exampleApp/src/main/java/it/trade/android/exampleapp/MainActivity.java

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,6 @@ public void onClick(View view) {
171171
Log.d(TAG, "Authenticate all linked brokers tapped!");
172172
authenticateAllLinkedBrokers();
173173
break;
174-
case AUTHENTICATE_WITH_SECURITY_QUESTION_SIMPLE:
175-
Log.d(TAG, "Simple security question was tapped!");
176-
authenticateWithSimpleSecurityQuestion();
177-
break;
178-
case AUTHENTICATE_WITH_SECURITY_QUESTION_OPTIONS:
179-
Log.d(TAG, "Security question with options was tapped!");
180-
authenticateWithSecurityQuestionOptions();
181-
break;
182174
case REFRESH_ALL_BALANCES_FIRST_LINKED_BROKER:
183175
Log.d(TAG, "Refresh all balances for first linked broker was tapped!");
184176
refreshAllBalancesFirstLinkedBroker();
@@ -334,71 +326,6 @@ public void onError(TradeItErrorResult error) {
334326
}
335327
}
336328

337-
private void authenticateWithSimpleSecurityQuestion() {
338-
authenticateWithSecurityQuestion("dummySecurity");
339-
}
340-
341-
private void authenticateWithSecurityQuestionOptions() {
342-
authenticateWithSecurityQuestion("dummyOption");
343-
}
344-
345-
private void authenticateWithSecurityQuestion(String dummySecurityQuestionLogin) {
346-
final MainActivity mainActivity = this;
347-
final String dummyLogin = dummySecurityQuestionLogin;
348-
linkedBrokerManager.linkBroker(dummyLogin, "Dummy", dummyLogin, "dummy", new TradeItCallback<TradeItLinkedBrokerParcelable>() {
349-
@Override
350-
public void onSuccess(final TradeItLinkedBrokerParcelable linkedBroker) {
351-
linkedBroker.authenticate(new TradeItCallbackWithSecurityQuestionImpl<List<TradeItLinkedBrokerAccountParcelable>>() {
352-
@Override
353-
public void onSuccess(final List<TradeItLinkedBrokerAccountParcelable> accounts) {
354-
showAlert("Dummy security", "Successfully Authenticate " + dummyLogin);
355-
linkedBrokerManager.unlinkBroker(linkedBroker, new TradeItCallback() {
356-
@Override
357-
public void onSuccess(Object type) {
358-
Log.d(TAG, "unlinking successfully " + dummyLogin);
359-
}
360-
361-
@Override
362-
public void onError(TradeItErrorResult error) {
363-
Log.e(TAG, "ERROR unlinking " + dummyLogin);
364-
}
365-
});
366-
}
367-
368-
@Override
369-
public void onSecurityQuestion(TradeItSecurityQuestion securityQuestion) {
370-
final EditText input = new EditText(mainActivity);
371-
final TradeItCallbackWithSecurityQuestionImpl securityQuestionImpl = this;
372-
showSecurityQuestion(securityQuestion, input,
373-
new DialogInterface.OnClickListener() {
374-
@Override
375-
public void onClick(DialogInterface dialog, int which) {
376-
securityQuestionImpl.submitSecurityAnswer(input.getText().toString());
377-
}
378-
},
379-
new DialogInterface.OnClickListener() {
380-
@Override
381-
public void onClick(DialogInterface dialog, int which) {
382-
securityQuestionImpl.cancelSecurityQuestion();
383-
}
384-
}
385-
);
386-
}
387-
388-
@Override
389-
public void onError(TradeItErrorResult error) {
390-
showAlert("authenticate " + dummyLogin, "Error authenticating: " + error);
391-
}
392-
});
393-
}
394-
395-
@Override
396-
public void onError(TradeItErrorResult error) {
397-
showAlert("authenticate " + dummyLogin, "Error linking " + dummyLogin + ": " + error);
398-
}
399-
});
400-
}
401-
402329
private void parcelFirstLinkedBrokerAccount() {
403330
final MainActivity mainActivity = this;
404331
List<TradeItLinkedBrokerParcelable> linkedBrokers = linkedBrokerManager.getLinkedBrokers();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Thu Apr 06 19:53:47 EDT 2017
1+
#Fri Dec 08 15:52:06 EST 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

tradeit-android-sdk/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ext {
2626

2727
android {
2828
compileSdkVersion 23
29-
buildToolsVersion '25.0.2'
29+
buildToolsVersion '26.0.2'
3030

3131
lintOptions {
3232
abortOnError false

tradeit-android-sdk/src/androidTest/java/it/trade/android/sdk/manager/TradeItLinkedBrokerManagerTest.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,28 +75,6 @@ public void onError(TradeItErrorResult error) {
7575
assertThat("The call to getAvailableBrokers is not expired", notExpired, is(true));
7676
}
7777

78-
// @Test TODO This should be tested in the UI tests if possible
79-
// public void testCacheIsCorrect() throws InterruptedException {
80-
// linkBrokerOldMethodAndAuthenticationAndRefreshBalanceAndPositions();
81-
// List<TradeItLinkedBrokerParcelable> linkedBrokers = linkedBrokerManager.getLinkedBrokers();
82-
// List<TradeItLinkedBrokerAccountParcelable> accounts = linkedBrokers.get(0).getAccounts();
83-
// TradeItLinkedBrokerAccountParcelable account = accounts.get(0);
84-
//
85-
// //reset to reload from cache
86-
// createTradeItLinkedBrokerManager();
87-
//
88-
// List<TradeItLinkedBrokerParcelable> linkedBrokerParcelables = linkedBrokerManager.getLinkedBrokers();
89-
// assertThat("The number of linked brokers loaded from cache is correct", linkedBrokerParcelables.size() , is(linkedBrokers.size()));
90-
//
91-
// TradeItLinkedBrokerParcelable linkedBrokerParcelable = linkedBrokerParcelables.get(0);
92-
// assertTrue("The error is set to session expired", linkedBrokerParcelable.isUnauthenticated());
93-
// assertThat("There number of linked broker accounts loaded from cache is correct", linkedBrokerParcelable.getAccounts().size() , is(accounts.size()));
94-
//
95-
// TradeItLinkedBrokerAccountParcelable linkedBrokerAccountParcelable = linkedBrokerParcelable.getAccounts().get(0);
96-
// assertThat("The balance loaded from cache is correct", linkedBrokerAccountParcelable.getBalance() , is(account.getBalance()));
97-
// assertThat("The fx balance loaded from cache is correct", linkedBrokerAccountParcelable.getFxBalance() , is(account.getFxBalance()));
98-
// }
99-
10078
@Test
10179
public void getOAuthLoginPopupUrlForMobile() throws InterruptedException {
10280
linkedBrokerManager.getOAuthLoginPopupUrl("Dummy", "myinternalappcallback", new TradeItCallback<String>() {

tradeit-android-sdk/src/androidTest/java/it/trade/android/sdk/model/TradeItLinkedBrokerAccountParcelableTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111
import org.junit.runner.RunWith;
1212

1313
import java.util.ArrayList;
14+
import java.util.Arrays;
1415
import java.util.List;
1516

1617
import it.trade.android.sdk.TradeItConfigurationBuilder;
1718
import it.trade.android.sdk.TradeItSDK;
1819
import it.trade.api.TradeItApiClient;
20+
import it.trade.model.reponse.DisplayLabelValue;
21+
import it.trade.model.reponse.Instrument;
22+
import it.trade.model.reponse.OrderCapability;
1923
import it.trade.model.reponse.TradeItBrokerAccount;
2024
import it.trade.model.reponse.TradeItOAuthAccessTokenResponse;
2125
import it.trade.model.request.TradeItEnvironment;
@@ -54,6 +58,13 @@ public void createTradeItLinkedBrokerAccount() {
5458
account.accountBaseCurrency = "MyAccountBaseCurrency";
5559
account.name = "MyAccountName";
5660
account.userCanDisableMargin = true;
61+
62+
OrderCapability orderCapability = new OrderCapability();
63+
DisplayLabelValue action = new DisplayLabelValue("Buy", "buy");
64+
orderCapability.actions = Arrays.asList(action);
65+
orderCapability.setInstrument(Instrument.EQUITIES);
66+
account.orderCapabilities = Arrays.asList(orderCapability);
67+
5768
linkedBrokerAccount = new TradeItLinkedBrokerAccountParcelable(linkedBroker, account);
5869
}
5970

@@ -94,6 +105,9 @@ public void linkedBrokerAccount_ParcelableWriteRead() {
94105
boolean userCanDisableMargin = createdFromParcel.userCanDisableMargin;
95106
TradeItBalanceParcelable createdBalance = createdFromParcel.getBalance();
96107
List<TradeItPositionParcelable> createdPositions = createdFromParcel.getPositions();
108+
List<TradeItOrderCapabilityParcelable> orderCapabilities = createdFromParcel.orderCapabilities;
109+
110+
DisplayLabelValueParcelable displayLabelValueParcelable = orderCapabilities.get(0).getActions().get(0);
97111

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

107121
assertThat(createdBalance, is(balance));
108122
assertThat(createdPositions, is(positions));
123+
assertThat(orderCapabilities.isEmpty(), is(false));
124+
assertThat(displayLabelValueParcelable.getDisplayLabel(), is("Buy"));
125+
assertThat(displayLabelValueParcelable.getValue(), is("buy"));
109126
}
110127
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package it.trade.android.sdk.model;
2+
3+
import android.os.Parcel;
4+
import android.support.test.runner.AndroidJUnit4;
5+
import android.test.suitebuilder.annotation.SmallTest;
6+
7+
import org.junit.Before;
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import java.util.Arrays;
12+
import java.util.List;
13+
14+
import it.trade.model.reponse.DisplayLabelValue;
15+
import it.trade.model.reponse.Instrument;
16+
import it.trade.model.reponse.OrderCapability;
17+
18+
import static org.hamcrest.Matchers.is;
19+
import static org.junit.Assert.assertFalse;
20+
import static org.junit.Assert.assertThat;
21+
22+
@RunWith(AndroidJUnit4.class)
23+
@SmallTest
24+
public class TradeItOrderCapabilityParcelableTest {
25+
26+
private TradeItOrderCapabilityParcelable orderCapabilityParcelable;
27+
private DisplayLabelValue action;
28+
private DisplayLabelValue priceType;
29+
private DisplayLabelValue expirationType;
30+
31+
@Before
32+
public void createTradeItOrderCapabilityParcelable() {
33+
OrderCapability orderCapability = new OrderCapability();
34+
action = new DisplayLabelValue("Buy", "buy");
35+
priceType = new DisplayLabelValue("Market", "market");
36+
expirationType = new DisplayLabelValue("Good for day", "day");
37+
orderCapability.setInstrument(Instrument.EQUITIES);
38+
orderCapability.actions = Arrays.asList(action);
39+
orderCapability.priceTypes = Arrays.asList(priceType);
40+
orderCapability.expirationTypes = Arrays.asList(expirationType);
41+
orderCapabilityParcelable = new TradeItOrderCapabilityParcelable(orderCapability);
42+
}
43+
44+
@Test
45+
public void orderCapabilities_ParcelableWriteRead() {
46+
47+
48+
// Write the data.
49+
Parcel parcel = Parcel.obtain();
50+
orderCapabilityParcelable.writeToParcel(parcel, orderCapabilityParcelable.describeContents());
51+
52+
// After you're done with writing, you need to reset the parcel for reading.
53+
parcel.setDataPosition(0);
54+
55+
// Read the data.
56+
TradeItOrderCapabilityParcelable createdFromParcel = TradeItOrderCapabilityParcelable.CREATOR.createFromParcel(parcel);
57+
Instrument instrument = createdFromParcel.getInstrument();
58+
List<DisplayLabelValueParcelable> actions = createdFromParcel.getActions();
59+
List<DisplayLabelValueParcelable> expirationTypes = createdFromParcel.getExpirationTypes();
60+
List<DisplayLabelValueParcelable> priceTypes = createdFromParcel.getPriceTypes();
61+
62+
// Verify that the received data is correct.
63+
assertThat(instrument, is(Instrument.EQUITIES));
64+
assertFalse(actions.isEmpty());
65+
assertThat(actions.get(0).getValue(), is(action.value));
66+
assertThat(actions.get(0).getDisplayLabel(), is(action.displayLabel));
67+
assertFalse(expirationTypes.isEmpty());
68+
assertThat(expirationTypes.get(0).getValue(), is(expirationType.value));
69+
assertThat(expirationTypes.get(0).getDisplayLabel(), is(expirationType.displayLabel));
70+
assertFalse(priceTypes.isEmpty());
71+
assertThat(priceTypes.get(0).getValue(), is(priceType.value));
72+
assertThat(priceTypes.get(0).getDisplayLabel(), is(priceType.displayLabel));
73+
74+
}
75+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package it.trade.android.sdk.model;
2+
3+
import android.os.Parcel;
4+
import android.os.Parcelable;
5+
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
9+
import it.trade.model.reponse.DisplayLabelValue;
10+
11+
public class DisplayLabelValueParcelable implements Parcelable {
12+
13+
private String displayLabel;
14+
private String value;
15+
16+
17+
public DisplayLabelValueParcelable(DisplayLabelValue displayLabelValue) {
18+
this.displayLabel = displayLabelValue.displayLabel;
19+
this.value = displayLabelValue.value;
20+
}
21+
22+
public static List<DisplayLabelValueParcelable> mapDisplayLabelValuesToDisplayLabelValueParcelables(List<DisplayLabelValue> displayLabelValues) {
23+
List<DisplayLabelValueParcelable> displayLabelValueParcelables = new ArrayList<>();
24+
if (displayLabelValues != null) {
25+
for (DisplayLabelValue displayLabelValue: displayLabelValues) {
26+
displayLabelValueParcelables.add(new DisplayLabelValueParcelable(displayLabelValue));
27+
}
28+
}
29+
return displayLabelValueParcelables;
30+
}
31+
32+
@Override
33+
public String toString() {
34+
return "DisplayLabelValueParcelable{" +
35+
"displayLabel='" + displayLabel + '\'' +
36+
", value='" + value + '\'' +
37+
'}';
38+
}
39+
40+
public String getDisplayLabel() {
41+
return displayLabel;
42+
}
43+
44+
public String getValue() {
45+
return value;
46+
}
47+
48+
@Override
49+
public boolean equals(Object o) {
50+
if (this == o) return true;
51+
if (o == null || getClass() != o.getClass()) return false;
52+
53+
DisplayLabelValueParcelable that = (DisplayLabelValueParcelable) o;
54+
55+
if (displayLabel != null ? !displayLabel.equals(that.displayLabel) : that.displayLabel != null)
56+
return false;
57+
return value != null ? value.equals(that.value) : that.value == null;
58+
}
59+
60+
@Override
61+
public int hashCode() {
62+
int result = displayLabel != null ? displayLabel.hashCode() : 0;
63+
result = 31 * result + (value != null ? value.hashCode() : 0);
64+
return result;
65+
}
66+
67+
@Override
68+
public int describeContents() {
69+
return 0;
70+
}
71+
72+
@Override
73+
public void writeToParcel(Parcel dest, int flags) {
74+
dest.writeString(this.displayLabel);
75+
dest.writeString(this.value);
76+
}
77+
78+
protected DisplayLabelValueParcelable(Parcel in) {
79+
this.displayLabel = in.readString();
80+
this.value = in.readString();
81+
}
82+
83+
public static final Parcelable.Creator<DisplayLabelValueParcelable> CREATOR = new Parcelable.Creator<DisplayLabelValueParcelable>() {
84+
@Override
85+
public DisplayLabelValueParcelable createFromParcel(Parcel source) {
86+
return new DisplayLabelValueParcelable(source);
87+
}
88+
89+
@Override
90+
public DisplayLabelValueParcelable[] newArray(int size) {
91+
return new DisplayLabelValueParcelable[size];
92+
}
93+
};
94+
}

0 commit comments

Comments
 (0)