SimpleRoadClient implements RoadClient<T> { @Override public StandardResponse sendMessage(T message) { return sendMessages(singletonList(message)).get(0); } @Deprecated /** @deprecated Use {@link #SimpleRoadClient(OnrampOptions)} */  SimpleRoadClient(String host, String username, String password, String roadName); @Deprecated /** @deprecated Use {@link #SimpleRoadClient(OnrampOptions)} */  SimpleRoadClient(String host, String username, String password, String roadName, int threads); @Deprecated /** @deprecated Use {@link #SimpleRoadClient(OnrampOptions)} */  SimpleRoadClient(String host, String username, String password, String roadName, ObjectMapper objectMapper); @Deprecated /** @deprecated Use {@link #SimpleRoadClient(OnrampOptions)} */  SimpleRoadClient(
      String host,
      String username,
      String password,
      String roadName,
      int threads,
      ObjectMapper objectMapper); @Deprecated /** @deprecated Use {@link #SimpleRoadClient(OnrampOptions)} */  SimpleRoadClient(
      String host,
      String username,
      String password,
      String roadName,
      int threads,
      TLSConfig tlsConfig); @Deprecated /** @deprecated Use {@link #SimpleRoadClient(OnrampOptions)} */  SimpleRoadClient(
      String host,
      String username,
      String password,
      String roadName,
      int threads,
      TLSConfig tlsConfig,
      ObjectMapper objectMapper);  SimpleRoadClient(OnrampOptions options); @Override StandardResponse sendMessage(T message); @Override List<StandardResponse> sendMessages(List<T> messages); String errorResponseAsString(HttpResponse response); @Override void close();  }
@Test public void singleMessage() throws Exception { stubFor(post(urlEqualTo("/onramp/v1/roads/" + TEST_ROAD + "/messages")).withBasicAuth("user", "pass").willReturn( aResponse().withStatus(HttpStatus.SC_OK).withBody(createStubResponse(1, true, "accepted: ")))); SimpleModel messageModel = new SimpleModel(); messageModel.setId(1L); messageModel.setStr("test message"); StandardResponse response = underTest.sendMessage(messageModel); assertThat(response.isSuccess(), is(true)); assertThat(response.getTimestamp(), is(100L)); assertThat(response.getMessage(), is("accepted: 0")); }
@Test(expected = OnrampException.class) public void internalServerError() throws Exception { stubFor(post(urlEqualTo("/onramp/v1/roads/" + TEST_ROAD + "/messages")).willReturn( aResponse().withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR).withBody(INTERNAL_SERVER_ERROR_MESSAGE))); SimpleModel messageModel = new SimpleModel(); messageModel.setId(1L); messageModel.setStr("test message"); underTest.sendMessage(messageModel); }
@Test(expected = OnrampEncodingException.class) public void responseParseError() throws Exception { stubFor(post(urlEqualTo("/onramp/v1/roads/" + TEST_ROAD + "/messages")) .willReturn(aResponse().withStatus(HttpStatus.SC_OK).withBody(INVALID_JSON))); SimpleModel messageModel = new SimpleModel(); messageModel.setId(1L); messageModel.setStr("test message"); underTest.sendMessage(messageModel); }
@Test(expected = OnrampException.class) public void ioError() throws Exception { stubFor(post(urlEqualTo("/onramp/v1/roads/" + TEST_ROAD + "/messages")) .willReturn(aResponse().withFault(Fault.RANDOM_DATA_THEN_CLOSE))); SimpleModel messageModel = new SimpleModel(); messageModel.setId(1L); messageModel.setStr("test message"); underTest.sendMessage(messageModel); }
@Test public void badRequest() throws Exception { stubFor(post(urlEqualTo("/onramp/v1/roads/" + TEST_ROAD + "/messages")) .willReturn(aResponse().withStatus(SC_BAD_REQUEST).withBody(createSingleResponse(0, false, "error")))); SimpleModel messageModel = new SimpleModel(); messageModel.setId(1L); messageModel.setStr("test message"); StandardResponse response = underTest.sendMessage(messageModel); assertThat(response.isSuccess(), is(false)); assertThat(response.getMessage(), is("error")); }
@Test(expected = OnrampException.class) public void anotherIOError() throws Exception { stubFor(post(urlEqualTo("/onramp/v1/roads/" + TEST_ROAD + "/messages")) .willReturn(aResponse().withFault(Fault.MALFORMED_RESPONSE_CHUNK))); SimpleModel messageModel = new SimpleModel(); messageModel.setId(1L); messageModel.setStr("test message"); underTest.sendMessage(messageModel); }