1

I am writing an integration test for a java component that calls some local service (in port 8888). I am able to intercept the call by passing the port as an argument to the MockWebServer, like this:

MockWebServer server= new MockWebServer();
        server.start(8888);
        server.enqueue(new MockResponse().setBody("{ \"score\": \"1.0\", \"match\": true, \"id\":\"faq.faq8\"}")
                .addHeader("Content-Type", "application/json"));

Now the actual call is something like this:

ResponseEntity<Response> responseEntity = restTemplate.exchange(url.toUriString(), HttpMethod.POST,
                    requestEntity, Response.class);

And the response class looks like this:

public static class Response implements Serializable {
        /* Serial UUID. */
        private static final long serialVersionUID = -7548720302478842018L;

        private boolean match;
        private float score;
        private String id;

        public boolean isMatch() {
            return match;
        }

        public float getScore() {
            return score;
        }

        public String getId() {
            return id;
        }
    }

I can make the response score and match fields to be whatever I want, but the id field is always null. I honestly have no idea why.

carlos palma
  • 722
  • 3
  • 12
  • 29

0 Answers0