Hi all,
  I'm having a lot of trouble building my tests.  I'm using spring
3.M4, and JDO.  I understand I cannot commit multiple entities that
aren't in the same entity graph from the documentation here.

http://code.google.com/appengine/docs/java/datastore/transactions.html#Uses_For_Transactions

 I'm having a lot of trouble with committing data in set up, then
querying to ensure it's correctly persisted.  Below is a unit test.
Has anyone that's used the spring framework with DAO performed the
test within a wrapped transaction, but committed pre transaction?



@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:/META-INF/
applicationContext.xml")
public abstract class AuditableDaoTest<DAO extends IAuditableDao<E>, E
extends Auditable > extends GoogleAppEngineDataUnitTest<E>{



        @Test
        public void Add() {
                E record = createRecord();

                Collection<E> results = getDao().list();

                assertTrue("First records saved", 
containsValue(results,record));

        }

        @Test
        public void List()  {
                E entityA = createRecord();

                E entityB = createRecord();

                E entityC = getEntity();


                Collection<E> results = getDao().list();


                assertTrue("Entity A saved", containsValue(results, entityA));
                assertTrue("Entity B saved", containsValue(results, entityB));
                assertFalse("Entity C not saved", containsValue(results, 
entityC));




        }

        @Test
        public void Delete() {
                E record = createRecord();

                Collection<E> results = getDao().list();

                assertTrue("First record saved", containsValue(results,record));

                getDao().delete(record);

                commitAndCreateTransaction();

                results = getDao().list();

                assertFalse("First record deleted", 
containsValue(results,record));

        }


        /**
         * Create a record of the entity in the database
         * @return
         */
        private E createRecord(){
                E entity = getEntity();

                getDao().add(entity);

                return entity;
        }


        protected abstract E getEntity();

        protected abstract DAO getDao();

}




public class PartDaoTest extends AuditableDaoTest<IPartDao, Part>{

        @Autowired
        private IPartDao partDao;


        @Override
        protected IPartDao getDao() {
                return partDao;
        }

        @Override
        protected Part getEntity() {
                String timeString = Calendar.getInstance().getTime().toString();
                Part part = new Part();
                part.setDescription("Description " + timeString);
                part.setName("Name " + timeString);

                return part;
        }

}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to