Spring Roo
  1. Spring Roo
  2. ROO-2027

@DecimalMax constraint not honored in RooDataOnDemand tests

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Complete
    • Affects Version/s: 1.1.2.RELEASE
    • Fix Version/s: 1.1.2.RELEASE
    • Component/s: PERSISTENCE
    • Labels:
      None

      Description

      Define an entity with the following field and generate the DoD driven integration tests:

          @NotNull
          @DecimalMin("0.0")
          @DecimalMax("9999.99")
          @Digits(integer = 5, fraction = 2)
          private BigDecimal myNum;
      

      Next, run the integration tests. The testPersist() method will fail with a constraint violation. The test uses Integer.MAX_VALUE as the value for the index in getRandomEntityName(). The DoD class then uses the index to construct the BigDecimal, even though the annotation above set the max decimal amount to "9999.99".

              obj.setMyNum(new java.math.BigDecimal(index));
      

      This does not happen with integer fields - the annotation is used to limit the maximum value to the value specified by the maximum value.

        Activity

        Hide
        Alan Stewart added a comment - - edited

        Ken, we now have shell scripts in deployment-support to build Roo. The maven assembly plugin was too slow and unreliable. Please try roo-ci.sh

        Show
        Alan Stewart added a comment - - edited Ken, we now have shell scripts in deployment-support to build Roo. The maven assembly plugin was too slow and unreliable. Please try roo-ci.sh
        Hide
        Stefan Ocke added a comment -

        Just tried that one:

        field number --fieldName price --type java.math.BigDecimal --notNull --digitsInteger 9 --digitsFraction 2

        The integration test generated by Roo still fails in the testPersist method since it still seems to use MAX_INT for the field. But MAX_INT has more than 9 digits...

        Show
        Stefan Ocke added a comment - Just tried that one: field number --fieldName price --type java.math.BigDecimal --notNull --digitsInteger 9 --digitsFraction 2 The integration test generated by Roo still fails in the testPersist method since it still seems to use MAX_INT for the field. But MAX_INT has more than 9 digits...
        Hide
        Stefan Ocke added a comment -

        ...And in DataOnDemand I still see:

        obj.setPreis(java.math.BigDecimal.valueOf(index));

        So are you sure this is fixed in 1.1.2 ?

        Show
        Stefan Ocke added a comment - ...And in DataOnDemand I still see: obj.setPreis(java.math.BigDecimal.valueOf(index)); So are you sure this is fixed in 1.1.2 ?
        Hide
        Alan Stewart added a comment -

        Your command above creates a field annotated with @Digits, which is not supported in DoD at the moment. Please raise another request for this to be added.
        Looking at the JEE6 API, annotations such as @DeimalMax (http://download.oracle.com/javaee/6/api/index.html?javax/validation/constraints/DecimalMax.html) support BigDecimal, BigInteger, String, byte, short, int, long, and their respective wrappers, but not float or double. I may have to rework DoD to match this, as only decimal types such as float, double, and BigDecimal are suppprted for @DecimalMax. It seems odd to allow Strings, and integer-types.

        Show
        Alan Stewart added a comment - Your command above creates a field annotated with @Digits, which is not supported in DoD at the moment. Please raise another request for this to be added. Looking at the JEE6 API, annotations such as @DeimalMax ( http://download.oracle.com/javaee/6/api/index.html?javax/validation/constraints/DecimalMax.html ) support BigDecimal, BigInteger, String, byte, short, int, long, and their respective wrappers, but not float or double. I may have to rework DoD to match this, as only decimal types such as float, double, and BigDecimal are suppprted for @DecimalMax. It seems odd to allow Strings, and integer-types.
        Hide
        Stefan Ocke added a comment -

        You are right... I had seen @Digits in the example above and assumed wrongly this is now also condsidered.
        I created https://jira.springsource.org/browse/ROO-2177 for this now.

        Show
        Stefan Ocke added a comment - You are right... I had seen @Digits in the example above and assumed wrongly this is now also condsidered. I created https://jira.springsource.org/browse/ROO-2177 for this now.

          People

          • Assignee:
            Alan Stewart
            Reporter:
            Ken Rimple
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: