Ejemplo n.º 1
0
 @Test
 public void testUnsupportedParsing() throws Exception {
   Map value =
       new ObjectMapper().readValue(getClass().getResourceAsStream("attachment.json"), Map.class);
   Field fl = Field.parseField(value);
   assertEquals("person", fl.name());
   assertEquals(0, fl.properties().length);
 }
Ejemplo n.º 2
0
 @Test
 public void testCompletionParsing() throws Exception {
   Map value =
       new ObjectMapper().readValue(getClass().getResourceAsStream("completion.json"), Map.class);
   Field fl = Field.parseField(value);
   assertEquals("song", fl.name());
   Field[] props = fl.properties();
   assertEquals(1, props.length);
   assertEquals("name", props[0].name());
 }
Ejemplo n.º 3
0
 @Test
 public void testMultiFieldParsing() throws Exception {
   Map value =
       new ObjectMapper().readValue(getClass().getResourceAsStream("multi_field.json"), Map.class);
   Field fl = Field.parseField(value);
   assertEquals("tweet", fl.name());
   assertEquals(1, fl.properties().length);
   Field nested = fl.properties()[0];
   assertEquals("name", nested.name());
   assertEquals(FieldType.STRING, nested.type());
 }
Ejemplo n.º 4
0
 @Test(expected = EsHadoopIllegalArgumentException.class)
 public void testMultiFieldWithoutDefaultFieldAndMultiTypesParsing() throws Exception {
   Map value =
       new ObjectMapper()
           .readValue(
               getClass().getResourceAsStream("multi_field_no_default_multi_types.json"),
               Map.class);
   Field fl = Field.parseField(value);
   assertEquals("tweet", fl.name());
   assertEquals(1, fl.properties().length);
   Field nested = fl.properties()[0];
   assertEquals("name", nested.name());
   assertEquals(FieldType.STRING, nested.type());
 }
Ejemplo n.º 5
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"));
  }
Ejemplo n.º 6
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()));
  }
Ejemplo n.º 7
0
 @Test
 public void testBasicParsing() throws Exception {
   Map value =
       new ObjectMapper().readValue(getClass().getResourceAsStream("basic.json"), Map.class);
   Field fl = Field.parseField(value);
 }
Ejemplo n.º 8
0
 @Test
 public void testNestedObjectParsing() throws Exception {
   Map value =
       new ObjectMapper().readValue(getClass().getResourceAsStream("nested.json"), Map.class);
   Field fl = Field.parseField(value);
   assertEquals("artiststimestamp", fl.name());
   Field[] properties = fl.properties();
   Field first = properties[0];
   assertEquals("date", first.name());
   assertEquals(FieldType.DATE, first.type());
   Field second = properties[1];
   assertEquals(FieldType.OBJECT, second.type());
   assertEquals("links", second.name());
   Field[] secondProps = second.properties();
   assertEquals("url", secondProps[0].name());
   assertEquals(FieldType.STRING, secondProps[0].type());
 }
Ejemplo n.º 9
0
 @Test
 public void testIpParsing() throws Exception {
   Map value = new ObjectMapper().readValue(getClass().getResourceAsStream("ip.json"), Map.class);
   Field fl = Field.parseField(value);
   assertEquals(1, fl.properties().length);
 }