KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > torque > util > CopyTest


1 package org.apache.torque.util;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import org.apache.torque.BaseRuntimeTestCase;
20 import org.apache.torque.test.Author;
21 import org.apache.torque.test.AuthorPeer;
22 import org.apache.torque.test.Book;
23
24 /**
25  * Test code for TorqueObject.copy().
26  *
27  * @author <a HREF="mailto:torque@kivus.myip.org">Rafal Maczewski</a>
28  * @version $Id: CopyTest.java,v 1.6 2005/04/16 13:59:30 tfischer Exp $
29  */

30 public class CopyTest extends BaseRuntimeTestCase
31 {
32     /**
33      * Creates a new instance.
34      */

35     public CopyTest(String JavaDoc name)
36     {
37         super(name);
38     }
39
40     public void setUp()
41     {
42         super.setUp();
43     }
44
45     /**
46      * does some inserts.
47      */

48     public void testCopyObject() throws Exception JavaDoc
49     {
50         Author author = new Author();
51         author.setName("Author to be copied");
52         author.save();
53
54         for (int j = 1; j <= 10; j++)
55         {
56             Book book = new Book();
57             book.setAuthor(author);
58             book.setTitle("Book " + j + " - " + author.getName());
59             book.setIsbn("unknown");
60             book.save();
61         }
62         assertTrue("Number of books before copy should be 10, was "
63                 + author.getBooks().size(),
64                 author.getBooks().size() == 10);
65         Author authorCopy = author.copy();
66         authorCopy.save();
67
68         author = AuthorPeer.retrieveByPK(author.getPrimaryKey());
69         assertTrue("Number of books in original object should be 10, was "
70                 + author.getBooks().size(),
71                 author.getBooks().size() == 10);
72
73         assertTrue("Number of books after copy should be 10, was "
74                 + authorCopy.getBooks().size(),
75                 authorCopy.getBooks().size() == 10);
76     }
77 }
78
Popular Tags