1 package org.apache.torque.util; 2 3 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 30 public class CopyTest extends BaseRuntimeTestCase 31 { 32 35 public CopyTest(String name) 36 { 37 super(name); 38 } 39 40 public void setUp() 41 { 42 super.setUp(); 43 } 44 45 48 public void testCopyObject() throws Exception 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 |