Package org.apache.torque.test

Examples of org.apache.torque.test.Author


     * 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

        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

        // insert some data into the database
        // taken from tutorial step 4 with some changes
        try
        {
            Author bloch = new Author();
            bloch.setName(AUTHOR_1_NAME);
            bloch.save();

            Author stevens = new Author();
            stevens.setName(AUTHOR_2_NAME);
            AuthorPeer.doInsert(stevens);

            Author withoutBook = new Author();
            withoutBook.setName(AUTHOR_3_NAME);
            AuthorPeer.doInsert(withoutBook);

            Book effective = new Book();
            effective.setTitle(BOOK_1_TITLE);
            effective.setIsbn(BOOK_1_ISBN);
View Full Code Here

                    Criteria.INNER_JOIN);

            bookAuthors = AuthorPeer.doSelect(criteria);

            // from Details section
            Author author = (Author) bookAuthors.get(0);
            List books = author.getBooks();
        }
        catch (Exception e)
        {
            e.printStackTrace();
            fail("inner join : Exception caught : "
View Full Code Here

        assertTrue(
            "size of bookAuthors is not 2, but"
            + bookAuthors.size(),
            bookAuthors.size() == 2);

        Author author = (Author) bookAuthors.get(0);
        assertTrue(
            "Author of first book is not"
            + AUTHOR_1_NAME
            + " but "
            + author.getName(),
            AUTHOR_1_NAME.equals(author.getName()));

        author = (Author) bookAuthors.get(1);
        assertTrue(
            "Author of second book is not"
            + AUTHOR_2_NAME
            + " but "
            + author.getName(),
            AUTHOR_2_NAME.equals(author.getName()));
    }
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 "
                + author.getBooks().size(), authorCopy.getBooks().size() == 10);
    }
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.