Package org.apache.torque.test.dbobject

Examples of org.apache.torque.test.dbobject.Author


     */
    public void testUpdate() throws Exception
    {
        cleanBookstore();

        Author otherAuthor = new Author();
        otherAuthor.setName("OtherName");
        otherAuthor.save();

        Author author = new Author();
        author.setName("Name");
        author.save();


        // Test doUpdate methods in Peer explicitly
        Connection connection = Transaction.begin(AuthorPeer.DATABASE_NAME);
        author.setName("NewName2");
        AuthorPeer.doUpdate(author);
        Transaction.commit(connection);

        Criteria criteria = new Criteria();
        criteria.addAscendingOrderByColumn(AuthorPeer.NAME);

        List<Author> authors = AuthorPeer.doSelect(criteria);
        assertEquals("List should contain 2 authors", 2, authors.size());
        assertEquals("First Author's name should be \"NewName2\"",
                "NewName2",
                authors.get(0).getName());
        assertEquals("Second Author's name should be \"OtherName\"",
                "OtherName",
                authors.get(1).getName());

        author.setName("NewName3");
        AuthorPeer.doUpdate(author);

        criteria = new Criteria();
        criteria.addAscendingOrderByColumn(AuthorPeer.NAME);

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 it is possible to serialize/deserialize beans
     * @throws Exception
     */
    public void testSerializeBeans() throws Exception
    {
        Author author = new Author();
        author.setName(AUTHOR_1_NAME);
        author.setAuthorId(AUTHOR_1_ID);

        AuthorBean authorBean = author.getBean();

        // serialize the AuthorBean
        byte[] serializedAuthorBean;
        {
            ObjectOutputStream objectOutputStream = null;
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 = authorBean.getBookBeans().get(0);
        assertTrue("authorBean from BookBean should be the same "
                + "object as authorBean",
                bookBean.getAuthorBean() == authorBean);

        author = Author.createAuthor(authorBean);
        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 = authorBean.getBookBeans().get(0);
        assertTrue("authorBean from BookBean should not be the same "
                + "object as authorBean",
                bookBean.getAuthorBean() != authorBean);

        author = Author.createAuthor(authorBean);
        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.where(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<Author> authorList = AuthorPeer.doSelect(new Criteria());
        Author readAuthor = 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

     * @throws Exception if the test fails
     */
    public void testRetrieveByPk() throws Exception
    {
        ObjectKey primaryKey = authorList.get(1).getPrimaryKey();
        Author author = AuthorPeer.retrieveByPK(primaryKey);
        assertEquals("Expected author with Id "
                + authorList.get(1).getAuthorId()
                + " at first position but got "
                + author.getAuthorId(),
                authorList.get(1).getAuthorId(),
                author.getAuthorId());
    }
View Full Code Here

    protected List<Author> insertBookstoreData() throws TorqueException
    {
        List<Author> result = new ArrayList<Author>();
        for (int i = 1; i <= 10; i++)
        {
            Author author = new Author();
            author.setName("Author " + i);
            author.save();
            result.add(author);
            assertTrue("authorId should not be 0 after insert",
                    author.getAuthorId() != 0);

            for (int j = 1; j <= 10; j++)
            {
                Book book = new Book();
                author.addBook(book);
                book.setTitle("Book " + j + " - Author " + i);
                if (j < 10)
                {
                    book.setIsbn("ISBN " + j + " - " + i);
                }
View Full Code Here

        List<Author> result = AuthorPeer.doSelect(criteria);
        assertEquals("Expected result of size 1 but got " + result.size(),
                1,
                result.size());
        Author author = result.get(0);
        assertEquals("Expected author with Id "
                + authorList.get(0).getAuthorId()
                + " at first position but got "
                + author.getAuthorId(),
                authorList.get(0).getAuthorId(),
                author.getAuthorId());
    }
View Full Code Here

        List<Author> result = AuthorPeer.doSelect(criteria);
        assertEquals("Expected result of size 1 but got " + result.size(),
                1,
                result.size());
        Author author = result.get(0);
        assertEquals("Expected author with Id "
                + authorList.get(0).getAuthorId()
                + " at first position but got "
                + author.getAuthorId(),
                authorList.get(0).getAuthorId(),
                author.getAuthorId());
    }
View Full Code Here

TOP

Related Classes of org.apache.torque.test.dbobject.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.