Package org.apache.torque.test.dbobject

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


            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);
            effective.setAuthor(bloch);
            effective.save();

            Book tcpip = new Book();
            tcpip.setTitle(BOOK_2_TITLE);
            tcpip.setIsbn(BOOK_2_ISBN);
            tcpip.setAuthorId(stevens.getAuthorId());
            tcpip.save();

            Book tcpipVolTwo = new Book();
            tcpipVolTwo.setTitle(BOOK_3_TITLE);
            tcpipVolTwo.setIsbn(BOOK_3_ISBN);
            tcpipVolTwo.setAuthorId(stevens.getAuthorId());
            tcpipVolTwo.save();

        }
        catch (Exception e) {
            e.printStackTrace();
            fail("Exception caught : "
View Full Code Here


            fail("Exception caught : "
                     + e.getClass().getName()
                     + " : " + e.getMessage());
        }

        Book book = books.get(0);
        assertTrue(
                "title of first book is not"
                + BOOK_1_TITLE
                + " but "
                + book.getTitle(),
                BOOK_1_TITLE.equals(book.getTitle())
                );

        book = books.get(2);
        assertTrue(
                "ISBN of third book is not"
                + BOOK_3_ISBN
                + " but "
                + book.getIsbn(),
                BOOK_3_ISBN.equals(book.getIsbn()));
    }
View Full Code Here

        // prepare
        cleanBookstore();
        List<Author> bookstoreContent = insertBookstoreData();
        Author author = new Author();
        author.setName("Author");
        Book book = new Book();
        author.addBook(book);
        book.setTitle("Book title");
        book.setIsbn("ISBN");

        // execute
        author.save();

        // verify
        assertNotNull(author.getAuthorId());
        assertEquals("Author", author.getName());
        assertNotNull(book.getBookId());
        assertEquals("Book title", book.getTitle());
        assertEquals("ISBN", book.getIsbn());

        bookstoreContent.add(author);
        verifyBookstore(bookstoreContent);
    }
View Full Code Here

        Author author = new Author();
        author.setName("Author");
        author.save();
        author.setName("nameModified"); // modify after saving

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

        // execute
        book.save();

        // verify
        // propagation would have been possible, reference is there
        assertNotNull(book.getAuthor());

        // Author in db should still have old name
        Criteria criteria = new Criteria().where(AuthorPeer.NAME, "Author");
        List<Author> authorList = AuthorPeer.doSelect(criteria);
        assertEquals(1, authorList.size());
View Full Code Here

        // insert test data
        Author firstAuthor = new Author();
        firstAuthor.setName("Author 1");
        firstAuthor.save();
        Book book = new Book();
        book.setAuthor(firstAuthor);
        book.setTitle("Book 1");
        book.setIsbn("unknown");
        book.save();

        Author secondAuthor = new Author();
        secondAuthor.setName("Author 2");
        secondAuthor.save();
        for (int bookNr = 2; bookNr <=4; bookNr++)
        {
            book = new Book();
            book.setAuthor(secondAuthor);
            book.setTitle("Book " + bookNr);
            book.setIsbn("unknown");
            book.save();
        }

        // test simple ascending order by
        Criteria criteria = new Criteria();
        criteria.addAscendingOrderByColumn(BookPeer.TITLE);
View Full Code Here

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

        Book book = new Book();
        book.setTitle("Name");
        book.setAuthor(author);
        book.setIsbn("unknown");
        book.save();

        Criteria criteria = new Criteria();
        criteria.addJoin(BookPeer.TITLE, AuthorPeer.NAME);
        BookPeer.addSelectColumns(criteria);
        AuthorPeer.addSelectColumns(criteria);
        // basically a BaseBookPeer.setDbName(criteria);
        // and BasePeer.doSelect(criteria);
        CompositeMapper mapper = new CompositeMapper();
        mapper.addMapper(new BookRecordMapper(), 0);
        mapper.addMapper(
                new AuthorRecordMapper(),
                BookPeer.numColumns);

        List<List<Object>> queryResult
                = BookPeer.doSelect(criteria, mapper);
        List<Object> mappedRow = queryResult.get(0);
        book = (Book) mappedRow.get(0);
        author = (Author) mappedRow.get(1);

        if (book.getAuthorId() == author.getAuthorId())
        {
            fail("wrong Ids read");
        }
    }
View Full Code Here

    public void testEquals() throws Exception
    {
        Author author = new Author();
        author.setAuthorId(1000);

        Book book = new Book();
        book.setBookId(1000);

        Book bookNotEqual = new Book();
        bookNotEqual.setBookId(2000);

        Book bookEqual = new Book();
        bookEqual.setBookId(1000);

        assertFalse("Author and Book should not be equal",
                author.equals(book));
        assertTrue("Book compared with itself should be equal",
                book.equals(book));
View Full Code Here

        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();
View Full Code Here

    public void testInsertWithForeignKeyConstraintViolation()
            throws TorqueException
    {
        // prepare
        cleanBookstore();
        Book book = new Book();
        book.setTitle("title");
        book.setIsbn("isbn");
        book.setAuthorId(1); // does not exist

        // execute & verify
        try
        {
            book.save();
            fail("Exception expected");
        }
        catch (ConstraintViolationException e)
        {
            assertTrue(e.getCause() instanceof SQLException);
View Full Code Here

        List<Book> books = BookPeer.doSelectJoinAuthor(criteria);

        assertTrue("books should contain 4 books but contains "
                + books.size(), books.size() == 4);
        Book bookTwo = books.get(1);
        Book bookThree = books.get(2);
        assertTrue ("the authors of BookTwo and BookThree"
                + " should point to the same instance",
                bookTwo.getAuthor() == bookThree.getAuthor());
    }
View Full Code Here

TOP

Related Classes of org.apache.torque.test.dbobject.Book

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.