Beispiel #1
0
  @Test
  public void timestamp() throws SQLException {
    connectWithJulianDayModeActivated();
    long now = System.currentTimeMillis();
    Timestamp d1 = new Timestamp(now);
    Date d2 = new Date(now);
    Time d3 = new Time(now);

    stat.execute("create table t (c1);");
    PreparedStatement prep = conn.prepareStatement("insert into t values (?);");
    prep.setTimestamp(1, d1);
    prep.executeUpdate();

    ResultSet rs = stat.executeQuery("select c1 from t;");
    assertTrue(rs.next());
    assertEquals(d1, rs.getTimestamp(1));

    rs = stat.executeQuery("select date(c1, 'localtime') from t;");
    assertTrue(rs.next());
    assertEquals(d2.toString(), rs.getString(1));

    rs = stat.executeQuery("select time(c1, 'localtime') from t;");
    assertTrue(rs.next());
    assertEquals(d3.toString(), rs.getString(1));

    rs = stat.executeQuery("select strftime('%Y-%m-%d %H:%M:%f', c1, 'localtime') from t;");
    assertTrue(rs.next());
    // assertEquals(d1.toString(), rs.getString(1)); // ms are not occurate...
  }
  @Before
  public void setUp() {
    controller = new Controller(35.0);
    Calendar cal = Calendar.getInstance();
    cal.set(2012, Calendar.JANUARY, 1, 1, 1, 0);

    Date d1, d2;
    d1 = cal.getTime();
    t1 = d1.getTime();

    cal.set(2012, Calendar.JANUARY, 1, 1, 1, 2);
    d2 = cal.getTime();
    t2 = d2.getTime();
  }
Beispiel #3
0
  @Test
  public void date2() throws SQLException {
    Date d1 = new Date(1092941466000L);
    stat.execute("create table t (c1);");
    PreparedStatement prep =
        conn.prepareStatement("insert into t values (datetime(?/1000, 'unixepoch'));");
    prep.setDate(1, d1);
    prep.executeUpdate();

    ResultSet rs = stat.executeQuery("select strftime('%s', c1) * 1000 from t;");
    assertTrue(rs.next());
    assertEquals(d1.getTime(), rs.getLong(1));
    assertTrue(rs.getDate(1).equals(d1));
  }
  private void assertTableContent(
      final JdbcContentPersistenceService tested,
      final String sysContentType,
      final String id,
      final Date expectedUpdated) {
    final String tablename = tested.getTableName(sysContentType);

    try (final Connection conn = this.getTested().searchiskoDs.getConnection();
        final PreparedStatement statement =
            conn.prepareStatement(
                String.format(
                    "select sys_content_type, updated from %s where id = ?", tablename))) {
      statement.setString(1, id);
      try (final ResultSet rs = statement.executeQuery()) {
        Assert.assertTrue(rs.next());
        Assert.assertEquals(sysContentType, rs.getString(1));
        Timestamp actualTimestamp = rs.getTimestamp(2);
        if (expectedUpdated != null) {
          Assert.assertEquals(new Timestamp(expectedUpdated.getTime()), actualTimestamp);
        } else {
          Assert.assertNotNull(actualTimestamp);
        }
      }
    } catch (SQLException e) {
      Assert.fail(e.getMessage());
    }
  }
Beispiel #5
0
  @SuppressWarnings("deprecation")
  @Test
  public void date() throws SQLException {
    connectWithJulianDayModeActivated();
    Date d1 = new Date(System.currentTimeMillis());

    stat.execute("create table t (c1);");
    PreparedStatement prep = conn.prepareStatement("insert into t values(?);");
    prep.setDate(1, d1);
    prep.executeUpdate();

    ResultSet rs = stat.executeQuery("select c1 from t;");
    assertTrue(rs.next());
    assertEquals(d1.getYear(), rs.getDate(1).getYear());
    assertEquals(d1.getMonth(), rs.getDate(1).getMonth());
    assertEquals(d1.getDay(), rs.getDate(1).getDay());
    rs.close();
  }
Beispiel #6
0
  @Test
  public void date1() throws SQLException {
    Date d1 = new Date(987654321);

    stat.execute("create table t (c1);");
    PreparedStatement prep = conn.prepareStatement("insert into t values(?);");
    prep.setDate(1, d1);
    prep.executeUpdate();
    prep.setDate(1, null);
    prep.executeUpdate();

    ResultSet rs = stat.executeQuery("select c1 from t;");
    assertTrue(rs.next());
    assertEquals(d1.getTime(), rs.getLong(1));
    assertTrue(rs.getDate(1).equals(d1));
    assertTrue(rs.next());
    assertEquals(null, rs.getDate(1));
    rs.close();
  }
 /** Test if a field, other than the primary key, of a BO instance can be modified. */
 @Test
 public void ModifyOrdersCheck() {
   DeployedModelDescription model =
       sf.getQueryService().getModels(DeployedModelQuery.findActiveForId(MODEL_NAME2)).get(0);
   BusinessObject bo = createOrder(model, 777);
   @SuppressWarnings("unchecked")
   final Map<String, Object> order = (Map<String, Object>) bo.getValues().get(0).getValue();
   Date date = (Date) order.get("date");
   order.put("date", new Date(date.getTime() + TIME_LAPSE));
   sf.getWorkflowService()
       .updateBusinessObjectInstance(
           new QName(model.getId(), "Order").toString(), (Serializable) order);
   BusinessObjectQuery query =
       BusinessObjectQuery.findWithPrimaryKey(new QName(model.getId(), "Order").toString(), 777);
   query.setPolicy(new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_VALUES));
   BusinessObjects bos = sf.getQueryService().getAllBusinessObjects(query);
   bo = bos.get(0);
   @SuppressWarnings("unchecked")
   Map<String, Object> updatedOrder = (Map<String, Object>) bo.getValues().get(0).getValue();
   Date updatedDate = (Date) updatedOrder.get("date");
   Assert.assertEquals("Time difference", TIME_LAPSE, updatedDate.getTime() - date.getTime());
 }