Weird error

From: Alex Gunawan Wibowo (netzone_tec..ahoo.com)
Date: Sun Dec 19 2004 - 22:12:42 EST

  • Next message: David Burnett: "Exception when running Modeler"

    Hello,

    I encountered this weird error with Cayenne and
    MockStrutsTestCase

    ClientUser with ID "10" belongs to Client with ID "1"
    Client with ID "1" has 2 client users, ID "10" and ID
    "11".
    I want to delete client users with ID "10"

    The following is a MockStrutsTest code that i wrote..

    //---------------------------------------------
     /**
      * Test deleting the client users
      */
    public void testDeleteClientUsers() throws Exception
    {

    setRequestPathInfo("/admin/saveViewDetailsClient.do");
            TestHelper.logAdminIn(this);
            TestHelper.setTransactionToken(this);
            
        
    addRequestParameter(Constants.ADMIN_BUTTON_PRESSED,
    Constants.ADMIN_DELETE_PRESSED);

            // Set the client user with ID "10" as selected
            addRequestParameter(Constants.ADMIN_SELECTED_ITEMS,
    new String[] {"10"});

                    
            // Verify the client users prior to deletion
            DataContext ctxt =
    BasicServletConfiguration.getDefaultContext(getSession());
            ClientUsers aClientUser = (ClientUsers)
    DataObjectUtils.objectForPK(ctxt, ClientUsers.class,
                            new Integer("10"));
            assertNotNull(aClientUser);

            //-------- START OF MARKING --------------
            Client aClient2 = (Client)
    DataObjectUtils.objectForPK(ctxt, Client.class, new
    Integer("1"));
            
            // Expect client to have 2 client users before the
    deletion
            assertEquals(2, aClient2.getClientUsersArray().size()
    );
            //--------- END OF MARKING --------------
                    
            actionPerform();
            verifyForward(Constants.ADMIN_SUCCESS_TARGET);
            verifyNoActionErrors();

            // After deletion, client user with ID "10" must not
    exist anymore
            aClientUser = (ClientUsers)
    DataObjectUtils.objectForPK(ctxt, ClientUsers.class,
                            new Integer("10"));
            assertNull(aClientUser);
                    
            // After deletion, client with id "1" must only have
    1 client user
            Client aClient = (Client)
    DataObjectUtils.objectForPK(ctxt, Client.class, new
    Integer("1"));
            assertEquals(1, aClient.getClientUsersArray().size()
    );
    }

    //----------------------------------------------

    Hopefully the code above is clear enough.

    The weird thing is....
    when I comment out the lines between the mark (see
    above), the test will be successful.
    With those lines however, the test will fail. The
    failure is on the
    last line
    "assertEquals(1, aClient.getClientUsersArray().size()
    );"
    The array size is 2.

    Isn't this very weird????????

    Apparently, I didn't include the following line in my
    code:

    aClientUser.getToClient().removeFromClientUsersArray(aClientUser);

    With this line, both test will be successful. But
    again, that problem above is very
    weird. They should fail before the workaround that I
    did above.
    But one of them give me a pass (if i comment out the
    marked section).
    Is this a bug in Cayenne?? or in Struts Test Case??

    Also, from the problem above, it seems that :
    If I have a one to many relationship, when I want
    to remove the record from the "many" side, I have to
    call the method "removeFromXXXArray()" manually.
    I can't just delete the "many" record and expect the
    "one" record to automatically handle the rest.
    Am I correct?

    Thanks for the help!

    Best regards,

    Alex Wibowo

                    
    __________________________________
    Do you Yahoo!?
    Yahoo! Mail - 250MB free storage. Do more. Manage less.
    http://info.mail.yahoo.com/mail_250



    This archive was generated by hypermail 2.0.0 : Sun Dec 19 2004 - 22:12:45 EST