Uploaded image for project: 'Spring Roo'
  1. Spring Roo
  2. ROO-1176

DataOnDemand and Number Fields - Unit tests ignore the @Min constraint and Numbers smaller than an int get an int shoved into them

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 1.1.0.M1
    • Fix Version/s: 1.1.0.M3
    • Component/s: TESTING
    • Labels:
      None
    • Environment:
      Linux (Ubuntu 10.04)

      Description

      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
      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.
      // 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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                stewarta Alan Stewart
                Reporter:
                wrochow Waldo Rochow
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: