ActionTest - Not executing sql queries on Action.class

6 messages Options
Embed this post
Permalink
paulie

ActionTest - Not executing sql queries on Action.class

Reply Threaded More More options
Print post
Permalink
Having problems getting testSave() and testRemove() methods to work properly from my CropActionTest class.  

For testSave(), I can see the select statement where the Crop object is getting loaded.  When I modify the crop name on the object and attempt to save, I don't see a subsequent update statement.

For testRemove(), I don't see a delete statement being executed.

Both of the test cases pass, another thing that is disturbing.

The majority of the sql that goes to the console comes from the onSetUpBeforeTransaction() and onTearDownAfterTransaction() methods.

I have even put breakpoints before the onTearDownAfterTransaction() method is called and cannot see the database activity performed on the affected table.

testSave()
  [eseed] DEBUG [main] CropActionTest.onSetUpBeforeTransaction(17)
  [eseed] DEBUG [main] SQL.log(401) | insert into Crop (crop_name, species) values (?, ?)
  [eseed] DEBUG [main] CropActionTest.startNewTransaction(392) | Began transaction (1):transaction manager [org.springframework.orm.hibernate3.HibernateTransactionManager@c12474]; rollback [true].
  [eseed] DEBUG [main] CropActionTest.testSave(66) | initialize
  [eseed] DEBUG [main] SQL.log(401) | select this_.cropId as cropId7_0_, this_.crop_name as crop2_7_0_, this_.species as species7_0_ from Crop crop0_ where crop0_.cropId=?
  [eseed] DEBUG [main] CropActionTest.testSave(72) | cropNameOld = Romaine
  [eseed] DEBUG [main] CropActionTest.testSave(74) | update crop name and save
  [eseed] DEBUG [main] CropActionTest.testSave(78) | cropNameNew = ActionSaveCrop
  [eseed] DEBUG [main] CropActionTest.endTransaction(360) | Rolled back transaction after execution of test [testSearch].
  [eseed] DEBUG [main] CropActionTest.onTearDownAfterTransaction(35)
  [eseed] DEBUG [main] SQL.log(401) | select crop0_.cropId as cropId7_0_, crop0_.crop_name as crop2_7_0_, from Crop crop0_ where crop0_.cropId=?
  [eseed] DEBUG [main] SQL.log(401) | delete from Crop where cropId=?

testRemove()
  [eseed] DEBUG [main] CropActionTest.onSetUpBeforeTransaction(17)
  [eseed] DEBUG [main] SQL.log(401) | insert into Crop (crop_name, species) values (?, ?)
        [eseed] DEBUG [main] CropActionTest.startNewTransaction(392) | Began transaction (1): transaction manager [org.springframework.orm.hibernate3.HibernateTransactionManager@c713d2]; rollback [true].
        [eseed] DEBUG [main] CropActionTest.testRemove(85) - initialize
        [eseed] DEBUG [main] CropActionTest.testRemove(100) - delete crop
        [eseed] DEBUG [main] SQL.log(401) | select crop0_.cropId as cropId7_0_, crop0_.crop_name as crop2_7_0_, crop0_.species as species7_0_ from Crop crop0_ where crop0_.cropId=?
        [eseed] DEBUG [main] CropActionTest.endTransaction(360) | Rolled back transaction after execution of test [testRemove].
        [eseed] DEBUG [main] CropActionTest.onTearDownAfterTransaction(35) | CropActionTest = onTearDownAfterTransaction
        [eseed] DEBUG [main] SQL.log(401) | select crop0_.cropId as cropId7_0_, crop0_.crop_name as crop2_7_0_, crop0_.species as species7_0_ from Crop crop0_ where crop0_.cropId=?
        [eseed] DEBUG [main] SQL.log(401) | delete from Crop where cropId=?

