コード例 #1
0
  @Test
  public void testFieldValidation() throws Exception {
    Map value =
        new ObjectMapper().readValue(getClass().getResourceAsStream("nested.json"), Map.class);
    Field fl = Field.parseField(value);

    List<String>[] findFixes = MappingUtils.findTypos(Collections.singletonList("nam"), fl);
    assertThat(findFixes[1], contains("name"));

    findFixes = MappingUtils.findTypos(Collections.singletonList("link.url"), fl);
    assertThat(findFixes[1], contains("links.url"));

    findFixes = MappingUtils.findTypos(Collections.singletonList("ulr"), fl);
    assertThat(findFixes[1], contains("links.url"));

    findFixes = MappingUtils.findTypos(Collections.singletonList("likn"), fl);
    assertThat(findFixes[1], contains("links"));

    findFixes = MappingUtils.findTypos(Collections.singletonList("_uid"), fl);
    assertThat(findFixes, is(nullValue()));
  }
コード例 #2
0
  @Test
  public void testFieldInclude() throws Exception {
    Map value =
        new ObjectMapper().readValue(getClass().getResourceAsStream("nested.json"), Map.class);
    Field fl = Field.parseField(value);

    Field filtered =
        MappingUtils.filter(fl, Collections.singleton("*a*e"), Collections.<String>emptyList());

    assertThat(fl.name(), is(filtered.name()));
    assertThat(fl.type(), is(filtered.type()));

    Field[] props = filtered.properties();

    assertThat(props.length, is(2));
    assertThat(props[0].name(), is("date"));
    assertThat(props[1].name(), is("name"));
  }