예제 #1
0
  @Test
  public void testUpdatePreference() throws JSONException {

    JSONObject createPreferenceResult =
        mp.createPreference(
            "{'items':[{'title':'Prueba','quantity':1,'currency_id':'ARS','unit_price':10.5}]}");

    String createdPreferenceId = createPreferenceResult.getJSONObject("response").getString("id");

    JSONObject updatePreferenceResult =
        mp.updatePreference(
            createdPreferenceId, "{'items':[{'title':'Modified','quantity':2,'unit_price':2.2}]}");

    assertEquals(updatePreferenceResult.getInt("status"), 200);

    JSONObject getPreferenceResult = mp.getPreference(createdPreferenceId);

    assertEquals(getPreferenceResult.getInt("status"), 200);

    JSONObject obtainedPreference =
        (JSONObject) getPreferenceResult.getJSONObject("response").getJSONArray("items").get(0);

    assertEquals(obtainedPreference.getString("title"), "Modified");
    assertEquals(obtainedPreference.getInt("quantity"), 2);
    assertEquals(obtainedPreference.getDouble("unit_price"), 2, 2d);
  }
예제 #2
0
  @Test
  public void testCreatePreference() throws JSONException {

    JSONObject createPreferenceResult =
        mp.createPreference(
            "{'items':[{'title':'Prueba','quantity':1,'currency_id':'ARS','unit_price':10.5}]}");

    assertEquals(createPreferenceResult.getInt("status"), 201);

    JSONObject createdPreference =
        (JSONObject) createPreferenceResult.getJSONObject("response").getJSONArray("items").get(0);

    assertEquals(createdPreference.getString("title"), "Prueba");
    assertEquals(createdPreference.getInt("quantity"), 1);
    assertEquals(createdPreference.getString("currency_id"), "ARS");
    assertEquals(createdPreference.getDouble("unit_price"), 10, 5d);
  }