use of com.urbanairship.connect.client.model.request.Subset in project connect-java-library by urbanairship.
the class StreamConnectionTest method testRequestBodyWithSubset.
@Test
public void testRequestBodyWithSubset() throws Exception {
final AtomicReference<String> body = new AtomicReference<>();
final CountDownLatch received = new CountDownLatch(1);
Answer httpAnswer = new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
HttpExchange exchange = (HttpExchange) invocation.getArguments()[0];
int length = Integer.parseInt(exchange.getRequestHeaders().getFirst(HttpHeaders.CONTENT_LENGTH));
byte[] bytes = new byte[length];
exchange.getRequestBody().read(bytes);
body.set(new String(bytes, UTF_8));
exchange.sendResponseHeaders(200, 0L);
received.countDown();
return null;
}
};
doAnswer(httpAnswer).when(serverHandler).handle(Matchers.<HttpExchange>any());
Subset subset = Subset.createPartitionSubset().setCount(10).setSelection(0).build();
StreamQueryDescriptor descriptor = subsetDescriptor(subset);
stream = new StreamConnection(descriptor, http, connectionRetryStrategy, consumer, url);
read(stream, Optional.<StartPosition>absent());
assertTrue(received.await(10, TimeUnit.SECONDS));
Gson gson = GsonUtil.getGson();
JsonObject bodyObj = parser.parse(body.get()).getAsJsonObject();
assertEquals(gson.toJson(subset), gson.toJson(bodyObj.get("subset")));
}
Aggregations