Adding docs and tests for some API handler classes (GetAccountBalances and GetAccountByName)
This commit is contained in:
parent
c29830da9b
commit
f367eb0021
4 changed files with 137 additions and 17 deletions
|
@ -19,6 +19,14 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Class that implements get_account_balances request handler.
|
||||
*
|
||||
* Get an account’s balances in various assets.
|
||||
*
|
||||
* The request returns the balances of the account
|
||||
*
|
||||
* @see <a href="https://goo.gl/faFdey">get_account_balances API doc</a>
|
||||
*
|
||||
* Created by nelson on 1/13/17.
|
||||
*/
|
||||
public class GetAccountBalances extends BaseGrapheneHandler {
|
||||
|
@ -27,18 +35,35 @@ public class GetAccountBalances extends BaseGrapheneHandler {
|
|||
private List<Asset> mAssetList;
|
||||
private boolean mOneTime;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
/**
|
||||
* Default Constructor
|
||||
*
|
||||
* @param userAccount account to get balances for
|
||||
* @param assets list of the assets to get balances of; if empty, get all assets account has a balance in
|
||||
* @param oneTime boolean value indicating if websocket must be closed (true) or not (false)
|
||||
* after the response
|
||||
* @param listener A class implementing the WitnessResponseListener interface. This should
|
||||
* be implemented by the party interested in being notified about the success/failure
|
||||
* of the transaction broadcast operation.
|
||||
*/
|
||||
public GetAccountBalances(UserAccount userAccount, boolean oneTime, List<Asset> assets, WitnessResponseListener listener) {
|
||||
public GetAccountBalances(UserAccount userAccount, List<Asset> assets, boolean oneTime, WitnessResponseListener listener) {
|
||||
super(listener);
|
||||
this.mUserAccount = userAccount;
|
||||
this.mAssetList = assets;
|
||||
this.mOneTime = oneTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Using this constructor the websocket connection closes after the response.
|
||||
*
|
||||
* @param userAccount account to get balances for
|
||||
* @param assets list of the assets to get balances of; if empty, get all assets account has a balance in
|
||||
* @param listener A class implementing the WitnessResponseListener interface. This should
|
||||
* be implemented by the party interested in being notified about the success/failure
|
||||
* of the transaction broadcast operation.
|
||||
*/
|
||||
public GetAccountBalances(UserAccount userAccount, List<Asset> assets, WitnessResponseListener listener) {
|
||||
this(userAccount, true, assets, listener);
|
||||
this(userAccount, assets, true, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,6 +20,14 @@ import de.bitsharesmunich.graphenej.models.ApiCall;
|
|||
import de.bitsharesmunich.graphenej.models.WitnessResponse;
|
||||
|
||||
/**
|
||||
* Class that implements get_account_by_name request handler.
|
||||
*
|
||||
* Get an account’s info by name.
|
||||
*
|
||||
* The request returns account data that refer to the name.
|
||||
*
|
||||
* @see <a href="https://goo.gl/w75qjV">get_account_by_name API doc</a>
|
||||
*
|
||||
* Created by nelson on 11/15/16.
|
||||
*/
|
||||
public class GetAccountByName extends BaseGrapheneHandler {
|
||||
|
@ -28,6 +36,16 @@ public class GetAccountByName extends BaseGrapheneHandler {
|
|||
private WitnessResponseListener mListener;
|
||||
private boolean mOneTime;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*
|
||||
* @param accountName name of the account to get info
|
||||
* @param oneTime boolean value indicating if websocket must be closed (true) or not (false)
|
||||
* after the response
|
||||
* @param listener A class implementing the WitnessResponseListener interface. This should
|
||||
* be implemented by the party interested in being notified about the success/failure
|
||||
* of the transaction broadcast operation.
|
||||
*/
|
||||
public GetAccountByName(String accountName, boolean oneTime, WitnessResponseListener listener){
|
||||
super(listener);
|
||||
this.accountName = accountName;
|
||||
|
@ -35,6 +53,14 @@ public class GetAccountByName extends BaseGrapheneHandler {
|
|||
this.mListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Using this constructor the websocket connection closes after the response.
|
||||
*
|
||||
* @param accountName name of the account to get info
|
||||
* @param listener A class implementing the WitnessResponseListener interface. This should
|
||||
* be implemented by the party interested in being notified about the success/failure
|
||||
* of the transaction broadcast operation.
|
||||
*/
|
||||
public GetAccountByName(String accountName, WitnessResponseListener listener){
|
||||
this(accountName, true, listener);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,15 @@ import de.bitsharesmunich.graphenej.models.BaseResponse;
|
|||
import de.bitsharesmunich.graphenej.models.WitnessResponse;
|
||||
|
||||
/**
|
||||
* Created by nelson on 11/15/16.
|
||||
* Class that implements get_limit_orders request handler.
|
||||
*
|
||||
* Get limit orders in a given market.
|
||||
*
|
||||
* The request returns the limit orders, ordered from least price to greatest
|
||||
*
|
||||
* @see <a href="https://goo.gl/5sRTRq">get_limit_orders API doc</a>
|
||||
*
|
||||
* Created by nelson on 1/5/17.
|
||||
*/
|
||||
public class GetLimitOrders extends BaseGrapheneHandler {
|
||||
|
||||
|
@ -34,6 +42,18 @@ public class GetLimitOrders extends BaseGrapheneHandler {
|
|||
private boolean mOneTime;
|
||||
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*
|
||||
* @param a id of asset being sold
|
||||
* @param b id of asset being purchased
|
||||
* @param limit maximum number of orders to retrieve
|
||||
* @param oneTime boolean value indicating if websocket must be closed (true) or not (false)
|
||||
* after the response
|
||||
* @param mListener A class implementing the WitnessResponseListener interface. This should
|
||||
* be implemented by the party interested in being notified about the success/failure
|
||||
* of the transaction broadcast operation.
|
||||
*/
|
||||
public GetLimitOrders(String a, String b, int limit, boolean oneTime, WitnessResponseListener mListener) {
|
||||
super(mListener);
|
||||
this.a = a;
|
||||
|
@ -43,6 +63,16 @@ public class GetLimitOrders extends BaseGrapheneHandler {
|
|||
this.mListener = mListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Using this constructor the websocket connection closes after the response.
|
||||
*
|
||||
* @param a id of asset being sold
|
||||
* @param b id of asset being purchased
|
||||
* @param limit maximum number of orders to retrieve
|
||||
* @param mListener A class implementing the WitnessResponseListener interface. This should
|
||||
* be implemented by the party interested in being notified about the success/failure
|
||||
* of the transaction broadcast operation.
|
||||
*/
|
||||
public GetLimitOrders(String a, String b, int limit, WitnessResponseListener mListener) {
|
||||
this(a, b, limit, true, mListener);
|
||||
}
|
||||
|
|
|
@ -27,10 +27,10 @@ import de.bitsharesmunich.graphenej.Address;
|
|||
* Created by nelson on 6/26/17.
|
||||
*/
|
||||
public class NodeConnectionTest {
|
||||
private String BLOCK_PAY_DE = System.getenv("OPENLEDGER_EU");
|
||||
private String NODE_URL_1 = System.getenv("NODE_URL_1");
|
||||
private String NODE_URL_2 = System.getenv("NODE_URL_2");
|
||||
private String NODE_URL_3 = System.getenv("NODE_URL_3");
|
||||
private String NODE_URL_4 = System.getenv("NODE_URL_4");
|
||||
private String ACCOUNT_ID = System.getenv("ACCOUNT_ID");
|
||||
private String ACCOUNT_NAME = System.getenv("ACCOUNT_NAME");
|
||||
private long BlOCK_TEST_NUMBER = Long.parseLong(System.getenv("BlOCK_TEST_NUMBER"));
|
||||
|
@ -75,7 +75,7 @@ public class NodeConnectionTest {
|
|||
@Test
|
||||
public void testNodeConnection(){
|
||||
nodeConnection = NodeConnection.getInstance();
|
||||
nodeConnection.addNodeUrl(BLOCK_PAY_DE);
|
||||
nodeConnection.addNodeUrl(NODE_URL_1);
|
||||
nodeConnection.connect("", "", true, mErrorListener);
|
||||
|
||||
Timer timer = new Timer();
|
||||
|
@ -93,15 +93,22 @@ public class NodeConnectionTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
/**
|
||||
* Test for NodeConnection's addNodeUrl and addNodeUrls working together.
|
||||
*
|
||||
* Need to setup the NODE_URL_(1 to 4) env to work. Some of the nodes may have invalid nodes
|
||||
* websockets URL just to test the hop.
|
||||
*
|
||||
*/
|
||||
public void testNodeHopFeature(){
|
||||
nodeConnection = NodeConnection.getInstance();
|
||||
nodeConnection.addNodeUrl(NODE_URL_1);
|
||||
nodeConnection.addNodeUrl(NODE_URL_4);
|
||||
//Test adding a "sublist"
|
||||
ArrayList<String> urlList = new ArrayList<String>(){{
|
||||
add(NODE_URL_1);
|
||||
add(NODE_URL_2);
|
||||
add(NODE_URL_3);
|
||||
add(NODE_URL_3);
|
||||
}};
|
||||
nodeConnection.addNodeUrl(BLOCK_PAY_DE);
|
||||
nodeConnection.addNodeUrl(NODE_URL_1);
|
||||
|
||||
nodeConnection.connect("", "", true, mErrorListener);
|
||||
|
||||
|
@ -119,10 +126,16 @@ public class NodeConnectionTest {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for GetAccountBalances Handler.
|
||||
*
|
||||
* Request balances for a valid account (Need to setup the ACCOUNT_ID env with desired account id)
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testGetAccountBalancesRequest(){
|
||||
nodeConnection = NodeConnection.getInstance();
|
||||
nodeConnection.addNodeUrl(BLOCK_PAY_DE);
|
||||
nodeConnection.addNodeUrl(NODE_URL_1);
|
||||
nodeConnection.connect("", "", false, mErrorListener);
|
||||
|
||||
System.out.println("Adding GetAccountBalances here");
|
||||
|
@ -132,7 +145,26 @@ public class NodeConnectionTest {
|
|||
assetList.add(BTS);
|
||||
assetList.add(BITDOLAR);
|
||||
assetList.add(BITEURO);
|
||||
nodeConnection.addRequestHandler(new GetAccountBalances(userAccount, false, assetList, new WitnessResponseListener(){
|
||||
System.out.println("Test: Request to discrete asset list");
|
||||
nodeConnection.addRequestHandler(new GetAccountBalances(userAccount, assetList, false, new WitnessResponseListener(){
|
||||
@Override
|
||||
public void onSuccess(WitnessResponse response) {
|
||||
System.out.println("getAccountBalances.onSuccess");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(BaseResponse.Error error) {
|
||||
System.out.println("getAccountBalances.onError. Msg: "+ error.message);
|
||||
}
|
||||
}));
|
||||
}catch(RepeatedRequestIdException e){
|
||||
System.out.println("RepeatedRequestIdException. Msg: "+e.getMessage());
|
||||
}
|
||||
|
||||
try{
|
||||
UserAccount userAccount = new UserAccount(ACCOUNT_ID);
|
||||
System.out.println("Test: Request to all account' assets balance");
|
||||
nodeConnection.addRequestHandler(new GetAccountBalances(userAccount, null, false, new WitnessResponseListener(){
|
||||
@Override
|
||||
public void onSuccess(WitnessResponse response) {
|
||||
System.out.println("getAccountBalances.onSuccess");
|
||||
|
@ -158,9 +190,16 @@ public class NodeConnectionTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
/**
|
||||
* Test for GetAccountByName Handler.
|
||||
*
|
||||
* Request for a valid account name by name (Need to setup the ACCOUNT_NAME env with desired
|
||||
* account name)
|
||||
*
|
||||
*/
|
||||
public void testGetAccountByNameRequest(){
|
||||
nodeConnection = NodeConnection.getInstance();
|
||||
nodeConnection.addNodeUrl(BLOCK_PAY_DE);
|
||||
nodeConnection.addNodeUrl(NODE_URL_1);
|
||||
nodeConnection.connect("", "", false, mErrorListener);
|
||||
|
||||
System.out.println("Adding GetAccountByName here");
|
||||
|
@ -193,7 +232,7 @@ public class NodeConnectionTest {
|
|||
@Test
|
||||
public void testGetAllAssetHoldersRequest(){
|
||||
nodeConnection = NodeConnection.getInstance();
|
||||
nodeConnection.addNodeUrl(BLOCK_PAY_DE);
|
||||
nodeConnection.addNodeUrl(NODE_URL_1);
|
||||
nodeConnection.connect("", "", false, mErrorListener);
|
||||
|
||||
System.out.println("Adding GetAllAssetHolders request");
|
||||
|
@ -226,7 +265,7 @@ public class NodeConnectionTest {
|
|||
@Test
|
||||
public void testGetBlockHeaderRequest(){
|
||||
nodeConnection = NodeConnection.getInstance();
|
||||
nodeConnection.addNodeUrl(BLOCK_PAY_DE);
|
||||
nodeConnection.addNodeUrl(NODE_URL_1);
|
||||
nodeConnection.connect("", "", false, mErrorListener);
|
||||
|
||||
|
||||
|
@ -261,7 +300,7 @@ public class NodeConnectionTest {
|
|||
@Test
|
||||
public void testGetKeyReferencesRequest(){
|
||||
nodeConnection = NodeConnection.getInstance();
|
||||
nodeConnection.addNodeUrl(BLOCK_PAY_DE);
|
||||
nodeConnection.addNodeUrl(NODE_URL_1);
|
||||
nodeConnection.connect("", "", false, mErrorListener);
|
||||
|
||||
Address address1 = null;
|
||||
|
|
Loading…
Reference in a new issue