Here is the CropActionTest code.  I would have expected to see an update and select statements for testSave() along with select and  remove statements with testRemove().  

    public void testSave() throws Exception {
     log.debug("initialize");
        MockHttpServletRequest request = new MockHttpServletRequest();
        ServletActionContext.setRequest(request);
        action.setCropId(1L);
        assertEquals("success", action.edit());
        assertNotNull(action.getCrop());
        log.debug("cropNameOld = " + action.getCrop().getCropName());
       
        log.debug("update crop name and save");
        action.getCrop().setCropName("ActionSaveCrop");
        assertEquals("input", action.save());
        assertEquals("ActionSaveCrop", action.getCrop().getCropName());
        log.debug("cropNameNew = " + action.getCrop().getCropName());
        assertFalse(action.hasActionErrors());
        assertFalse(action.hasFieldErrors());
        assertNotNull(request.getSession().getAttribute("messages"));
    }
   
    public void testRemove() throws Exception {
      log.debug("initialize");
        MockHttpServletRequest request = new MockHttpServletRequest();
        ServletActionContext.setRequest(request);

        log.debug("delete crop");
        action.setDelete("");
        Crop crop = new Crop();
        crop.setCropId(2L);
        action.setCrop(crop);
        assertEquals("success", action.delete());
        assertNotNull(request.getSession().getAttribute("messages"));
    }
   

How come my update and delete queries aren't getting executed.  Thanks in advance.
paulie

Re: ActionTest - Not executing sql queries on Action.class

Reply Threaded More More options
Print post
Permalink

paulie wrote:
Having problems getting testSave() and testRemove() methods to work properly from my CropActionTest class.  

For testSave(), I can see the select statement where the Crop object is getting loaded.  When I modify the crop name on the object and attempt to save, I don't see a subsequent update statement.

For testRemove(), I don't see a delete statement being executed.

Both of the test cases pass, another thing that is disturbing.

The majority of the sql that goes to the console comes from the onSetUpBeforeTransaction() and onTearDownAfterTransaction() methods.

I have even put breakpoints before the onTearDownAfterTransaction() method is called and cannot see the database activity performed on the affected table.

testSave()
  [eseed] DEBUG [main] CropActionTest.onSetUpBeforeTransaction(17)
  [eseed] DEBUG [main] SQL.log(401) | insert into Crop (crop_name, species) values (?, ?)
  [eseed] DEBUG [main] CropActionTest.startNewTransaction(392) | Began transaction (1):transaction manager [org.springframework.orm.hibernate3.HibernateTransactionManager@c12474]; rollback [true].
  [eseed] DEBUG [main] CropActionTest.testSave(66) | initialize
  [eseed] DEBUG [main] SQL.log(401) | select this_.cropId as cropId7_0_, this_.crop_name as crop2_7_0_, this_.species as species7_0_ from Crop crop0_ where crop0_.cropId=?
  [eseed] DEBUG [main] CropActionTest.testSave(72) | cropNameOld = Romaine
  [eseed] DEBUG [main] CropActionTest.testSave(74) | update crop name and save
  [eseed] DEBUG [main] CropActionTest.testSave(78) | cropNameNew = ActionSaveCrop
  [eseed] DEBUG [main] CropActionTest.endTransaction(360) | Rolled back transaction after execution of test [testSearch].
  [eseed] DEBUG [main] CropActionTest.onTearDownAfterTransaction(35)
  [eseed] DEBUG [main] SQL.log(401) | select crop0_.cropId as cropId7_0_, crop0_.crop_name as crop2_7_0_, from Crop crop0_ where crop0_.cropId=?
  [eseed] DEBUG [main] SQL.log(401) | delete from Crop where cropId=?

