Package org.apache.torque.test

Examples of org.apache.torque.test.Author


    public void testInsertData() throws Exception
    {
        // insert books and authors
        for (int i = 1; i <= 10; i++)
        {
            Author author = new Author();
            author.setName("Author " + i);
            author.save();
            assertTrue("authorId should not be 0 after insert",
                    author.getAuthorId() != 0);

            for (int j = 1; j <= 10; j++)
            {
                Book book = new Book();
                book.setAuthor(author);
View Full Code Here


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

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

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

        // delete without matching data
        Criteria criteria = new Criteria();
        criteria.add(
                AuthorPeer.AUTHOR_ID,
                author.getAuthorId(),
                Criteria.NOT_EQUAL);
        AuthorPeer.doDelete(criteria);
        List authorResult = AuthorPeer.doSelect(new Criteria());
        assertTrue("deleted too many records", authorResult.size() == 1);

        BookPeer.doDelete(book);
        List bookResult = BookPeer.doSelect(new Criteria());
        authorResult = AuthorPeer.doSelect(new Criteria());
        // check that the book has disappeared
        assertTrue("delete by object failed",
            bookResult.size() == 0);
        // check that the underlying author has not been deleted
        assertTrue("delete by object deleted in cascade",
            authorResult.size() == 1);

        // delete with matching data
        criteria.clear();
        criteria.add(AuthorPeer.AUTHOR_ID, author.getAuthorId());
        AuthorPeer.doDelete(criteria);
        authorResult = AuthorPeer.doSelect(new Criteria());
        assertTrue("deleted not enough records",
            authorResult.size() == 0);
    }
View Full Code Here

        criteria = new Criteria();
        criteria.add(BookPeer.BOOK_ID, (Long) null, Criteria.NOT_EQUAL);
        BookPeer.doDelete(criteria, null);

        Author author = new Author();
        author.setName("name");
        author.save((Connection) null);
    }
View Full Code Here

    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

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

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.