Esempio n. 1
0
 /** 最初の日付の文字列解析。 */
 @Test
 public void parse_zero() {
   Date date = Date.valueOf("00010101", Date.Format.SIMPLE);
   assertThat(date.getYear(), is(1));
   assertThat(date.getMonth(), is(1));
   assertThat(date.getDay(), is(1));
 }
Esempio n. 2
0
  /** ************ Helper stuff ***************** */
  private void createAndFillUserTable() {

    int rowCount = 10000;
    sql2o
        .createQuery(
            "create table User(\n"
                + "id int identity primary key,\n"
                + "name varchar(20),\n"
                + "email varchar(255),\n"
                + "text varchar(100))")
        .executeUpdate();

    Query insQuery =
        sql2o.createQuery("insert into User(name, email, text) values (:name, :email, :text)");
    Date before = new Date();
    for (int idx = 0; idx < rowCount; idx++) {
      insQuery
          .addParameter("name", "a name " + idx)
          .addParameter("email", String.format("*****@*****.**", idx))
          .addParameter("text", "some text")
          .addToBatch();
    }
    insQuery.executeBatch();
    Date after = new Date();
    Long span = after.getTime() - before.getTime();

    System.out.println(
        String.format("inserted %d rows into User table. Time used: %s ms", rowCount, span));

    insertIntoUsers += rowCount;
  }
Esempio n. 3
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...
  }
Esempio n. 4
0
 /** parses standard date string. */
 @Test
 public void parse_standard() {
   Date date = Date.valueOf("1234-01-02", Date.Format.STANDARD);
   assertThat(date.getYear(), is(1234));
   assertThat(date.getMonth(), is(1));
   assertThat(date.getDay(), is(2));
 }
Esempio n. 5
0
 /** 単純な文字列解析。 */
 @Test
 public void parse() {
   Date date = Date.valueOf("12340102", Date.Format.SIMPLE);
   assertThat(date.getYear(), is(1234));
   assertThat(date.getMonth(), is(1));
   assertThat(date.getDay(), is(2));
 }
Esempio n. 6
0
 /** 大きな日付の文字列解析。 */
 @Test
 public void parse_big() {
   Date date = Date.valueOf("29991231", Date.Format.SIMPLE);
   assertThat(date.getYear(), is(2999));
   assertThat(date.getMonth(), is(12));
   assertThat(date.getDay(), is(31));
 }
Esempio n. 7
0
 /** optionの解析。 */
 @Test
 public void parse_option() {
   StringOption option = new StringOption("20100615");
   Date date = Date.valueOf(option, Date.Format.SIMPLE);
   assertThat(date.getYear(), is(2010));
   assertThat(date.getMonth(), is(6));
   assertThat(date.getDay(), is(15));
 }
Esempio n. 8
0
 public void convert() {
   // param dateString looks like:2016.2.23
   String dateString = "2016.2.23";
   Date date = new Date();
   DateFormat sdf = new SimpleDateFormat("yyyy.M.d");
   try {
     date = sdf.parse(dateString);
   } catch (ParseException e) {
     e.printStackTrace();
   }
   Timestamp timestamp = new Timestamp(date.getTime());
   System.out.println(timestamp);
 }
Esempio n. 9
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));
  }
  @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();
  }
Esempio n. 11
0
 public void orderTest() {
   Customer customer = customerDAO.getCustomerById(3);
   List<Commodity> commodityList = commoDAO.getCommoditiesByIdString("2;3;4");
   List<OrderCommodityRel> relationLsit = CommodityListTools.commoToRel(commodityList);
   Order order = new Order(customer, relationLsit, 100);
   Map<Integer, Integer> map = new HashMap<Integer, Integer>();
   map.put(2, 2);
   map.put(3, 4);
   map.put(4, 4);
   order.setBuyNum(map);
   Date date = new Date();
   order.setOrderTime(new Timestamp(date.getTime()));
   orderDAO.createOrder(order);
   System.out.println(order.getOrderId());
 }
 @Given("^I wait until the statisticaltest status code is either (\\d) or (\\d) less than (\\d+)$")
 public void I_wait_until_statisticaltest_status_code_is(int code1, int code2, int secs)
     throws AuthenticationException {
   Long code = (Long) ((JSONObject) context.statisticaltest.get("status")).get("code");
   GregorianCalendar start = new GregorianCalendar();
   start.add(Calendar.SECOND, secs);
   Date end = start.getTime();
   while (code.intValue() != code1 && code.intValue() != code2) {
     try {
       Thread.sleep(3000);
     } catch (InterruptedException e) {
     }
     assertTrue("Time exceded ", end.after(new Date()));
     I_get_the_statisticaltest((String) context.statisticaltest.get("resource"));
     code = (Long) ((JSONObject) context.statisticaltest.get("status")).get("code");
   }
   assertEquals(code1, code.intValue());
 }
Esempio n. 13
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();
  }
  @Test
  public void testDecodeQualificationForXML() throws IOException {
    assumeTrue(TestUtil.testdataAvailable());

    Date startDate = Calendar.getInstance().getTime();
    DecodeQualification decodeQualification =
        plugIn.getDecodeQualification(
            TestUtil.getTestFile(productsFolder + "dimap/test_ST4_MT.xml"));
    assertEquals(DecodeQualification.UNABLE, decodeQualification);
    decodeQualification =
        plugIn.getDecodeQualification(
            TestUtil.getTestFile(productsFolder + "SPOT4_HRVIR1_XS_88888888_N1A.tgz"));
    assertEquals(DecodeQualification.INTENDED, decodeQualification);
    Date endDate = Calendar.getInstance().getTime();
    assertTrue(
        "The decoding time for the file is too big!",
        (endDate.getTime() - startDate.getTime()) / 1000 < 30); // 30 sec
  }