testRemove()
  [eseed] DEBUG [main] CropActionTest.onSetUpBeforeTransaction(17)
  [eseed] DEBUG [main] SQL.log(401) | insert into Crop (crop_name, species) values (?, ?)
        [eseed] DEBUG [main] CropActionTest.startNewTransaction(392) | Began transaction (1): transaction manager [org.springframework.orm.hibernate3.HibernateTransactionManager@c713d2]; rollback [true].
        [eseed] DEBUG [main] CropActionTest.testRemove(85) - initialize
        [eseed] DEBUG [main] CropActionTest.testRemove(100) - delete crop
        [eseed] DEBUG [main] SQL.log(401) | select crop0_.cropId as cropId7_0_, crop0_.crop_name as crop2_7_0_, crop0_.species as species7_0_ from Crop crop0_ where crop0_.cropId=?
        [eseed] DEBUG [main] CropActionTest.endTransaction(360) | Rolled back transaction after execution of test [testRemove].
        [eseed] DEBUG [main] CropActionTest.onTearDownAfterTransaction(35) | CropActionTest = onTearDownAfterTransaction
        [eseed] DEBUG [main] SQL.log(401) | select crop0_.cropId as cropId7_0_, crop0_.crop_name as crop2_7_0_, crop0_.species as species7_0_ from Crop crop0_ where crop0_.cropId=?
        [eseed] DEBUG [main] SQL.log(401) | delete from Crop where cropId=?

Here is the CropActionTest code.  I would have expected to see an update and select statements for testSave() along with select and  remove statements with testRemove().  

    public void testSave() throws Exception {
     log.debug("initialize");
        MockHttpServletRequest request = new MockHttpServletRequest();
        ServletActionContext.setRequest(request);
        action.setCropId(1L);
        assertEquals("success", action.edit());
        assertNotNull(action.getCrop());
        log.debug("cropNameOld = " + action.getCrop().getCropName());
       
        log.debug("update crop name and save");
        action.getCrop().setCropName("ActionSaveCrop");
        assertEquals("input", action.save());
        assertEquals("ActionSaveCrop", action.getCrop().getCropName());
        log.debug("cropNameNew = " + action.getCrop().getCropName());
        assertFalse(action.hasActionErrors());
        assertFalse(action.hasFieldErrors());
        assertNotNull(request.getSession().getAttribute("messages"));
    }
   
    public void testRemove() throws Exception {
      log.debug("initialize");
        MockHttpServletRequest request = new MockHttpServletRequest();
        ServletActionContext.setRequest(request);

        log.debug("delete crop");
        action.setDelete("");
        Crop crop = new Crop();
        crop.setCropId(2L);
        action.setCrop(crop);
        assertEquals("success", action.delete());
        assertNotNull(request.getSession().getAttribute("messages"));
    }
   

How come my update and delete queries aren't getting executed.  Thanks in advance.
paulie

Re: ActionTest - Not executing sql queries on Action.class

Reply Threaded More More options
Print post
Permalink
In reply to this post by paulie
Can someone tell me if you see the update and delete sql on the console during the execution of SomeActionTest.java methods testSave() and testRemove()?  Thanks.
mraible

Re: ActionTest - Not executing sql queries on Action.class

Reply Threaded More More options
Print post
Permalink
You might not be seeing these statements because transactions are rolled back after tests are executed so the database remains in an untainted state.

Matt

On Tue, May 26, 2009 at 10:21 PM, paulie <[hidden email]> wrote:

Can someone tell me if you see the update and delete sql on the console
during the execution of SomeActionTest.java methods testSave() and
testRemove()?  Thanks.
--
View this message in context: http://www.nabble.com/ActionTest---Not-executing-sql-queries-on-Action.class-tp23680254s2369p23735755.html
Sent from the AppFuse - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


paulie

Re: ActionTest - Not executing sql queries on Action.class

Reply Threaded More More options
Print post
Permalink
In reply to this post by paulie
You're correct.  I turned off the rollback and was able to see the additional queries.  Thanks.
paulie

Re: ActionTest - Not executing sql queries on Action.class

Reply Threaded More More options
Print post
Permalink
In reply to this post by paulie
I think that there is still a problem with my action test cases.  With isRollback() set to false, I can see the update and delete queries executing and their updates on the database.  I can also see a foreign key exception that I have been trying to recreate with an action test case.  

When I leave isRollback() set to true, I don't see the queries and have to believe that they are executing correctly.  The problem is that I am not getting the foreign key exception in this scenario.

Is there something that I am missing?

Thanks again,
Paul