2 Replies Latest reply on Dec 26, 2008 9:42 AM by Matt Nirgue

    Help with entity test

    Paul Keogh Novice


      Can someone point me at an example of how to test an entity component using Seam managed persistence under testng ?


      An example of how to write an integration test where the Seam component under test contains a foreign key.

      Thank you.

        • 1. Re: Help with entity test
          Paul Keogh Novice
          Managed to answer the first part of my question... here it is;

          public class TestCDREntity extends SeamTest {
               public void testSingleCDRParse () throws Exception {
                  new ComponentTest() {
                           protected void testComponents() throws Exception {
                                EntityManager em = (EntityManager) Component.getInstance("entityManager");
                               UserTransaction tx = Transaction.instance();
                                  Cdr entity = new Cdr();
                                  CdrId id = new CdrId();

                                  assert(entity.getId() != null);

          I didn't need to change anything under test as generated - the explcit support for Tx is required because the test config doesn't support JTA Txs by default.
          • 2. Re: Help with entity test
            Matt Nirgue Newbie

            Wouldn't it be something quite similar to what you've done in the first test? you'd need to create and persist both objects though:

            ReferencedComponent refComp = new ReferencedComponent();
            refCompt.setBlaBlaBla("anything you need to set");
            //save refComp
            YourComponent comp = new YourComponent();
            //save comp

            Is this what you were asking about?