Example #1
0
  @Test
  public void testToStringFromStringCoherente() throws Exception {
    Value v = ValueFactory.createValue(1300.5566d);
    assertTrue(
        (v.equals(ValueFactory.createValueByType(v.toString(), Type.DOUBLE))).getAsBoolean());

    v = ValueFactory.createValue(13.5f);
    assertTrue((v.equals(ValueFactory.createValueByType(v.toString(), Type.FLOAT))).getAsBoolean());

    v = ValueFactory.createValue(1300L);
    assertTrue((v.equals(ValueFactory.createValueByType(v.toString(), Type.LONG))).getAsBoolean());

    v = ValueFactory.createValue(false);
    assertTrue(
        (v.equals(ValueFactory.createValueByType(v.toString(), Type.BOOLEAN))).getAsBoolean());

    v = ValueFactory.createValue("hola");
    assertTrue(
        (v.equals(ValueFactory.createValueByType(v.toString(), Type.STRING))).getAsBoolean());

    Calendar c = Calendar.getInstance();

    // month is 0-based
    c.set(1980, 8, 5, 0, 0, 0);
    c.set(Calendar.MILLISECOND, 0);

    v = ValueFactory.createValue(d);
    assertTrue((v.equals(ValueFactory.createValueByType(v.toString(), Type.DATE))).getAsBoolean());

    v = ValueFactory.createValue(15);
    assertTrue((v.equals(ValueFactory.createValueByType(v.toString(), Type.INT))).getAsBoolean());

    v = ValueFactory.createValue((short) 13);
    assertTrue((v.equals(ValueFactory.createValueByType(v.toString(), Type.SHORT))).getAsBoolean());

    v = ValueFactory.createValue((byte) 5);
    assertTrue((v.equals(ValueFactory.createValueByType(v.toString(), Type.BYTE))).getAsBoolean());

    v = ValueFactory.createValue(new byte[] {4, 5, 7, 8, 3, 8});
    assertTrue(
        (v.equals(ValueFactory.createValueByType(v.toString(), Type.BINARY))).getAsBoolean());

    c.set(1970, 0, 1, 22, 45, 20);
    c.set(Calendar.MILLISECOND, 0);

    Time t = new Time(c.getTime().getTime());
    v = ValueFactory.createValue(t);
    assertTrue((v.equals(ValueFactory.createValueByType(v.toString(), Type.TIME))).getAsBoolean());

    v = ValueFactory.createValue(new Timestamp(2465));
    assertTrue(
        (v.equals(ValueFactory.createValueByType(v.toString(), Type.TIMESTAMP))).getAsBoolean());
  }
Example #2
0
 @Test(expected = ParseException.class)
 public void testEmptyStringIsNotValidGeometry() throws Exception {
   ValueFactory.createValueByType("", Type.GEOMETRY);
 }
Example #3
0
  /**
   * DOCUMENT ME!
   *
   * @throws Exception DOCUMENT ME!
   */
  @Test
  public void testCreateByType() throws Exception {
    assertTrue(
        (ValueFactory.createValueByType("1", Type.LONG).equals(ValueFactory.createValue(1L)))
            .getAsBoolean());

    assertTrue(
        (ValueFactory.createValueByType("true", Type.BOOLEAN)
                .equals(ValueFactory.createValue(true)))
            .getAsBoolean());
    assertTrue(
        (ValueFactory.createValueByType("false", Type.BOOLEAN)
                .equals(ValueFactory.createValue(false)))
            .getAsBoolean());

    assertTrue(
        (ValueFactory.createValueByType("carajo", Type.STRING)
                .equals(ValueFactory.createValue("carajo")))
            .getAsBoolean());

    Calendar c = Calendar.getInstance();

    // month is 0-based
    c.set(1980, 8, 5, 0, 0, 0);
    c.set(Calendar.MILLISECOND, 0);

    assertTrue(
        (ValueFactory.createValueByType(d.toString(), Type.DATE)
                .equals(ValueFactory.createValue(d)))
            .getAsBoolean());

    assertTrue(
        (ValueFactory.createValueByType(
                    NumberFormat.getNumberInstance(Locale.ROOT).format(1.1), Type.DOUBLE)
                .equals(ValueFactory.createValue(1.1d)))
            .getAsBoolean());

    assertTrue(
        (ValueFactory.createValueByType("1", Type.INT).equals(ValueFactory.createValue(1)))
            .getAsBoolean());

    assertTrue(
        (ValueFactory.createValueByType(
                    NumberFormat.getNumberInstance(Locale.ROOT).format(1.1), Type.FLOAT)
                .equals(ValueFactory.createValue(1.1f)))
            .getAsBoolean());

    assertTrue(
        (ValueFactory.createValueByType("1", Type.SHORT).equals(ValueFactory.createValue(1)))
            .getAsBoolean());

    assertTrue(
        (ValueFactory.createValueByType("1", Type.BYTE).equals(ValueFactory.createValue(1)))
            .getAsBoolean());

    byte[] array = new byte[] {(byte) 255, (byte) 160, (byte) 7};
    assertTrue(
        (ValueFactory.createValueByType("FFA007", Type.BINARY)
                .equals(ValueFactory.createValue(array)))
            .getAsBoolean());

    c.set(1970, 0, 1, 22, 45, 00);
    c.set(Calendar.MILLISECOND, 0);

    Time t = new Time(c.getTime().getTime());
    assertTrue(
        (ValueFactory.createValueByType(
                    new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(t), Type.TIME)
                .equals(ValueFactory.createValue(t)))
            .getAsBoolean());

    c.set(1970, 0, 1, 22, 45, 20);
    c.set(Calendar.MILLISECOND, 2345);

    Timestamp ts = new Timestamp(c.getTime().getTime());
    assertTrue(
        (ValueFactory.createValueByType(ts.toString(), Type.TIMESTAMP)
                .equals(ValueFactory.createValue(ts)))
            .getAsBoolean());
  }