Package org.apache.torque.test.dbobject

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


    public void testInsertWithPkViolation() throws TorqueException
    {
        // prepare
        cleanBookstore();
        List<Author> bookstoreContent = insertBookstoreData();
        Author author = new Author();
        author.setName("Author");
        author.setAuthorId(bookstoreContent.get(0).getAuthorId());

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


    public void testInsertWithNonNullableColumnViolation()
            throws TorqueException
    {
        // prepare
        cleanBookstore();
        Author author = new Author();
        author.setName(null); // is required

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

            transaction1 = Transaction.begin();
            if (transaction1.getAutoCommit())
            {
                fail("autocommit must be set to false for this test");
            }
            Author author1 = bookstoreContent.get(0);
            author1.setName("new Author1");
            author1.save(transaction1);

            // lock author 2 in transaction 2
            transaction2 = Transaction.begin();
            if (transaction2.getAutoCommit())
            {
                fail("autocommit must be set to false for this test(2)");
            }
            Author author2 = bookstoreContent.get(1);
            author2.setName("new Author2");
            author2.save(transaction2);

            // lock author 2 in transaction 1 (must wait for lock)
            author2.setName("newer Author2");
            SaveAndRollbackThread saveThreadTransaction1
                = new SaveAndRollbackThread(
                        author2,
                        transaction1,
                        "saveThreadAuthor2Con1");
            saveThreadTransaction1.start();

            long startTime = System.currentTimeMillis();
            while (!author2.isSaving() && author2.isModified()
                    && saveThreadTransaction1.isAlive())
            {
                Thread.sleep(SLEEP_TIME);
                if (System.currentTimeMillis() > startTime + TIMEOUT)
                {
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);
            author.save();
            if (-1 == firstAuthorId)
            {
                firstAuthorId = author.getAuthorId();
            }
        }
        // Set up the standard criteria for the test.
        criteria = new Criteria();
        criteria.where(AuthorPeer.NAME, LARGE_SELECT_AUTHOR);
View Full Code Here

     * @throws TorqueException if saving fails.
     */
    protected void insertTestData() throws TorqueException
    {
        // insert test data
        Author author = new Author();
        author.setName("Author with one book");
        author.save();
        Book book = new Book();
        book.setAuthor(author);
        book.setTitle("Book 1");
        book.setIsbn("unknown");
        book.save();

        author = new Author();
        author.setName("Author without book");
        author.save();

        author = new Author();
        author.setName("Author with three books");
        author.save();
        for (int bookNr = 2; bookNr <=4; bookNr++)
        {
            book = new Book();
            book.setAuthor(author);
            book.setTitle("Book " + bookNr);
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

    public void testGetRelatedObjects() throws Exception
    {
        Criteria criteria = new Criteria().where(
                AuthorPeer.AUTHOR_ID,
                authorList.get(0).getAuthorId());
        Author author = AuthorPeer.doSelect(criteria).get(0);

        // execute loading books
        List<Book> books = author.getBooks();

        // verify
        assertEquals(10, books.size());
        assertTrue(books.get(0).getTitle().endsWith("- Author 1"));
    }
View Full Code Here

    public void testGetRelatedObjectsAfterInit() throws Exception
    {
        Criteria criteria = new Criteria().where(
                AuthorPeer.AUTHOR_ID,
                authorList.get(0).getAuthorId());
        Author author = AuthorPeer.doSelect(criteria).get(0);

        // execute : init, then load books
        author.initBooks();
        List<Book> books = author.getBooks();

        // verify
        // Books should not be loaded from db but cache should be used
        assertEquals(0, books.size());
    }
View Full Code Here

    public void testGetRelatedObjectsWithCriteria() throws Exception
    {
        Criteria criteria = new Criteria().where(
                AuthorPeer.AUTHOR_ID,
                authorList.get(0).getAuthorId());
        Author author = AuthorPeer.doSelect(criteria).get(0);
        Book book = authorList.get(0).getBooks().get(2);

        // execute : load books
        criteria = new Criteria().where(BookPeer.BOOK_ID, book.getBookId());
        List<Book> books = author.getBooks(criteria);

        // verify
        assertEquals(1, books.size());
        assertEquals(book.getBookId(), books.get(0).getBookId());
    }
View Full Code Here

    public void testGetRelatedObjectsWithOtherCriteria() throws Exception
    {
        Criteria criteria = new Criteria().where(
                AuthorPeer.AUTHOR_ID,
                authorList.get(0).getAuthorId());
        Author author = AuthorPeer.doSelect(criteria).get(0);
        author.getBooks();
        Book book = authorList.get(0).getBooks().get(2);

        // execute : load books
        criteria = new Criteria().where(BookPeer.BOOK_ID, book.getBookId());
        List<Book> books = author.getBooks(criteria);

        // verify
        assertEquals(1, books.size());
        assertEquals(book.getBookId(), books.get(0).getBookId());
    }
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.