Package org.apache.torque.test

Examples of org.apache.torque.test.Author


    {
        try
        {
            for (int i = 1; i <= 10; i++)
            {
                Author author = new Author();
                author.setName("Author " + i);
                author.save();

                for (int j = 1; j <= 10; j++)
                {
                    Book book = new Book();
                    book.setAuthor(author);
View Full Code Here


        tearDown();

        // Create some test data
        for (int i = 0; i < TEST_ROWS; i++)
        {
            Author author = new Author();
            author.setName(LARGE_SELECT_AUTHOR);
            try
            {
                author.save();
            }
            catch (Exception e)
            {
                fail("Cannot create test data for LargeSelectTest.");
            }
            if (-1 == firstAuthorId)
            {
                firstAuthorId = author.getAuthorId();
            }
        }
        // Set up the standard criteria for the test.
        criteria = new Criteria();
        criteria.add(AuthorPeer.NAME, LARGE_SELECT_AUTHOR);
View Full Code Here

    /**
     * does some inserts.
     */
    public void testCopyObject() throws Exception
    {
        Author author = new Author();
        author.setName("Author to be copied");
        author.save();

        for (int j = 1; j <= 10; j++)
        {
            Book book = new Book();
            book.setAuthor(author);
            book.setTitle("Book " + j + " - " + author.getName());
            book.setIsbn("unknown");
            book.save();
        }
        assertTrue("Number of books before copy should be 10, was "
                + author.getBooks().size(),
                author.getBooks().size() == 10);
        Author authorCopy = author.copy();
        authorCopy.save();

        author = AuthorPeer.retrieveByPK(author.getPrimaryKey());
        assertTrue("Number of books in original object should be 10, was "
                + author.getBooks().size(),
                author.getBooks().size() == 10);

        assertTrue("Number of books after copy should be 10, was "
                + authorCopy.getBooks().size(),
                authorCopy.getBooks().size() == 10);
    }
View Full Code Here

    /**
     * tests the creation of beans from objects and vice versa
     */
    public void testCreateBeans() throws Exception
    {
        Author author = new Author();
        author.setName(AUTHOR_1_NAME);
        author.setAuthorId(AUTHOR_1_ID);
       
        AuthorBean authorBean = author.getBean();
        assertTrue("bean.getName() is " + authorBean.getName()
                + " should be " + author.getName(),
                author.getName().equals(authorBean.getName()));
        assertTrue("bean.getId() is " + authorBean.getAuthorId()
                + " should be " + AUTHOR_1_ID,
                author.getAuthorId() == authorBean.getAuthorId());
       
        Author authorFromBean = Author.createAuthor(authorBean);
        assertTrue("author from bean has name " + authorFromBean.getName()
                + " should be " + author.getName(),
                author.getName().equals(authorFromBean.getName()));
        assertTrue("author from bean has Id " + authorFromBean.getAuthorId()
                + " should be " + author.getAuthorId(),
                author.getAuthorId() == authorBean.getAuthorId());
    }
View Full Code Here

     * tests whether object relations are transferred correctly,
     * if two objects refer to each other
     */
    public void testSameObjectRelations() throws Exception
    {
        Author author = new Author();
        author.setAuthorId(AUTHOR_1_ID);
     
        Book book = new Book();
        book.setBookId(BOOK_1_ID);
     
        author.addBook(book);
        book.setAuthor(author);
       
        // check one roundtrip from author
        assertTrue("author from book should be the same object as author",
                author == book.getAuthor());
       
        AuthorBean authorBean = author.getBean();
        BookBean bookBean = (BookBean) authorBean.getBookBeans().get(0);
        assertTrue("authorBean from BookBean should be the same "
                + "object as authorBean",
                bookBean.getAuthorBean() == authorBean);
       
        author = Author.createAuthor(authorBean);
        book = (Book) author.getBooks().get(0);
       
        assertTrue("author from book should be the same object as author "
                + "after creating from bean",
                author == book.getAuthor());
       
        // check one roundtrip from book
        assertTrue("book from author should be the same object as book",
                book == author.getBooks().get(0));

        bookBean = book.getBean();
        authorBean = bookBean.getAuthorBean();
        assertTrue("bookBean from authorBean should be the same "
                + "object as bookBean",
                authorBean.getBookBeans().get(0) == bookBean);

        book = Book.createBook(bookBean);
        author = book.getAuthor();

        assertTrue("book from author should be the same object as book "
                + "after creating from bean",
                author.getBooks().get(0) == book);
    }
View Full Code Here

        // create a relation chain:
        //
        //      getBooks()  getAuthor()          getBooks()
        //         |            |                    |  
        // author ----> book -----> differentAuthor ---> differentBook
        Author author = new Author();
        author.setAuthorId(AUTHOR_1_ID);

        Book book = new Book();
        book.setBookId(BOOK_1_ID);
       
        Author differentAuthor = new Author();
        author.setAuthorId(AUTHOR_1_ID);

        author.addBook(book);
        book.setAuthor(differentAuthor);
       
        Book differentBook = new Book();
        book.setBookId(BOOK_1_ID);
       
        differentAuthor.addBook(differentBook);

        // check one roundtrip from author
        assertTrue("author from book should not be the same object as author",
                author != book.getAuthor());

        AuthorBean authorBean = author.getBean();
        BookBean bookBean = (BookBean) authorBean.getBookBeans().get(0);
        assertTrue("authorBean from BookBean should not be the same "
                + "object as authorBean",
                bookBean.getAuthorBean() != authorBean);

        author = Author.createAuthor(authorBean);
        book = (Book) author.getBooks().get(0);

        assertTrue("author from book should not be the same object as author "
                + "after creating from bean",
                author != book.getAuthor());

        // check one roundtrip from book
        assertTrue("book from differentAuthor should not be "
                + "the same object as book",
                book != differentAuthor.getBooks().get(0));

        bookBean = book.getBean();
        AuthorBean differentAuthorBean = bookBean.getAuthorBean();
        assertTrue("bookBean from differentAuthorBean should not be the same "
                + "object as bookBean",
                differentAuthorBean.getBookBeans().get(0) != bookBean);

        book = Book.createBook(bookBean);
        differentAuthor = book.getAuthor();

        assertTrue("book from differentAuthor should not be "
                + "the same object as book "
                + "after creating from bean",
                differentAuthor.getBooks().get(0) != book);
    }
View Full Code Here

       
        criteria = new Criteria();
        criteria.add(AuthorPeer.AUTHOR_ID, (Long) null, Criteria.NOT_EQUAL);
        AuthorPeer.doDelete(criteria);
       
        Author author = new Author();
        author.setName(AUTHOR_1_NAME);
        author.save();
       
        assertFalse("isModified() should return false after save",
                author.isModified());
        assertFalse("isNew() should return false after save",
                author.isNew());
       
        AuthorBean authorBean = author.getBean();
       
        assertFalse("bean.isModified() should return false after save "
                + "and bean creation",
                authorBean.isModified());
        assertFalse("bean.isNew() should return false after save "
                + "and bean creation",
                authorBean.isNew());
       
        author = Author.createAuthor(authorBean);
       
        assertFalse("isModified() should return false after save "
                + "and bean roundtrip",
                author.isModified());
        assertFalse("isNew() should return false after save "
                + "and bean rounddtrip",
                author.isNew());
       
        authorBean.setName(AUTHOR_2_NAME);
        assertTrue("bean.isModified() should return true after it was modified",
                authorBean.isModified());
        assertFalse("bean.isNew() should still return false "
                + "after bean creation and modification",
                authorBean.isNew());
       
        author = Author.createAuthor(authorBean);
        assertTrue("isModified() should return true after creation of object "
                + "from modified bean",
                author.isModified());
       
        author.save();
       
        List authorList = AuthorPeer.doSelect(new Criteria());
        Author readAuthor = (Author) authorList.get(0);
        assertEquals("name from read Author is " + readAuthor.getName()
                +" but should be " + authorBean.getName(),
                readAuthor.getName(),
                authorBean.getName());
       
        BookBean bookBean = new BookBean();
        bookBean.setTitle(BOOK_1_TITLE);
        bookBean.setIsbn(BOOK_1_ISBN);
View Full Code Here

    public void testInsertData() throws Exception
    {
        // insert books and authors
        for (int i = 1; i <= 10; i++)
        {
            Author author = new Author();
            author.setName("Author " + i);
            author.save();
            assertTrue("authorId should not be 0 after insert",
                    author.getAuthorId() != 0);

            for (int j = 1; j <= 10; j++)
            {
                Book book = new Book();
                book.setAuthor(author);
View Full Code Here

     */
    public void testDelete() throws Exception
    {
        cleanBookstore();
       
        Author author = new Author();
        author.setName("Name");
        author.save();

        Book book = new Book();
        book.setTitle("title");
        book.setAuthor(author);
        book.setIsbn("ISBN");
        book.save();

        // delete without matching data
        Criteria criteria = new Criteria();
        criteria.add(
                AuthorPeer.AUTHOR_ID,
                author.getAuthorId(),
                Criteria.NOT_EQUAL);
        AuthorPeer.doDelete(criteria);
        List authorResult = AuthorPeer.doSelect(new Criteria());
        assertTrue("deleted too many records", authorResult.size() == 1);

        BookPeer.doDelete(book);
        List bookResult = BookPeer.doSelect(new Criteria());
        authorResult = AuthorPeer.doSelect(new Criteria());
        // check that the book has disappeared
        assertTrue("delete by object failed",
            bookResult.size() == 0);
        // check that the underlying author has not been deleted
        assertTrue("delete by object deleted in cascade",
            authorResult.size() == 1);

        // delete with matching data
        criteria.clear();
        criteria.add(AuthorPeer.AUTHOR_ID, author.getAuthorId());
        AuthorPeer.doDelete(criteria);
        authorResult = AuthorPeer.doSelect(new Criteria());
        assertTrue("deleted not enough records",
            authorResult.size() == 0);
    }
View Full Code Here

       
        criteria = new Criteria();
        criteria.add(BookPeer.BOOK_ID, (Long) null, Criteria.NOT_EQUAL);
        BookPeer.doDelete(criteria, null);
       
        Author author = new Author();
        author.setName("name");
        author.save((Connection) null);
    }
View Full Code Here

TOP

Related Classes of org.apache.torque.test.Author

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.