Esempio n. 15
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();
  }
Esempio n. 16
0
  public void planTest() {
    Worker worker = workerDAO.getWorkerById(6);
    Department department = depDAO.getDepartment(2);
    Date date = new Date();
    new Timestamp(date.getTime());

    // plan creating
    Plan plan = new Plan();
    plan.setWorker(worker); // worker
    plan.setDepartment(department); // department
    // set several timestamp attributes
    plan.setCreateTime(new Timestamp(date.getTime()));
    plan.setBeginTime(new Timestamp(date.getTime()));
    plan.setEndTime(new Timestamp(date.getTime()));
    // planCommodityRel creating
    PlanCommodityRel relation1 = new PlanCommodityRel();
    Commodity commodity1 = commoDAO.getCommodityById(1);
    relation1.setCommodity(commodity1);
    relation1.setPlan(plan);
    relation1.setPlanNum(50);
    relation1.setSinglePrice(8);

    PlanCommodityRel relation2 = new PlanCommodityRel();
    Commodity commodity2 = commoDAO.getCommodityById(2);
    relation2.setCommodity(commodity2);
    relation2.setPlan(plan);
    relation2.setPlanNum(50);
    relation2.setSinglePrice(8);

    PlanCommodityRel relation3 = new PlanCommodityRel();
    Commodity commodity3 = commoDAO.getCommodityById(3);
    relation3.setCommodity(commodity3);
    relation3.setPlan(plan);
    relation3.setPlanNum(50);
    relation3.setSinglePrice(8);

    plan.getPlanCommodityRelList().add(relation1);
    plan.getPlanCommodityRelList().add(relation2);
    plan.getPlanCommodityRelList().add(relation3);

    planDAO.createPlan(plan);
  }
 @Test
 public void testDate() {
   assertTrue(eval(builder.profileProperty("properties.lastVisit").equalTo(lastVisit).build()));
   assertTrue(
       eval(
           builder
               .profileProperty("properties.lastVisit")
               .greaterThan(new Date(lastVisit.getTime() - 10000))
               .build()));
   assertTrue(
       eval(
           builder
               .profileProperty("properties.lastVisit")
               .lessThan(new Date(lastVisit.getTime() + 10000))
               .build()));
   assertTrue(
       eval(
           builder
               .profileProperty("properties.lastVisit")
               .in(
                   new Date(lastVisit.getTime() + 10000),
                   new Date(lastVisit.getTime() - 10000),
                   lastVisit)
               .build()));
   assertTrue(
       eval(
           builder
               .profileProperty("properties.lastVisit")
               .notIn(new Date(lastVisit.getTime() + 10000), new Date(lastVisit.getTime() - 10000))
               .build()));
   assertFalse(
       eval(
           builder
               .profileProperty("properties.lastVisit")
               .notIn(
                   new Date(lastVisit.getTime() + 10000),
                   new Date(lastVisit.getTime() - 10000),
                   lastVisit)
               .build()));
   assertTrue(eval(builder.profileProperty("properties.lastVisit").all(lastVisit).build()));
   assertFalse(
       eval(
           builder
               .profileProperty("properties.lastVisit")
               .all(new Date(lastVisit.getTime() + 10000), lastVisit)
               .build()));
 }
Esempio n. 18
0
  void checkCalendar(int start, int end) {
    GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    calendar.clear();

    calendar.set(Calendar.YEAR, start);
    calendar.set(Calendar.MONTH, Calendar.JANUARY);
    calendar.set(Calendar.DATE, 1);

    Date date = new Date();
    date.setElapsedDays(DateUtil.getDayFromDate(start, 1, 1));
    while (calendar.get(Calendar.YEAR) <= end) {

      String calString = calendar.toString();
      assertThat("Year: " + calString, date.getYear(), is(calendar.get(Calendar.YEAR)));
      assertThat("Month: " + calString, date.getMonth(), is(calendar.get(Calendar.MONTH) + 1));
      assertThat("Date: " + calString, date.getDay(), is(calendar.get(Calendar.DATE)));

      calendar.add(Calendar.DATE, 1);
      date.setElapsedDays(date.getElapsedDays() + 1);
    }
  }
Esempio n. 19
0
  @Test
  public void testExecuteAndFetch() {
    createAndFillUserTable();

    Date before = new Date();
    List<User> allUsers = sql2o.createQuery("select * from User").executeAndFetch(User.class);
    Date after = new Date();
    long span = after.getTime() - before.getTime();
    System.out.println(String.format("Fetched %s user: %s ms", insertIntoUsers, span));

    // repeat this
    before = new Date();
    allUsers = sql2o.createQuery("select * from User").executeAndFetch(User.class);
    after = new Date();
    span = after.getTime() - before.getTime();
    System.out.println(String.format("Again Fetched %s user: %s ms", insertIntoUsers, span));

    assertTrue(allUsers.size() == insertIntoUsers);
    deleteUserTable();
  }
Esempio n. 20
0
 /** nullの解析。 */
 @Test
 public void parse_null() {
   StringOption option = new StringOption(null);
   Date date = Date.valueOf(option, Date.Format.SIMPLE);
   assertThat(date, is(nullValue()));
 }