Announcement Announcement Module
Collapse
No announcement yet.
Roo 1.1.5.RELEASE - Integration tests fail on fields with regex pattern Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Roo 1.1.5.RELEASE - Integration tests fail on fields with regex pattern

    I am fairly new to Roo, so this could be a user issue. Any help is appreciated.

    I have an entity with a string field and regex pattern:

    Code:
    @NotNull
    @Pattern(regexp = "^([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$")
    private String email;
    When I run "perform tests", the build fails with the following message in the surefire-reports file:

    Code:
    testFlush(com.xf.domain.UserDetailsIntegrationTest)  Time elapsed: 0.057 sec  <<< ERROR!
    java.lang.RuntimeException: [ConstraintDescriptorImpl{annotation=javax.validation.constraints.Pattern, 
    payloads=[], hasComposingConstraints=true, isReportAsSingleInvalidConstraint=false, 
    elementType=FIELD, definedOn=DEFINED_LOCALLY, 
    groups=[interface javax.validation.groups.Default], attributes={message={javax.validation.constraints.Pattern.message}, 
    payload=[Ljava.lang.Class;@6ca02839, flags=[Ljavax.validation.constraints.Pattern$Flag;@6b0ede6, 
    regexp=^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$, groups=[Ljava.lang.Class;@49d29a78}}:
    must match "^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$"=email_0]
    	at com.xf.domain.UserDetailsDataOnDemand_Roo_DataOnDemand.ajc$interMethod$com_xf_domain_UserDetailsDataOnDemand_Roo_DataOnDemand$com_xf_domain_UserDetailsDataOnDemand$init(UserDetailsDataOnDemand_Roo_DataOnDemand.aj:141)
    I have tracked this down to the DataonDemand.aj file, which is not respecting the regex pattern when it sets the value for the email field:

    Code:
    public void UserDetailsDataOnDemand.setEmail(UserDetails obj, int index) {
        String email = "email_" + index;
        obj.setEmail(email);
    }
    Currently - I only have two approaches to get around this problem
    • Skip tests - BAD!
    • Modify DataOnDemand.aj to put in a valid email address - BAD!

    My question is - why is Roo not generating a test which respects the regex pattern? Is it up to me to customize the test data? If so, where do I do this customization. Certainly, I cannot be the only developer to come across this issue.

    Thanks.

  • #2
    The data on demand type is providing a best efforts approach to generating reasonable data for testing, however it can not read regular expressions such as yours and provide test data that adheres to it. If you want this - feel free to provide a patch ;-). Modifying .aj files is not recommended since Roo will delete your changes next time your shell is running again. So in your case you need to push the offending method in your data on demand type into the .java source and modify it there.

    Comment


    • #3
      Thanks Stefan. I moved the method from the aj file to the DataOnDemand java file and now the tests pass.

      Thanks!

      Comment

      Working...
      X