use of com.urbanairship.connect.client.model.request.filters.NotificationFilter in project connect-java-library by urbanairship.
the class StreamConnectionTest method testRequestBodyWithFilter.
@Test
public void testRequestBodyWithFilter() 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());
DeviceFilter device1 = new DeviceFilter(DeviceFilterType.ANDROID_CHANNEL, "c8044c8a-d5fa-4e58-91d4-54d0f70b7409");
DeviceFilter device2 = new DeviceFilter(DeviceFilterType.IOS_CHANNEL, "3d970087-600e-4bb6-8474-5857d438faaa");
DeviceFilter device3 = new DeviceFilter(DeviceFilterType.NAMED_USER_ID, "cool user");
NotificationFilter notification = new NotificationFilter(NotificationFilter.Type.GROUP_ID, "a30abf06-7878-4096-9535-b50ac0ad6e8e");
Filter filter1 = Filter.newBuilder().setLatency(20000000).addDevices(device1, device2, device3).addDeviceTypes(DeviceType.ANDROID).addNotifications(notification).addEventTypes("OPEN").build();
Filter filter2 = Filter.newBuilder().setLatency(400).addDeviceTypes(DeviceType.IOS).addEventTypes("TAG_CHANGE").build();
StreamQueryDescriptor descriptor = filterDescriptor(filter1, filter2);
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(new HashSet<>(Arrays.asList(filter1, filter2))), gson.toJson(bodyObj.get("filters")));
}
Aggregations