Exemplo n.º 1
0
 @Test
 public void testBuilderDeprecated() throws Exception {
   DateTimeValue.Builder builder = DateTimeValue.builder(CONTENT);
   DateTimeValue value = builder.meaning(1).excludeFromIndexes(true).build();
   assertEquals(CONTENT, value.get());
   assertEquals(1, value.meaning());
   assertTrue(value.excludeFromIndexes());
 }
Exemplo n.º 2
0
 @SuppressWarnings("deprecation")
 @Test
 public void testBuilder() throws Exception {
   DateTimeValue.Builder builder = DateTimeValue.newBuilder(CONTENT);
   DateTimeValue value = builder.setMeaning(1).setExcludeFromIndexes(true).build();
   assertEquals(CONTENT, value.get());
   assertEquals(1, value.getMeaning());
   assertTrue(value.excludeFromIndexes());
 }
  /** This method should fail because the value is no close to. */
  @Test
  @NeedReload
  public void should_fail_because_value_is_not_close_to() {
    Table table = new Table(source, "test");
    Changes changes = new Changes(table).setStartPointNow();
    update("update test set var14 = 1 where var1 = 1");
    changes.setEndPointNow();

    try {
      assertThat(changes)
          .change()
          .column("var10")
          .valueAtEndPoint()
          .isCloseTo(
              DateTimeValue.of(DateValue.of(2014, 5, 24), TimeValue.of(9, 46, 31)),
              TimeValue.of(0, 0, 0, 1));
      fail("An exception must be raised");
    } catch (AssertionError e) {
      Assertions.assertThat(e.getMessage())
          .isEqualTo(
              String.format(
                  "[Value at end point of Column at index 9 (column name : VAR10) of Change at index 0 (with primary key : [1]) of Changes on TEST table of 'sa/jdbc:h2:mem:test' source] %n"
                      + "Expecting:%n"
                      + "  <2014-05-24T09:46:30.000000000>%n"
                      + "to be close to: %n"
                      + "  <2014-05-24T09:46:31.000000000> %n"
                      + " with tolerance <00:00:00.000000001>"));
    }
    try {
      assertThat(table)
          .column("var10")
          .value()
          .isCloseTo(
              DateTimeValue.of(DateValue.of(2014, 5, 24), TimeValue.of(9, 46, 31)),
              TimeValue.of(0, 0, 0, 100));
      fail("An exception must be raised");
    } catch (AssertionError e) {
      Assertions.assertThat(e.getMessage())
          .isEqualTo(
              String.format(
                  "[Value at index 0 of Column at index 9 (column name : VAR10) of TEST table] %n"
                      + "Expecting:%n"
                      + "  <2014-05-24T09:46:30.000000000>%n"
                      + "to be close to: %n"
                      + "  <2014-05-24T09:46:31.000000000> %n"
                      + " with tolerance <00:00:00.000000100>"));
    }
  }
Exemplo n.º 4
0
  /**
   * Factory method which tries to parse an untyped value.
   *
   * @param pTyped
   * @param pUriStr
   * @return <code>Value</code> instance
   * @throws IllegalArgumentException if parsing failed.
   */
  public static Value parse(boolean pTyped, URIString pUriStr) throws IllegalArgumentException {
    // TODO: tracing TRC.debug(uriStr.toString());
    if (pTyped) return parseTypedValue(pUriStr);
    URIString uriStr = pUriStr.deepCopy();
    Value value;
    try {
      StringValue strVal = (StringValue) StringValue.parse(uriStr);

      // string like value
      // is this string an instance reference?
      try {
        URI ref = URI.parseRef(new URIString(strVal.toString()), false);
        value = new ReferenceValue(ref);
      } catch (IllegalArgumentException e) {
        if ((value = DateTimeValue.parse(strVal.toString())) == null) {
          // if not dateTimeValue, it is stringvalue
          value = strVal;
        }
      }
      pUriStr.set(uriStr);
      return value;
    } catch (IllegalArgumentException e) {
      // non string like value
      if ((value = IntegerValue.parse(uriStr)) != null
          || (value = RealValue.parse(uriStr)) != null
          || (value = BooleanValue.parse(uriStr)) != null
          || (value = CharValue.parse(uriStr)) != null) {
        pUriStr.set(uriStr);
        return value;
      }
      String msg = "Failed to parse untyped value!\n" + uriStr.markPosition();
      throw new IllegalArgumentException(msg);
    }
  }
Exemplo n.º 5
0
 private static Value parseTypedDateTime(URIString pUriStr) throws IllegalArgumentException {
   Value strVal;
   try {
     strVal = StringValue.parse(pUriStr);
   } catch (IllegalArgumentException e) {
     String msg =
         "Failed to retrieve typed datetime string!\n"
             + pUriStr.markPosition()
             + "Nested message is:\n"
             + e.getMessage();
     throw new IllegalArgumentException(msg);
   }
   return DateTimeValue.parse(strVal.toString(), true);
 }
  /** This method tests the {@code isCloseTo} assertion method. */
  @Test
  @NeedReload
  public void test_is_close_to() {
    Table table = new Table(source, "test");
    Changes changes = new Changes(table).setStartPointNow();
    update("update test set var14 = 1 where var1 = 1");
    changes.setEndPointNow();

    ChangeColumnValueAssert changeColumnValueAssert =
        assertThat(changes).change().column("var10").valueAtEndPoint();
    ChangeColumnValueAssert changeColumnValueAssert2 =
        changeColumnValueAssert.isCloseTo(
            DateTimeValue.of(DateValue.of(2014, 5, 24), TimeValue.of(9, 46, 30)),
            TimeValue.of(0, 0, 0));
    Assertions.assertThat(changeColumnValueAssert).isSameAs(changeColumnValueAssert2);

    TableColumnValueAssert tableColumnValueAssert = assertThat(table).column("var10").value();
    TableColumnValueAssert tableColumnValueAssert2 =
        tableColumnValueAssert.isCloseTo(
            DateTimeValue.of(DateValue.of(2014, 5, 24), TimeValue.of(9, 46, 30)),
            TimeValue.of(0, 0, 0));
    Assertions.assertThat(tableColumnValueAssert).isSameAs(tableColumnValueAssert2);
  }
Exemplo n.º 7
0
 @Test
 public void testOf() throws Exception {
   DateTimeValue value = DateTimeValue.of(CONTENT);
   assertEquals(CONTENT, value.get());
   assertFalse(value.excludeFromIndexes());
 }
Exemplo n.º 8
0
 @Test
 public void testToBuilder() throws Exception {
   DateTimeValue value = DateTimeValue.of(CONTENT);
   assertEquals(value, value.toBuilder().build());
 }