Search in sources :

Example 1 with MinerRoot

use of it.angelic.mpw.model.jsonpojos.miners.MinerRoot in project MPW by shineangelic.

the class MasterInstrumentedTest method TestJsonWalletSyncReq.

@Test
public void TestJsonWalletSyncReq() {
    RequestFuture<JSONObject> future = RequestFuture.newFuture();
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, Utils.getMinersStatsUrl(sharedPreferences), new JSONObject(), future, future);
    JSONClientSingleton.getInstance(appContext).addToRequestQueue(request);
    Gson gson = TestUtils.getGsonFromBuilder();
    String addr = null;
    try {
        // this will block
        JSONObject response = future.get();
        MinerRoot retrieved = gson.fromJson(response.toString(), MinerRoot.class);
        HashMap<String, Miner> map = retrieved.getMiners();
        String[] minerArr = new String[map.size()];
        minerArr = map.keySet().toArray(minerArr);
        Assume.assumeTrue(minerArr.length > 0);
        addr = minerArr[0];
    } catch (InterruptedException e) {
        fail(e.getMessage());
    } catch (ExecutionException e) {
        fail(e.getMessage());
    }
    RequestFuture<JSONObject> futuress = RequestFuture.newFuture();
    try {
        JsonObjectRequest requesst = new JsonObjectRequest(Request.Method.GET, Utils.getWalletStatsUrl(sharedPreferences) + addr, new JSONObject(), futuress, futuress);
        JSONClientSingleton.getInstance(appContext).addToRequestQueue(requesst);
        // this will block
        JSONObject response = futuress.get();
        Wallet retrieved = gson.fromJson(response.toString(), Wallet.class);
        assertNotNull(retrieved);
    } catch (InterruptedException e) {
        fail(e.getMessage());
    } catch (ExecutionException e) {
        fail(e.getMessage());
    }
}
Also used : Miner(it.angelic.mpw.model.jsonpojos.miners.Miner) JSONObject(org.json.JSONObject) MinerRoot(it.angelic.mpw.model.jsonpojos.miners.MinerRoot) Wallet(it.angelic.mpw.model.jsonpojos.wallet.Wallet) Gson(com.google.gson.Gson) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 2 with MinerRoot

use of it.angelic.mpw.model.jsonpojos.miners.MinerRoot in project MPW by shineangelic.

the class MasterInstrumentedTest method getFirstMinerAddress.

private String getFirstMinerAddress(RequestFuture<JSONObject> future, Gson gson) throws ExecutionException, InterruptedException {
    // this will block
    JSONObject response = future.get();
    MinerRoot retrieved = gson.fromJson(response.toString(), MinerRoot.class);
    assertNotNull(retrieved);
    HashMap<String, Miner> map = retrieved.getMiners();
    String[] minerArr = new String[map.size()];
    minerArr = map.keySet().toArray(minerArr);
    assertNotNull(minerArr);
    return minerArr[0];
// assertNotNull(minerAddr);
}
Also used : Miner(it.angelic.mpw.model.jsonpojos.miners.Miner) JSONObject(org.json.JSONObject) MinerRoot(it.angelic.mpw.model.jsonpojos.miners.MinerRoot)

Example 3 with MinerRoot

use of it.angelic.mpw.model.jsonpojos.miners.MinerRoot in project MPW by shineangelic.

the class NoobPoolInstrumentedTest method testJsonMinerRequest.

@Test
public void testJsonMinerRequest() throws Exception {
    final GsonBuilder builder = new GsonBuilder();
    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, Utils.getMinersStatsUrl(sharedPreferences), null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(final JSONObject response) {
            Log.i(Constants.TAG, response.toString());
            Gson gson = builder.create();
            // Register an adapter to manage the date types as long values
            MinerRoot retrieved = gson.fromJson(response.toString(), MinerRoot.class);
            minerAddr = retrieved.getMiners().values().iterator().next().getAddress();
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e(Constants.TAG, "Error: " + error.getMessage());
        }
    });
    // Adding request to request queue
    JSONClientSingleton.getInstance(appContext).addToRequestQueue(jsonObjReq);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) MinerRoot(it.angelic.mpw.model.jsonpojos.miners.MinerRoot) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest) Test(org.junit.Test)

Example 4 with MinerRoot

use of it.angelic.mpw.model.jsonpojos.miners.MinerRoot in project MPW by shineangelic.

the class MaxHashInstrumentedTest method testJsonMinerRequest.

@Test
public void testJsonMinerRequest() throws Exception {
    final GsonBuilder builder = new GsonBuilder();
    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, Utils.getMinersStatsUrl(sharedPreferences), null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(final JSONObject response) {
            Log.i(Constants.TAG, response.toString());
            Gson gson = builder.create();
            // Register an adapter to manage the date types as long values
            MinerRoot retrieved = gson.fromJson(response.toString(), MinerRoot.class);
            minerAddr = retrieved.getMiners().values().iterator().next().getAddress();
            assertNotNull(retrieved);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e(Constants.TAG, "Error: " + error.getMessage());
            fail();
        }
    });
    // Adding request to request queue
    JSONClientSingleton.getInstance(appContext).addToRequestQueue(jsonObjReq);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) MinerRoot(it.angelic.mpw.model.jsonpojos.miners.MinerRoot) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest) Test(org.junit.Test)

Example 5 with MinerRoot

use of it.angelic.mpw.model.jsonpojos.miners.MinerRoot in project MPW by shineangelic.

the class KratosInstrumentedTest method testJsonMinerRequest.

@Test
public void testJsonMinerRequest() throws Exception {
    final GsonBuilder builder = new GsonBuilder();
    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, Utils.getMinersStatsUrl(sharedPreferences), null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(final JSONObject response) {
            Log.i(Constants.TAG, response.toString());
            Gson gson = builder.create();
            // Register an adapter to manage the date types as long values
            MinerRoot retrieved = gson.fromJson(response.toString(), MinerRoot.class);
            minerAddr = retrieved.getMiners().values().iterator().next().getAddress();
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e(Constants.TAG, "Error: " + error.getMessage());
            fail(error.getMessage());
        }
    });
    // Adding request to request queue
    JSONClientSingleton.getInstance(appContext).addToRequestQueue(jsonObjReq);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) MinerRoot(it.angelic.mpw.model.jsonpojos.miners.MinerRoot) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest) Test(org.junit.Test)

Aggregations

MinerRoot (it.angelic.mpw.model.jsonpojos.miners.MinerRoot)7 JSONObject (org.json.JSONObject)7 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)6 Gson (com.google.gson.Gson)6 Test (org.junit.Test)5 Response (com.android.volley.Response)4 VolleyError (com.android.volley.VolleyError)4 GsonBuilder (com.google.gson.GsonBuilder)3 Miner (it.angelic.mpw.model.jsonpojos.miners.Miner)3 ExecutionException (java.util.concurrent.ExecutionException)2 RadioButton (android.widget.RadioButton)1 Wallet (it.angelic.mpw.model.jsonpojos.wallet.Wallet)1