Package org.apache.torque.test

Examples of org.apache.torque.test.Author


    public void testJoins() throws Exception
    {
        cleanBookstore();

        // 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


    public void testOrderBy() throws Exception
    {
        cleanBookstore();

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

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

        Author author = new Author();
        author.setName("AuTHor");
        author.save();
       
        Criteria criteria = new Criteria();
        criteria.add(AuthorPeer.NAME, author.getName().toLowerCase());
        criteria.setIgnoreCase(true);
        List result = AuthorPeer.doSelect(criteria);
        if (result.size() != 1)
        {
            fail("Size of result is not 1, but " + result.size());
View Full Code Here

     * @throws Exception if the test fails
     */
    public void testSameColumnName() throws Exception
    {
        cleanBookstore();
        Author author = new Author();
        author.setName("Name");
        author.save();
       
        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);
        List villageRecords = BookPeer.doSelectVillageRecords(criteria);
        Record record = (Record) villageRecords.get(0);
        book = new Book();
        BookPeer.populateObject(record, 1, book);
        author = new Author();
        AuthorPeer.populateObject(record, BookPeer.numColumns + 1, author);

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

     * @throws Exception if the test fails
     */
    public void testCountHelper() throws Exception
    {
        cleanBookstore();
        Author author = new Author();
        author.setName("Name");
        author.save();
       
        author = new Author();
        author.setName("Name2");
        author.save();
       
        author = new Author();
        author.setName("Name");
        author.save();
       
        Criteria criteria = new Criteria();
        int count = new CountHelper().count(
                criteria,
                null,
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.