0

I have a simple test in which I was testing if the POST of a json is successful. This was my test:

int expectedCodeResponse = 201;
Map<String, String> params = new HashMap<String, String>();
    params.put("batchPublicId", "001");
    params.put("fileSize", "2");
    params.put("location", "{\\\"bucket\\\":\\\"blabla\\\"}");
    params.put("title", "testInvoice");
    JSONObject parameter = new JSONObject(params);

OkHttpClient httpClient = new OkHttpClient();

    RequestBody body = RequestBody.create(JSON, parameter.toString());
    Request request = new Request.Builder()
            .url(environmentUrls.get("base_url") + "/invoices")
            .post(body)
            .addHeader("content-type", "application/json; charset=utf-8")
            .build();


    Response response = httpClient.newCall(request).execute();

    Assert.assertEquals(response.code(), expectedCodeResponse);

Now it doesn't work anymore because fileSize is not a String anymore, it's an int. How can I solve this?

H.A.
  • 161
  • 1
  • 4
  • 18
  • Possible duplicate of [OkHttp Post Body as JSON](https://stackoverflow.com/questions/34179922/okhttp-post-body-as-json) – Andrea Motto Mar 23 '18 at 04:22

1 Answers1

0

convert your string to an int like this, and assess equality of both ints.

    ...

    Response response = httpClient.newCall(request).execute();

    Assert.assertEquals(Integer.parseInt(response.code()), expectedCodeResponse);
Community
  • 1
  • 1
Sventies
  • 2,314
  • 1
  • 28
  • 44