Search in sources :

Example 21 with JsonApiDocument

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);
}
Also used : JsonApiDocument(com.yahoo.elide.jsonapi.models.JsonApiDocument) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 22 with JsonApiDocument

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));
}
Also used : JsonApiDocument(com.yahoo.elide.jsonapi.models.JsonApiDocument) Resource(com.yahoo.elide.jsonapi.models.Resource) Test(org.junit.Test)

Example 23 with JsonApiDocument

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)));
}
Also used : JsonApiDocument(com.yahoo.elide.jsonapi.models.JsonApiDocument) Resource(com.yahoo.elide.jsonapi.models.Resource) Data(com.yahoo.elide.jsonapi.models.Data) ResourceNotFoundException(com.faforever.api.web.ResourceNotFoundException) Async(org.springframework.scheduling.annotation.Async) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with JsonApiDocument

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)));
}
Also used : JsonApiDocument(com.yahoo.elide.jsonapi.models.JsonApiDocument) Resource(com.yahoo.elide.jsonapi.models.Resource) Data(com.yahoo.elide.jsonapi.models.Data) ResourceNotFoundException(com.faforever.api.web.ResourceNotFoundException) Async(org.springframework.scheduling.annotation.Async) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 25 with JsonApiDocument

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());
}
Also used : JsonApiDocument(com.yahoo.elide.jsonapi.models.JsonApiDocument) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Test(org.junit.jupiter.api.Test) IntegrationTest(com.yahoo.elide.initialization.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

JsonApiDocument (com.yahoo.elide.jsonapi.models.JsonApiDocument)51 Resource (com.yahoo.elide.jsonapi.models.Resource)31 Test (org.junit.jupiter.api.Test)26 PersistentResource (com.yahoo.elide.core.PersistentResource)25 RequestScope (com.yahoo.elide.core.RequestScope)15 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)9 Data (com.yahoo.elide.jsonapi.models.Data)8 IOException (java.io.IOException)7 TestRequestScope (com.yahoo.elide.core.TestRequestScope)6 Parent (example.Parent)6 InvalidEntityBodyException (com.yahoo.elide.core.exceptions.InvalidEntityBodyException)5 EntityProjectionMaker (com.yahoo.elide.jsonapi.EntityProjectionMaker)4 PatchRequestScope (com.yahoo.elide.jsonapi.extensions.PatchRequestScope)4 Relationship (com.yahoo.elide.jsonapi.models.Relationship)4 BaseVisitor (com.yahoo.elide.jsonapi.parser.BaseVisitor)4 Child (example.Child)4 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)3 JsonApiMapper (com.yahoo.elide.jsonapi.JsonApiMapper)3 DocumentProcessor (com.yahoo.elide.jsonapi.document.processors.DocumentProcessor)3 IncludedProcessor (com.yahoo.elide.jsonapi.document.processors.IncludedProcessor)3