⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 threaddaojdotest.java

📁 Chinaxp 论坛源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        assertEquals("Update Thread Title", oldTitle + "AddedTitle.", pt.getTitle());        assertEquals("Update Thread Content", oldContent + "AddedContent.", pt.getContent());        assertEquals("Update thread Notify", !oldNotify, pt.isNotify());                // remove this thread        dao.removeThread( thread );/*        // back to original value        // change values        pt.setTitle(oldTitle);        pt.setContent(oldContent);        pt.setNotify(oldNotify);        // update        dao.updateThread(pt);*/    }    public void testUpdateClick() throws Exception {        ThreadDAOJDO dao = (ThreadDAOJDO) new LiberatorDAOFactory().getThreadDAO();        long current = System.currentTimeMillis();        org.redsoft.forum.dao.Thread thread = new org.redsoft.forum.dao.Thread(                "for testUpdateClick",                "hello, god",                "charles",                current,                -1,                category,                1,                0,                1234,                true);        dao.addThread(thread);        org.redsoft.forum.dao.Thread pt = dao.findByUID( thread.getId() );        int oldClick = pt.getClick();        dao.updateClick(pt.getId());        // query again        pt = dao.findByUID( thread.getId() );        assertEquals("New click count", pt.getClick(), oldClick + 1);                // remove thread        dao.removeThread( thread );    }    public void testFindByUserId() {        org.redsoft.forum.dao.Thread newThread = new org.redsoft.forum.dao.Thread(9990999l,                "my test title",                "Hello, world!",                USER,                System.currentTimeMillis(),                -1,                0,                category,                0, 0, 0, true);        org.redsoft.forum.dao.Thread anotherThread = new org.redsoft.forum.dao.Thread(9999099l,                "my another",                "hi",                USER,                System.currentTimeMillis(),                -1,                0,                category,                0, 0, 0, true);        final int numberOfThreads = 2;        final String testUserId = USER;        ThreadDAOJDO dao = (ThreadDAOJDO) new LiberatorDAOFactory().getThreadDAO();        try {            // initially, I add 2 threads created by myself:john liu to database            dao.addThread(newThread);            dao.addThread(anotherThread);            // test the method here            Collection listOfTestThreads = dao.findByUserId(testUserId, 1, 3);            assertEquals("Expecting 3", numberOfThreads, listOfTestThreads.size());            for (Iterator itOfThread = listOfTestThreads.iterator(); itOfThread.hasNext();) {                // get the PersistentThread Objects returned by findByUserID()                org.redsoft.forum.dao.Thread testThread = (org.redsoft.forum.dao.Thread) itOfThread.next();                assertEquals("Expecting JUnit Tester For findByUserId", testUserId, testThread.getAuthor());            }            dao.removeThread(newThread);            dao.removeThread(anotherThread);        } catch (final ClassCastException cce) {            cce.printStackTrace();            fail("The list returned from FindByUserId(String) is not a list of PersistentThread object");        } catch (final Exception e) {            e.printStackTrace();            fail("Unexpected exception::" + e.getMessage());        }    }    public void testRemoveThreadByID() {        try {            ThreadDAOJDO dao = (ThreadDAOJDO) new LiberatorDAOFactory().getThreadDAO();            long current = System.currentTimeMillis();            org.redsoft.forum.dao.Thread thread = new org.redsoft.forum.dao.Thread(                    "my first",                    "hello I can't have it. \"world\",hello world",                    "charles",                    current,                    -1,                    category,                    1,                    0, 0, true);            thread = dao.addThread(thread);            dao.removeThread(thread.getId());            dao.findByUID(thread.getId());            fail("Expecting ThreadNotFoundException");        } catch (final ThreadNotFoundException ex) {            //pass        } catch (final Exception e) {            e.printStackTrace();            fail("Unexpected exception::" + e.toString());        }    }    public void testRemoveThreadNotExistID() {        try {            ThreadDAOJDO dao = (ThreadDAOJDO) new LiberatorDAOFactory().getThreadDAO();            dao.removeThread(1000);        } catch (final Exception e) {            e.printStackTrace();            fail("Unexpected exception::" + e.toString());        }    }    public void testRemoveChildrenThread() {        try {            ThreadDAOJDO dao = (ThreadDAOJDO) new LiberatorDAOFactory().getThreadDAO();            long current = System.currentTimeMillis();            org.redsoft.forum.dao.Thread thread = new org.redsoft.forum.dao.Thread(                    "my first",                    "hello I can't have it. \"world\",hello world",                    "charles",                    current,                    -1,                    category,                    0,                    0, 0, true);            thread = dao.addThread(thread);            org.redsoft.forum.dao.Thread thread_1 = new org.redsoft.forum.dao.Thread("my first",                    "hello I can't have it. \"world\",hello world",                    "charles",                    current,                    thread.getId(),                    category,                    0,                    0, 0, true);            org.redsoft.forum.dao.Thread thread_2 = new org.redsoft.forum.dao.Thread("my second",                    "hello I can't have it. \"world\",hello world",                    "charles",                    current,                    thread.getId(),                    category,                    0,                    0, 0, true);            thread_1 = dao.addThread(thread_1);            thread_2 = dao.addThread(thread_2);            thread = dao.findByUID(thread.getId());            assertEquals("Expecting 2", 2, thread.getReply());            dao.removeThread(thread_1.getId());            thread = dao.findByUID(thread.getId());            assertEquals("Expecting 1", 1, thread.getReply());            dao.removeThread(thread_2.getId());            thread = dao.findByUID(thread.getId());            assertEquals("Expecting 0", 0, thread.getReply());            dao.removeThread(thread.getId());        } catch (final Exception e) {            e.printStackTrace();            fail("Unexpected exception::" + e.toString());        }    }    public void testRemoveChildrenThreadByID() {        try {            ThreadDAOJDO dao = (ThreadDAOJDO) new LiberatorDAOFactory().getThreadDAO();            long current = System.currentTimeMillis();            org.redsoft.forum.dao.Thread thread = new org.redsoft.forum.dao.Thread(                    "my first",                    "hello I can't have it. \"world\",hello world",                    "charles",                    current,                    -1,                    category,                    0,                    0, 0, true);            thread = dao.addThread(thread);            org.redsoft.forum.dao.Thread thread_1 = new org.redsoft.forum.dao.Thread("my first",                    "hello I can't have it. \"world\",hello world",                    "charles",                    current,                    thread.getId(),                    category,                    0,                    0, 0, true);            org.redsoft.forum.dao.Thread thread_2 = new org.redsoft.forum.dao.Thread("my second",                    "hello I can't have it. \"world\",hello world",                    "charles",                    current,                    thread.getId(),                    category,                    0,                    0, 0, true);            thread_1 = dao.addThread(thread_1);            thread_2 = dao.addThread(thread_2);            thread = dao.findByUID(thread.getId());            assertEquals("Expecting 2", 2, thread.getReply());            dao.removeThread(thread_1);            thread = dao.findByUID(thread.getId());            assertEquals("Expecting 1", 1, thread.getReply());            dao.removeThread(thread_2);            thread = dao.findByUID(thread.getId());            assertEquals("Expecting 0", 0, thread.getReply());            dao.removeThread(thread);        } catch (final Exception e) {            e.printStackTrace();            fail("Unexpected exception::" + e.toString());        }    }    public void testFindThreadsPostedLaterThan() {        ThreadDAOJDO dao = (ThreadDAOJDO) new LiberatorDAOFactory().getThreadDAO();        org.redsoft.forum.dao.Thread thread_1 = new org.redsoft.forum.dao.Thread("first",                "hello I can't have it. \"world\",hello world",                "cinc",                System.currentTimeMillis(),                -1,                category,                0,                0, 0, true);        org.redsoft.forum.dao.Thread thread_2 = new org.redsoft.forum.dao.Thread("re:first",                "oh u can have it. \"world\",hello world",                "cinc",                System.currentTimeMillis(),                thread_1.getId(),                category,                0,                0, 0, true);        org.redsoft.forum.dao.Thread thread_3 = new org.redsoft.forum.dao.Thread("second",                "oh my god",                "cinc",                System.currentTimeMillis(),                -1,                category,                0,                0, 0, true);        org.redsoft.forum.dao.Thread thread_4 = new org.redsoft.forum.dao.Thread("re:second",                "oh your god",                "cinc",                System.currentTimeMillis(),                thread_3.getId(),                category,                0,                0, 0, true);        try {            // add thread_1 before testTime            thread_1.setTimeStamp(System.currentTimeMillis());            thread_1 = dao.addThread(thread_1);            // testTime            // wait for a while            try {                java.lang.Thread.sleep(500);            } catch (Exception e) {            }            long testTime = System.currentTimeMillis();            //System.out.println ("\nTest time: " + testTime);            // wait for a while            try {                java.lang.Thread.sleep(500);            } catch (Exception e) {            }            // add thread_2 : reply of thread_1            thread_2.setTimeStamp(System.currentTimeMillis());            thread_2 = dao.addThread(thread_2);            // add thread_3            thread_3.setTimeStamp(System.currentTimeMillis());            thread_3 = dao.addThread(thread_3);            // add thread_4 : reply of thread_3            thread_4.setTimeStamp(System.currentTimeMillis());            thread_4 = dao.addThread(thread_4);            Collection list = dao.findThreadsPostedLaterThan(testTime);            assertEquals("Expecting 3", 3, list.size());            // remove threads        } catch (final DAOException daoException) {            daoException.printStackTrace();            fail("Unexpected exeption:" + daoException.toString());        } finally {            try {                dao.removeThread(thread_4);                dao.removeThread(thread_3);                dao.removeThread(thread_2);                dao.removeThread(thread_1);            } catch (DAOException e) {            }        }    }    public void testUpdateColumnThread() {        ThreadDAOJDO dao = (ThreadDAOJDO) new LiberatorDAOFactory().getThreadDAO();        org.redsoft.forum.dao.Thread thread = new org.redsoft.forum.dao.Thread(                "my first",                "hello world,hello world",                "charles",                System.currentTimeMillis(),                -1,                category,                0,                0,                0,                true);        try {            dao.addThread(thread);            thread.setColumnThread(true);            dao.addColumnThread(thread.getId());            PersistentThread thread_AddedToColumn = dao.findByUID(thread.getId());            assertEquals("should be true", true, thread_AddedToColumn.isColumnThread());            thread_AddedToColumn.setColumnThread(false);            dao.removeColumnThread(thread_AddedToColumn.getId());            PersistentThread thread_RemovedFromColumn = dao.findByUID(thread.getId());            assertEquals("should be false", false, thread_RemovedFromColumn.isColumnThread());        } catch (final DAOException daoException) {            daoException.printStackTrace();            fail("Unexpected exeption:" + daoException.toString());        } catch (ThreadNotFoundException e) {            fail("Unexpected exeption:" + e.toString());        } finally {            try {                dao.removeThread(thread);            } catch (DAOException daoe) {            }        }    }    public void testFindColumnThreadsByAccountId() {        ThreadDAOJDO dao = (ThreadDAOJDO) new LiberatorDAOFactory().getThreadDAO();        try {            Collection results = dao.findColumnThreadsByAccountId( "testuser" );            assertNotNull( "results", results );        } catch (DAOException daoe) {            fail( "DB error" + daoe.getMessage() );        }    }    public void testFindCountByUserId() {        ThreadDAOJDO dao = (ThreadDAOJDO) new LiberatorDAOFactory().getThreadDAO();        org.redsoft.forum.dao.Thread thread = new org.redsoft.forum.dao.Thread(                "my first",                "hello world",                "testuser",                System.currentTimeMillis(),                -1,                category,                0,                0,                0,                true);        try {            dao.addThread( thread );            assertTrue( "list size should not be zero", dao.findCountByUserId( "testuser" ) != 0 );            dao.removeThread( thread );        } catch (DAOException daoe) {            fail( "DB error" + daoe.getMessage() );        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -