コード例 #1
0
  @Test
  public void testNoQueryIncludeParams() throws Exception {
    JsonApiDocument jsonApiDocument = new JsonApiDocument();

    MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
    queryParams.put("unused", Collections.emptyList());
    includedProcessor.execute(jsonApiDocument, parentRecord1, Optional.of(queryParams));

    Assert.assertNull(
        jsonApiDocument.getIncluded(),
        "Included Processor adds no resources when not given query params");
  }
コード例 #2
0
  @Test
  public void testNoQueryParams() throws Exception {
    JsonApiDocument jsonApiDocument = new JsonApiDocument();

    MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
    queryParams.put("include", Arrays.asList("children", "spouses"));
    includedProcessor.execute(jsonApiDocument, parentRecord1, Optional.empty());

    Assert.assertNull(
        jsonApiDocument.getIncluded(),
        "Included Processor adds no resources when not given query params");
  }
コード例 #3
0
  @Test
  public void testExecuteSingleRelation() throws Exception {
    JsonApiDocument jsonApiDocument = new JsonApiDocument();

    MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
    queryParams.put("include", Collections.singletonList("children"));
    includedProcessor.execute(jsonApiDocument, parentRecord1, Optional.of(queryParams));

    List<Resource> expectedIncluded = Collections.singletonList(childRecord1.toResource());
    List<Resource> actualIncluded = jsonApiDocument.getIncluded();

    Assert.assertEquals(
        actualIncluded,
        expectedIncluded,
        "Included Processor added single requested resource from 'include' query param");
  }
コード例 #4
0
  @Test
  public void testExecuteMultipleNestedRelations() throws Exception {
    JsonApiDocument jsonApiDocument = new JsonApiDocument();

    MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
    queryParams.put("include", Collections.singletonList("children.friends"));
    includedProcessor.execute(jsonApiDocument, parentRecord3, Optional.of(queryParams));

    Set<Resource> expectedIncluded =
        Sets.newHashSet(
            childRecord1.toResource(),
            childRecord2.toResource(),
            childRecord3.toResource(),
            childRecord4.toResource());
    Set<Resource> actualIncluded = new HashSet<>(jsonApiDocument.getIncluded());

    Assert.assertEquals(
        actualIncluded,
        expectedIncluded,
        "Included Processor added multiple nested requested resource collections from 'include' query param");
  }
コード例 #5
0
  @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"));
    includedProcessor.execute(jsonApiDocument, parents, Optional.of(queryParams));

    List<Resource> expectedIncluded =
        Arrays.asList(childRecord1.toResource(), childRecord2.toResource());
    List<Resource> actualIncluded = jsonApiDocument.getIncluded();

    Assert.assertEquals(
        actualIncluded,
        expectedIncluded,
        "Included Processor added requested resource from all records");
  }