use of com.yahoo.elide.jsonapi.models.JsonApiDocument in project elide by yahoo.
the class IncludedProcessorTest method testExecuteSingleRelationOnCollection.
@Test
public void testExecuteSingleRelationOnCollection() throws Exception {
JsonApiDocument jsonApiDocument = new JsonApiDocument();
Set<PersistentResource> parents = new HashSet<>();
parents.add(parentRecord1);
parents.add(parentRecord2);
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
queryParams.put(INCLUDE, Collections.singletonList("children"));
testScope.setQueryParams(queryParams);
includedProcessor.execute(jsonApiDocument, parents, queryParams);
List<Resource> expectedIncluded = Arrays.asList(childRecord1.toResource(), childRecord2.toResource());
List<Resource> actualIncluded = jsonApiDocument.getIncluded();
assertEquals(expectedIncluded, actualIncluded, "Included Processor added requested resource from all records");
}
use of com.yahoo.elide.jsonapi.models.JsonApiDocument in project elide by yahoo.
the class IncludedProcessorTest method testExecuteMultipleRelations.
@Test
public void testExecuteMultipleRelations() throws Exception {
JsonApiDocument jsonApiDocument = new JsonApiDocument();
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
queryParams.put(INCLUDE, Arrays.asList("children", "spouses"));
testScope.setQueryParams(queryParams);
includedProcessor.execute(jsonApiDocument, parentRecord1, queryParams);
List<Resource> expectedIncluded = Arrays.asList(childRecord1.toResource(), parentRecord2.toResource());
List<Resource> actualIncluded = jsonApiDocument.getIncluded();
assertEquals(expectedIncluded, actualIncluded, "Included Processor added single requested resource from 'include' query param");
}
use of com.yahoo.elide.jsonapi.models.JsonApiDocument in project elide by yahoo.
the class IncludedProcessorTest method testNoQueryIncludeParams.
@Test
public void testNoQueryIncludeParams() throws Exception {
JsonApiDocument jsonApiDocument = new JsonApiDocument();
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
queryParams.put("unused", Collections.emptyList());
testScope.setQueryParams(queryParams);
includedProcessor.execute(jsonApiDocument, parentRecord1, queryParams);
assertNull(jsonApiDocument.getIncluded(), "Included Processor adds no resources when not given query params");
}
use of com.yahoo.elide.jsonapi.models.JsonApiDocument in project faf-java-api by FAForever.
the class LeaderboardControllerTest method getLadder1v1.
@Test
public void getLadder1v1() throws Exception {
when(leaderboardService.getLadder1v1Leaderboard(1, 100)).thenReturn(new PageImpl<>(Arrays.asList(new Ladder1v1LeaderboardEntry().setId(14).setPlayerName("JUnit 14").setMean(1500f).setDeviation(51f).setNumGames((short) 514).setRank(1).setWonGames((short) 270), new Ladder1v1LeaderboardEntry().setId(5).setPlayerName("JUnit 5").setMean(1400f).setDeviation(67f).setNumGames((short) 65).setRank(2).setWonGames((short) 32))));
CompletableFuture<JsonApiDocument> result = instance.getLadder1v1(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("wonGames"), is((short) 270));
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("wonGames"), is((short) 32));
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 PlayerEventsControllerTest method update.
@Test
public void update() throws Exception {
AchievementUpdateRequest[] updateRequests = new AchievementUpdateRequest[] { new AchievementUpdateRequest(1, "111", Operation.INCREMENT, 7), new AchievementUpdateRequest(1, "222", Operation.INCREMENT, 19), new AchievementUpdateRequest(1, "333", Operation.SET_STEPS_AT_LEAST, 9), new AchievementUpdateRequest(1, "444", Operation.SET_STEPS_AT_LEAST, 13), new AchievementUpdateRequest(1, "555", Operation.UNLOCK, 11), new AchievementUpdateRequest(1, "666", Operation.UNLOCK, 17) };
when(achievementService.increment(anyInt(), any(), anyInt())).thenAnswer(invocation -> new UpdatedAchievementResponse(invocation.getArgument(1), true, AchievementState.UNLOCKED, invocation.getArgument(2)));
when(achievementService.setStepsAtLeast(anyInt(), any(), anyInt())).thenAnswer(invocation -> new UpdatedAchievementResponse(invocation.getArgument(1), true, AchievementState.UNLOCKED, invocation.getArgument(2)));
when(achievementService.unlock(anyInt(), any())).thenAnswer(invocation -> new UpdatedAchievementResponse(invocation.getArgument(1), true, AchievementState.UNLOCKED));
JsonApiDocument result = instance.update(updateRequests);
verify(achievementService).increment(1, "111", 7);
verify(achievementService).increment(1, "222", 19);
verify(achievementService).setStepsAtLeast(1, "333", 9);
verify(achievementService).setStepsAtLeast(1, "444", 13);
verify(achievementService).unlock(1, "555");
verify(achievementService).unlock(1, "666");
assertThat(result.getData().get(), hasSize(6));
}
Aggregations