use of com.yahoo.elide.jsonapi.models.JsonApiDocument in project elide by yahoo.
the class ResourceIT method testSpecialCharacterLikeQuery.
@ParameterizedTest
@MethodSource("likeQueryProvider")
public void testSpecialCharacterLikeQuery(String filterParam, int noOfRecords) throws Exception {
String actual = given().when().get(String.format("/book?%s", filterParam)).then().statusCode(HttpStatus.SC_OK).extract().body().asString();
JsonApiDocument doc = jsonApiMapper.readJsonApiDocument(actual);
assertEquals(doc.getData().get().size(), noOfRecords);
}
use of com.yahoo.elide.jsonapi.models.JsonApiDocument in project faf-java-api by FAForever.
the class LeaderboardControllerTest method getGlobal.
@Test
public void getGlobal() throws Exception {
when(leaderboardService.getGlobalLeaderboard(1, 100)).thenReturn(new PageImpl<>(Arrays.asList(new GlobalLeaderboardEntry().setId(14).setPlayerName("JUnit 14").setMean(1500f).setDeviation(51f).setNumGames((short) 514).setRank(1), new GlobalLeaderboardEntry().setId(5).setPlayerName("JUnit 5").setMean(1400f).setDeviation(67f).setNumGames((short) 65).setRank(2))));
CompletableFuture<JsonApiDocument> result = instance.getGlobal(1, 100);
assertThat(result.get(), is(notNullValue()));
Collection<Resource> resources = result.get().getData().get();
assertThat(resources, hasSize(2));
Iterator<Resource> iterator = resources.iterator();
Resource firstEntry = iterator.next();
assertThat(firstEntry.getId(), is("14"));
assertThat(firstEntry.getAttributes().get("name"), is("JUnit 14"));
assertThat(firstEntry.getAttributes().get("mean"), is(1500f));
assertThat(firstEntry.getAttributes().get("deviation"), is(51f));
assertThat(firstEntry.getAttributes().get("numGames"), is((short) 514));
assertThat(firstEntry.getAttributes().get("rank"), is(1));
assertThat(firstEntry.getAttributes().get("rating"), is(1347));
Resource secondEntry = iterator.next();
assertThat(secondEntry.getId(), is("5"));
assertThat(secondEntry.getAttributes().get("name"), is("JUnit 5"));
assertThat(secondEntry.getAttributes().get("mean"), is(1400f));
assertThat(secondEntry.getAttributes().get("deviation"), is(67f));
assertThat(secondEntry.getAttributes().get("numGames"), is((short) 65));
assertThat(secondEntry.getAttributes().get("rank"), is(2));
assertThat(secondEntry.getAttributes().get("rating"), is(1199));
}
use of com.yahoo.elide.jsonapi.models.JsonApiDocument in project faf-java-api by FAForever.
the class LeaderboardController method getSingleGlobal.
@Async
@RequestMapping(path = "/global/{playerId}", method = RequestMethod.GET)
@ApiOperation("Lists the global leaderboard for the specified player")
public CompletableFuture<JsonApiDocument> getSingleGlobal(@PathVariable("playerId") String playerId) {
GlobalLeaderboardEntry entry = leaderboardService.getGlobalEntry(Integer.valueOf(playerId));
if (entry == null) {
throw new ResourceNotFoundException("No global leaderboard entry found for player: " + playerId);
}
Resource resource = new Resource(GLOBAL_LEADERBOARD_ENTRY, playerId, ImmutableMap.<String, Object>builder().put("name", entry.getPlayerName()).put("mean", entry.getMean()).put("deviation", entry.getDeviation()).put("numGames", entry.getNumGames()).put("rank", entry.getRank()).put("rating", (int) (entry.getMean() - 3 * entry.getDeviation())).build(), null, null, null);
return CompletableFuture.completedFuture(new JsonApiDocument(new Data<>(resource)));
}
use of com.yahoo.elide.jsonapi.models.JsonApiDocument in project faf-java-api by FAForever.
the class LeaderboardController method getSingleLadder1v1.
@Async
@RequestMapping(path = "/ladder1v1/{playerId}", method = RequestMethod.GET)
@ApiOperation("Lists the ladder1v1 leaderboard for the specified player")
public CompletableFuture<JsonApiDocument> getSingleLadder1v1(@PathVariable("playerId") String playerId) {
Ladder1v1LeaderboardEntry entry = leaderboardService.getLadder1v1Entry(Integer.valueOf(playerId));
if (entry == null) {
throw new ResourceNotFoundException("No ladder1v1 entry found for player: " + playerId);
}
Resource resource = new Resource(LADDER_1V1_LEADERBOARD_ENTRY, playerId, ImmutableMap.<String, Object>builder().put("name", entry.getPlayerName()).put("mean", entry.getMean()).put("deviation", entry.getDeviation()).put("numGames", entry.getNumGames()).put("wonGames", entry.getWonGames()).put("rank", entry.getRank()).put("rating", (int) (entry.getMean() - 3 * entry.getDeviation())).build(), null, null, null);
return CompletableFuture.completedFuture(new JsonApiDocument(new Data<>(resource)));
}
use of com.yahoo.elide.jsonapi.models.JsonApiDocument in project elide by yahoo.
the class ResourceIT method testRootCollectionWithNoOperatorFilter.
@Test
public void testRootCollectionWithNoOperatorFilter() throws Exception {
String actual = given().when().get("/parent?filter[parent.id][isnull]").then().statusCode(HttpStatus.SC_OK).extract().body().asString();
JsonApiDocument doc = jsonApiMapper.readJsonApiDocument(actual);
assertEquals(0, doc.getData().get().size());
}
Aggregations