Exemplo n.º 1
0
  @Test
  public void testUpdateWithEmptyObjectArray() throws Exception {
    UpdateAnalyzedStatement.NestedAnalyzedStatement analysis =
        analyze("update users set friends=? where other_id=0", new Object[] {new Map[0], 0})
            .nestedStatements()
            .get(0);

    Literal friendsLiteral =
        (Literal)
            analysis
                .assignments()
                .get(new Reference(USER_TABLE_INFO.getReferenceInfo(new ColumnIdent("friends"))));
    assertThat(friendsLiteral.valueType().id(), is(ArrayType.ID));
    assertEquals(DataTypes.OBJECT, ((ArrayType) friendsLiteral.valueType()).innerType());
    assertThat(((Object[]) friendsLiteral.value()).length, is(0));
  }
 @Test
 public void testEvaluateCastFromInvalidString() throws Exception {
   expectedException.expect(IllegalArgumentException.class);
   expectedException.expectMessage("Cannot convert \"POINTE ()\" to geo_shape");
   ToGeoFunction fn = getFunction(FUNCTION_NAME, DataTypes.STRING);
   fn.evaluate(Literal.newLiteral(DataTypes.STRING, INVALID_STR));
 }
  @Test
  public void testEvaluateCastFromInvalidObject() throws Exception {
    ToGeoFunction fn = getFunction(FUNCTION_NAME, DataTypes.OBJECT);

    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage(allOf(startsWith("Cannot convert"), endsWith("to geo_shape")));
    fn.evaluate(Literal.newLiteral(DataTypes.OBJECT, INVALID_OBJECT));
  }
 @Test
 public void testEvaluateCastFromString() throws Exception {
   ToGeoFunction fn = getFunction(FUNCTION_NAME, DataTypes.STRING);
   Object val = fn.evaluate(Literal.newLiteral(DataTypes.STRING, VALID_STR));
   assertThat(val, instanceOf(Map.class));
   assertThat(
       (Map<String, Object>) val,
       allOf(
           hasEntry("type", (Object) "Point"),
           hasEntry("coordinates", (Object) new double[] {0.0, 0.1})));
 }
  @Test
  public void testEvaluateCastFromObject() throws Exception {
    ToGeoFunction fn = getFunction(FUNCTION_NAME, DataTypes.OBJECT);

    Object val = fn.evaluate(Literal.newLiteral(DataTypes.OBJECT, VALID_OBJECT));
    assertThat(val, instanceOf(Map.class));
    Map<String, Object> valMap = (Map<String, Object>) val;
    assertThat(valMap.size(), is(2));
    assertThat(
        valMap,
        Matchers.allOf(
            Matchers.<String, Object>hasEntry("type", "Polygon"),
            Matchers.hasEntry("coordinates", VALID_OBJECT.get("coordinates"))));
  }