Exemple #1
0
  @Test
  public void testPresenceValidator() {
    deleteAndPopulateTable("people");
    Person p = new Person();
    p.validate();
    a(p.errors().size()).shouldBeEqual(2);
    a(p.errors().get("name")).shouldBeEqual("value is missing");
    a(p.errors().get("last_name")).shouldBeEqual("value is missing");

    p.set("name", "igor");
    p.validate();
    a(p.errors().size()).shouldBeEqual(1);

    p.set("last_name", "polevoy");
    p.validate();
    a(p.errors().size()).shouldBeEqual(0);
  }
Exemple #2
0
  @Test
  public void shouldReturnSecondsInDateTime() throws ParseException {
    Person p = new Person();
    p.set("name", "john", "last_name", "doe").saveIt();
    p.refresh();
    String json = p.toJson(true);

    System.out.println(json);
    @SuppressWarnings("unchecked")
    Map<String, String> map = JsonHelper.toMap(json);

    Date d = new ISO8601DateFormat().parse(map.get("created_at"));
    // difference between date in Json and in original model instance should be less than 1000
    // milliseconds
    a(Math.abs(d.getTime() - p.getTimestamp("created_at").getTime()) < 1000L).shouldBeTrue();
  }
Exemple #3
0
  /**
   * Create a new person entry in the database and returns the new item.
   *
   * @param inName String
   * @param inFirstname String
   * @param inFrom String
   * @param inTo String
   * @param inText String
   * @return Person
   * @throws BOMException
   */
  public AbstractPerson newPerson(
      final String inName,
      final String inFirstname,
      final String inFrom,
      final String inTo,
      final String inText)
      throws BOMException {
    try {
      final Timestamp lCreated = new Timestamp(System.currentTimeMillis());
      final Person outPerson = (Person) create();
      outPerson.set(PersonHome.KEY_NAME, inName);
      outPerson.set(PersonHome.KEY_FIRSTNAME, inFirstname);
      outPerson.set(PersonHome.KEY_FROM, inFrom);
      outPerson.set(PersonHome.KEY_TO, inTo);
      outPerson.set(PersonHome.KEY_TEXT, inText);
      outPerson.set(KEY_CREATED, lCreated);
      outPerson.set(KEY_MODIFIED, lCreated);

      final Long lID = outPerson.insert(true);
      outPerson.set(KEY_ID, lID);
      // final KeyObject lKey = new KeyObjectImpl();
      // lKey.setValue(KEY_ID, new BigDecimal(lID.doubleValue()));
      // outPerson = (Person) findByKey(lKey);

      // index person
      getIndexer().addToIndex(outPerson);

      return outPerson;
    } catch (final VException exc) {
      throw new BOMException(exc.getMessage());
    } catch (final IOException exc) {
      throw new BOMException(exc.getMessage());
    } catch (final SQLException exc) {
      if (AbstractItem.TRUNCATION_STATE.equals(exc.getSQLState())) {
        throw new BOMTruncationException(AbstractItem.TRUNCATION_MSG);
      }
      throw new BOMException(exc.getMessage());
    }
  }