Spring Roo
  1. Spring Roo
  2. ROO-316

DataOnDemand ITD references non-existing abstract class if the corresponding member is @NotNull

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0.0.RC2
    • Fix Version/s: 1.0.0.RC3
    • Component/s: TESTING
    • Labels:
      None

      Description

      the following roo script

       
      project --topLevelPackage tld.domain.project --java 6 --projectName icc_roo2
      
      persistence setup --database HYPERSONIC_IN_MEMORY --provider HIBERNATE
      
      
      entity --abstract --name ~.model.AbstractEntity
      
      entity --name ~.model.ConcreteEntity --testAutomatically
      field reference --fieldName reference --type ~.model.AbstractEntity --notNull yes
      

      produces the entity

      @Entity
      @RooJavaBean
      @RooToString
      @RooEntity
      public class ConcreteEntity {
      
          @NotNull
          @ManyToOne(targetEntity = AbstractEntity.class)
          @JoinColumn
          private AbstractEntity reference;
      }
      

      and the following DataOnDemand ITD

      privileged aspect ConcreteEntityDataOnDemand_Roo_DataOnDemand {
      [...]
          @Autowired    
          private AbstractEntityDataOnDemand ConcreteEntityDataOnDemand.abstractEntityDataOnDemand;    
      [...]
      

      Unfortunately AbstractEntityDataOnDemand does not exist.
      And it can not be created because --testAutomatically is not allowed for abstract classes.
      The reference to abstractEntityDataOnDemand is only included if the corresponding class member is marked as @NotNull.

        Issue Links

          Activity

          Hide
          Tim Schmidt added a comment -

          I have just found out that AbstractEntityDataOnDemand can indeed be created by running the corresponding command explicitly:

          test integration --entity tld.domain.project.model.AbstractEntity
          

          but then the resulting code reads:

          AbstractEntityDataOnDemand_Roo_DataOnDemand.aj
          tld.domain.project.model.AbstractEntity obj = new tld.domain.project.model.AbstractEntity();
          

          and this does not compile because AbstractEntity cannot be instantiated.
          The creation of integration tests for abstract classes should generally not be possible, shouldn't it? I have created a separate issue for that (https://jira.springsource.org/browse/ROO-321).

          Back to the reference to the abstract class:
          Is it possible and does it make sense to somehow exclude references to abstract classes from the test code?

          Show
          Tim Schmidt added a comment - I have just found out that AbstractEntityDataOnDemand can indeed be created by running the corresponding command explicitly: test integration --entity tld.domain.project.model.AbstractEntity but then the resulting code reads: AbstractEntityDataOnDemand_Roo_DataOnDemand.aj tld.domain.project.model.AbstractEntity obj = new tld.domain.project.model.AbstractEntity(); and this does not compile because AbstractEntity cannot be instantiated. The creation of integration tests for abstract classes should generally not be possible, shouldn't it? I have created a separate issue for that ( https://jira.springsource.org/browse/ROO-321 ). Back to the reference to the abstract class: Is it possible and does it make sense to somehow exclude references to abstract classes from the test code?
          Hide
          Ben Alex added a comment -

          SVN revision 373 corrects this issue.

          Roo now provides the ability to create a data on demand class that will provide instances for an abstract entity, but it requires the user to nominate the actual concrete entity that will be used to obtain instances representative of that abstract entity.

          For example, the following script executes successfully and the tests pass. As show, the "dod" command allowed nomination that the "Solid" entity should be used for AbstractFoodDataOnDemand:

          project --topLevelPackage com.abstracttest --projectName abstracttest
          
          persistence setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY
          
          entity --name ~.AbstractFood --abstract
          field number sku --type java.lang.Long
          
          entity --name ~.Drink --extends ~.AbstractFood --testAutomatically
          field number ml --type java.lang.Long --notNull
          
          entity --name ~.Solid --extends ~.AbstractFood --testAutomatically
          field string contents --notNull
          
          dod --entity ~.Solid --class com.abstracttest.AbstractFoodDataOnDemand
          
          entity --name ~.MenuItem --testAutomatically
          field reference food --type ~.AbstractFood --notNull
          field number price --type java.lang.Double --notNull
          
          perform tests
          
          Show
          Ben Alex added a comment - SVN revision 373 corrects this issue. Roo now provides the ability to create a data on demand class that will provide instances for an abstract entity, but it requires the user to nominate the actual concrete entity that will be used to obtain instances representative of that abstract entity. For example, the following script executes successfully and the tests pass. As show, the "dod" command allowed nomination that the "Solid" entity should be used for AbstractFoodDataOnDemand: project --topLevelPackage com.abstracttest --projectName abstracttest persistence setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY entity --name ~.AbstractFood -- abstract field number sku --type java.lang. Long entity --name ~.Drink -- extends ~.AbstractFood --testAutomatically field number ml --type java.lang. Long --notNull entity --name ~.Solid -- extends ~.AbstractFood --testAutomatically field string contents --notNull dod --entity ~.Solid --class com.abstracttest.AbstractFoodDataOnDemand entity --name ~.MenuItem --testAutomatically field reference food --type ~.AbstractFood --notNull field number price --type java.lang. Double --notNull perform tests

            People

            • Assignee:
              Ben Alex
              Reporter:
              Tim Schmidt
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: