Results 1 to 2 of 2

Thread: DataOnDemand and Number Fields - Unit tests fail on Short and @Min(1L)

  1. #1
    Join Date
    Jul 2010
    Location
    Ottawa, Canada
    Posts
    19

    Default DataOnDemand and Number Fields - Unit tests fail on Short and @Min(1L)

    I just opened the following bug (ROO-1176).

    This bug covers two separate issues, I have placed them together because they seem to stem from the same code.

    FIRST:
    Creating an entity with number type fields and applying an @Min constraint greater than zero will fail. It seems that either the getNewTransient_() method or the init() method should take the @Min constraint into account. The init() method sends indexes that are from 0 to 9, but if you have an @Min of 1, the getNewTransient_() will try to populate your field with a zero, which will fail when the object persist() method is called.

    SECOND:
    Creating an entity with number type fields that are smaller than an int fail when the testPersist() test is called, because it calls getNewTransient__(Integer.MAX_VALUE) which cannot be squeezed into a Short (for example).

    WORK AROUND:
    Override the getNewTransient__() method and add this to the beginning
    Code:
    if(index == 0){
     index = 1; 
    } else if(index < 0){
     index = index * -1; 
    }
    if(index > Short.MAX_VALUE){
     Random rnd = new Random(new Integer(index).longValue());
     index = rnd.nextInt(Short.MAX_VALUE); 
    }
    LOG.ROO:
    The following is a log.roo for a test.
    Code:
    // Spring Roo 1.1.0.M1 [rev 3a0b8a3] log opened at 2010-08-05 11:46:45
    project --topLevelPackage com.things
    persistence setup --database HYPERSONIC_IN_MEMORY --provider HIBERNATE
    entity --class ~.domain.ShortThings --testAutomatically 
    field string --fieldName name
    field number --fieldName thingValue --type java.lang.Short --min 1 --notNull 
    entity --class ~.domain.LongThings --testAutomatically 
    field number --fieldName thingValue --type java.lang.Long --min 1 --notNull 
    perform tests
    // Spring Roo 1.1.0.M1 [rev 3a0b8a3] log opened at 2010-08-05 11:54:26

  2. #2
    Join Date
    Dec 2005
    Posts
    935

    Default

    This should be fixed now in Git master.
    Alan Stewart
    Spring Roo Committer
    twitter @alankstewart

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •