Adding support for a string-based query when using the LookupAssetSymbols API
This commit is contained in:
parent
3406fcdd68
commit
70b251a665
2 changed files with 70 additions and 5 deletions
|
@ -28,7 +28,7 @@ import cy.agorise.graphenej.models.WitnessResponse;
|
||||||
*/
|
*/
|
||||||
public class LookupAssetSymbols extends BaseGrapheneHandler {
|
public class LookupAssetSymbols extends BaseGrapheneHandler {
|
||||||
private WitnessResponseListener mListener;
|
private WitnessResponseListener mListener;
|
||||||
private List<Asset> assets;
|
private List<? extends Object> assets;
|
||||||
|
|
||||||
private boolean mOneTime;
|
private boolean mOneTime;
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ public class LookupAssetSymbols extends BaseGrapheneHandler {
|
||||||
* be implemented by the party interested in being notified about the
|
* be implemented by the party interested in being notified about the
|
||||||
* success/failure of the operation.
|
* success/failure of the operation.
|
||||||
*/
|
*/
|
||||||
public LookupAssetSymbols(List<Asset> assets, boolean oneTime, WitnessResponseListener listener){
|
public LookupAssetSymbols(List<? extends Object> assets, boolean oneTime, WitnessResponseListener listener){
|
||||||
super(listener);
|
super(listener);
|
||||||
this.assets = assets;
|
this.assets = assets;
|
||||||
this.mOneTime = oneTime;
|
this.mOneTime = oneTime;
|
||||||
|
@ -57,7 +57,7 @@ public class LookupAssetSymbols extends BaseGrapheneHandler {
|
||||||
* be implemented by the party interested in being notified about the
|
* be implemented by the party interested in being notified about the
|
||||||
* success/failure of the operation.
|
* success/failure of the operation.
|
||||||
*/
|
*/
|
||||||
public LookupAssetSymbols(List<Asset> assets, WitnessResponseListener listener){
|
public LookupAssetSymbols(List<Object> assets, WitnessResponseListener listener){
|
||||||
this(assets, true, listener);
|
this(assets, true, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,8 +65,13 @@ public class LookupAssetSymbols extends BaseGrapheneHandler {
|
||||||
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
|
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
|
||||||
ArrayList<Serializable> params = new ArrayList<>();
|
ArrayList<Serializable> params = new ArrayList<>();
|
||||||
ArrayList<String> subArray = new ArrayList<>();
|
ArrayList<String> subArray = new ArrayList<>();
|
||||||
for(Asset asset : this.assets){
|
for(int i = 0; i < assets.size(); i++){
|
||||||
subArray.add(asset.getObjectId());
|
Object obj = assets.get(i);
|
||||||
|
if(obj instanceof String){
|
||||||
|
subArray.add((String) obj);
|
||||||
|
}else{
|
||||||
|
subArray.add(((Asset) obj).getObjectId());
|
||||||
|
}
|
||||||
params.add(subArray);
|
params.add(subArray);
|
||||||
}
|
}
|
||||||
ApiCall loginCall = new ApiCall(0, RPC.CALL_LOOKUP_ASSET_SYMBOLS, params, RPC.VERSION, 0);
|
ApiCall loginCall = new ApiCall(0, RPC.CALL_LOOKUP_ASSET_SYMBOLS, params, RPC.VERSION, 0);
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
package cy.agorise.graphenej.api;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import cy.agorise.graphenej.Asset;
|
||||||
|
import cy.agorise.graphenej.interfaces.WitnessResponseListener;
|
||||||
|
import cy.agorise.graphenej.models.BaseResponse;
|
||||||
|
import cy.agorise.graphenej.models.WitnessResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testing the standalone usage of the {@link LookupAssetSymbols} API handler.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class LookupAssetSymbolsTest extends BaseApiTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLookupAssetSymbolsWithString(){
|
||||||
|
ArrayList<String> assetSymbols = new ArrayList<>();
|
||||||
|
assetSymbols.add("USD");
|
||||||
|
mWebSocket.addListener(new LookupAssetSymbols(assetSymbols, true, new WitnessResponseListener() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(WitnessResponse response) {
|
||||||
|
System.out.println("onSuccess");
|
||||||
|
List<Asset> assets = (List<Asset>) response.result;
|
||||||
|
Assert.assertEquals(1, assets.size());
|
||||||
|
Assert.assertEquals("1.3.121", assets.get(0).getObjectId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(BaseResponse.Error error) {
|
||||||
|
System.out.println("onError");
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLookupAssetSymbolsWithAsset(){
|
||||||
|
ArrayList<Asset> assetSymbols = new ArrayList<>();
|
||||||
|
assetSymbols.add(new Asset("1.3.121"));
|
||||||
|
mWebSocket.addListener(new LookupAssetSymbols(assetSymbols, true, new WitnessResponseListener() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(WitnessResponse response) {
|
||||||
|
System.out.println("onSuccess");
|
||||||
|
List<Asset> assets = (List<Asset>) response.result;
|
||||||
|
Assert.assertEquals(1, assets.size());
|
||||||
|
Assert.assertEquals("1.3.121", assets.get(0).getObjectId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(BaseResponse.Error error) {
|
||||||
|
System.out.println("onError");
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue