Ok. I have somehow found my own answer. To delete the latest additional 
provisory object, you have to remember its id. My solution is like this.

Add a private field "id" of type Long. When you create the provisory object,
store its id in onSetUpBeforeTransaction():
        competency = competencyManager.save(competency);
        id = competency.getId(); 

Then overwrite the onTearDownAfterTransaction() method:

    @Override
    protected void onTearDownAfterTransaction() throws Exception {
        super.onTearDownAfterTransaction();
        if (id != null) {
                log.debug("Deleting provisory object: " + id);
                Person person = new Person();
                person.setId(id);
                action.setPerson(Person);
                action.delete();
                id=null;
        }
    }

Nice short quest. :-)



Martin Homik wrote:
> 
> Let me also add the comment that the test will cause an error if one of
> the POJO fields is
> annotated with "unique = true". That's because onSetUpBeforeTransaction()
> is invoked
> before each test and hence populates the database with as many additional
> objects as
> tests exist. 
> 
> According to my database, after finishing the tests, all additional
> objects
> are removed from the database. What's the counterpart of
> onSetUpBeforeTransaction()?
> How does the mechanism work? Will all added objects be removed from the
> database after 
> finishing the last test?
> 
> Martin
> 
> 
> 
> chino fish wrote:
>> 
>> 
>> 
>> 
>> On 5/16/07, chino fish <[EMAIL PROTECTED]> wrote:
>>>
>>>
>>>
>>>
>>> 1.       the test is function test, not unit test. Isn't it ? b/c it
>>> uses
>>> real service object, but mock objects.
>> 
>> Yes.
>> 
>>>
>>> 2.       the method followed is a bit of useless..b/c personManager andd
>>> person are not used by other test at all.
>> 
>> It's used to add at least one record to the database so testSearch()
>> doesn't fail.
>> 
>> Matt
>> 
>> Oh, that's what I guessed ;-)
>> It seems the method should only be called in testSearch method。
>> But actually, it is called before every test b/c the code was in method
>> onSetupBeforeTransaction which is called by setup method.
>> 
>> And b/c dbunit plunge some sample data into db, so there is already at
>> least
>> one record in the table.
>> 
>>>
>>>     protected void onSetUpBeforeTransaction() throws Exception {
>>>
>>>
>>>
>>>         super.onSetUpBeforeTransaction();
>>>
>>>         GenericManager personManager = (GenericManager)
>>> applicationContext.getBean("personManager");
>>>
>>>
>>>
>>>
>>>
>>>         // add a test person to the database
>>>
>>>
>>>
>>>         Person person = new Person();
>>>
>>>         person.setFirstName("Jack");
>>>
>>>
>>>
>>>         person.setLastName("Raible");
>>>
>>>
>>>
>>>         personManager.save(person);
>>>
>>> }
>>>
>>>
>>>
>>> chinofish
>> 
>> 
>> -- 
>> http://raibledesigns.com
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>> 
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Two-questions-about-PersonActionTest-tf3768046s2369.html#a13056040
Sent from the AppFuse - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to