Announcement Announcement Module
Collapse
No announcement yet.
problem with generated entity tests when entities have relationships Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • problem with generated entity tests when entities have relationships

    Hi,

    I generated a set of entities which have relationships.

    For example:

    1 Profile <- many Workload

    Associations are defined as follows:

    Profile

    @Entity
    @RooJavaBean
    @RooToString
    @RooEntity(identifierField = "id")
    public class Profile {

    @NotNull
    private Integer id;

    private String profileName;
    }


    @Entity
    @RooJavaBean
    @RooToString
    @RooEntity(identifierField = "id")
    public class Workload {

    @NotNull
    private Integer id;

    private Double forecasted;

    private Double actual;

    @ManyToOne(targetEntity = Profile.class)
    @JoinColumn(name = "id", insertable = false, updatable = false)
    private Profile profile;
    }
    Workload


    When I run the tests, the tests for Profile are OK, bu I get the following failures in the tests for Workload:

    Tests run: 9, Failures: 0, Errors: 6, Skipped: 0, Time elapsed: 3.543 sec <<< FAILURE!

    testFlush(com.gemalto.sstep.mnosearch.domain.Workl oadIntegrationTest) Time elapsed: 0.359 sec <<< ERROR!
    javax.persistence.EntityNotFoundException: Unable to find com.gemalto.sstep.mnosearch.domain.Profile with id 9

    testMerge(com.gemalto.sstep.mnosearch.domain.Workl oadIntegrationTest) Time elapsed: 0 sec <<< ERROR!
    javax.persistence.EntityNotFoundException: Unable to find com.gemalto.sstep.mnosearch.domain.Profile with id 3

    testRemove(com.gemalto.sstep.mnosearch.domain.Work loadIntegrationTest) Time elapsed: 0 sec <<< ERROR!
    javax.persistence.EntityNotFoundException: Unable to find com.gemalto.sstep.mnosearch.domain.Profile with id 2

    testFindWorkload(com.gemalto.sstep.mnosearch.domai n.WorkloadIntegrationTest) Time elapsed: 0 sec <<< ERROR!
    javax.persistence.EntityNotFoundException: Unable to find com.gemalto.sstep.mnosearch.domain.Profile with id 0

    testFindAllWorkloads(com.gemalto.sstep.mnosearch.d omain.WorkloadIntegrationTest) Time elapsed: 0.016 sec <<< ERROR!
    javax.persistence.EntityNotFoundException: Unable to find com.gemalto.sstep.mnosearch.domain.Profile with id 0

    testFindWorkloadEntries(com.gemalto.sstep.mnosearc h.domain.WorkloadIntegrationTest) Time elapsed: 0 sec <<< ERROR!
    javax.persistence.EntityNotFoundException: Unable to find com.gemalto.sstep.mnosearch.domain.Profile with id 0



    Should these tests work OK out of the box, or do I have to include any extra operations by hand in the test classes?

    Thank you very much for your help

    Raul

  • #2
    OK.. I'm an idiot

    I was manually defining the "id" field, which was already in the @RooEntity annotation, so in the database I had an ENTITY_ID column and an ID column, and the mapping was not being done with the right data...

    What I also found is that there are no referenced objects defined in the data on demand. For example if a project has a project manager, this field will be null, same for a project manager who has a set of projects.

    I manually added this to the DOD AJ by autowiring the referenced object DOD and in the getNewTransientXXX methid, I add a obj.setYYY(yyyDOD.getRandomYYY()) which works fine... the only issue is that these AJ files are totally regenerated when I modify the corresponding entities.

    Comment

    Working...
    X