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

    Help with entity test

    Paul Keogh Novice

      Hi,


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


      And...


      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 {
               @Test
               public void testSingleCDRParse () throws Exception {
                  new ComponentTest() {
                           protected void testComponents() throws Exception {
                                EntityManager em = (EntityManager) Component.getInstance("entityManager");
                              
                               UserTransaction tx = Transaction.instance();
                               tx.begin();
                              
                                  Cdr entity = new Cdr();
                                  CdrId id = new CdrId();
                                 
                                  id.setXXX("123");
                                 
                                  entity.setId(id);
                                  entity.setYYY(3);

                                  tx.commit();
                                 
                                  assert(entity.getId() != null);
                              
                                  em.close();
                              }
                  }.run();
               }
          }

          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();
            comp.setBla("whatever");
            //...
            comp.setReferencedComponent(refComp);
            //save comp



            Is this what you were asking about?