AnalyticsResource { @POST @Path("/async") @Timed @ApiOperation("runSyncAsync") public AsyncDataToken runSyncAsync(@Valid final ActionRequest request) { return queryExecutor.executeAsync(request); } @Inject  AnalyticsResource(final QueryExecutor queryExecutor, final ObjectMapper objectMapper); @POST @Timed @ApiOperation("runSync") ActionResponse runSync(@Valid final ActionRequest request); @POST @Path("/async") @Timed @ApiOperation("runSyncAsync") AsyncDataToken runSyncAsync(@Valid final ActionRequest request); @POST @Path("/validate") @Timed @ApiOperation("validateQuery") ActionValidationResponse validateQuery(@Valid final ActionRequest request); @POST @Produces(FoxtrotExtraMediaType.TEXT_CSV) @Path("/download") @Timed @ApiOperation("downloadAnalytics") StreamingOutput download(@Valid final ActionRequest actionRequest);  }
@Test public void testRunSyncAsync() throws Exception { GroupRequest groupRequest = new GroupRequest(); groupRequest.setTable(TestUtils.TEST_TABLE_NAME); groupRequest.setNesting(Arrays.asList("os", "device", "version")); Map<String, Object> expectedResponse = new LinkedHashMap<String, Object>(); final Map<String, Object> nexusResponse = new LinkedHashMap<String, Object>() {{ put("1", 2); put("2", 2); put("3", 1); }}; final Map<String, Object> galaxyResponse = new LinkedHashMap<String, Object>() {{ put("2", 1); put("3", 1); }}; expectedResponse.put("android", new LinkedHashMap<String, Object>() {{ put("nexus", nexusResponse); put("galaxy", galaxyResponse); }}); final Map<String, Object> nexusResponse2 = new LinkedHashMap<String, Object>() {{ put("2", 1); }}; final Map<String, Object> iPadResponse = new LinkedHashMap<String, Object>() {{ put("2", 2); }}; final Map<String, Object> iPhoneResponse = new LinkedHashMap<String, Object>() {{ put("1", 1); }}; expectedResponse.put("ios", new LinkedHashMap<String, Object>() {{ put("nexus", nexusResponse2); put("ipad", iPadResponse); put("iphone", iPhoneResponse); }}); Entity<GroupRequest> serviceUserEntity = Entity.json(groupRequest); AsyncDataToken response = resources.client() .target("/v1/analytics/async") .request() .post(serviceUserEntity, AsyncDataToken.class); await().pollDelay(2000, TimeUnit.MILLISECONDS).until(() -> true); GroupResponse actualResponse = GroupResponse.class.cast(getCacheManager().getCacheFor(response.getAction()) .get(response.getKey())); assertEquals(expectedResponse, actualResponse.getResult()); }