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

📄 storagetest.java

📁 这个是perst-269.zip下面的SOURCECODE,和大家分享了。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $URL: StorageTest.java $  * $Rev: 147 $  * $Date: 2005-07-08 19:43:40 +0400 (Fri, 08 Jul 2005) $ * * Copyright 2005 Netup, Inc. All rights reserved. * URL:    http://www.netup.biz * e-mail: info@netup.biz */package org.garret.perst;import static org.garret.perst.Storage.INFINITE_PAGE_POOL;import junit.framework.*;import java.util.*;import java.io.File;/** * These tests verifies an implementation of the <code>Storage</code> interface. <br /> * The implementation is created by the following way : * <pre> *   storage = org.garret.perst.StorageFactory.getInstance().createStorage() * </pre> * <p> * In test are used simple <CODE>Persistent</CODE> class <CODE>Stored</CODE>: * <pre> *   class Stored extends Persistent { *       public String name; *   } * </pre> */public class StorageTest extends TestCase {    Storage storage;    public StorageTest(String testName) {        super(testName);    }    public static junit.framework.Test suite()    {        junit.framework.TestSuite suite =                new junit.framework.TestSuite(StorageTest.class);        return suite;    }    protected void setUp() throws java.lang.Exception {        storage = StorageFactory.getInstance().createStorage();    }    protected void tearDown() throws java.lang.Exception {        if(storage.isOpened()){            storage.close();        }        try {            (new File("StorageTest.dbs")).delete();        } catch (Exception e) {        }    }    /**     * <B>Goal:</B> To verify the functionality of the <CODE>open(...)</CODE> method.     * <P>     * <B>Conditions:</B>     * <ul>     * <li>The <code>open(...)</code> method is invoked.</li>     * </ul>     * <P>     * <B>Result:</B>     * <ul>     * <li>no exceptions are thrown.</li>     * <li><code>isOpened()</code> returned <i>true</i>.</li>     * </ul>     */    public void testOpen(){        storage.open(new NullFile(), INFINITE_PAGE_POOL);        assertTrue(storage.isOpened());    }    /**     * <B>Goal:</B> To verify the functionality of the <CODE>createQuery()</CODE> method.     * <P>     * <B>Conditions:</B>     * <ul>     * <li><code>createQuery()</code> are invoked.</li>     * </ul>     * <P>     * <B>Result:</B>     * <ul>     * <li>no exceptions are thrown.</li>     * <li><code>createQuery()</code> returned not-<i>null</i> object.</li>     * </ul>     */    public void testCreateQuery(){        storage.open(new NullFile(), INFINITE_PAGE_POOL);        assertTrue(storage.isOpened());        Query q = storage.createQuery();        assertNotNull(q);    }    /**     * <B>Goal:</B> To verify the functionality of the <CODE>createIndex()</CODE> method.     * <P>     * <B>Conditions:</B>     * <ul>     * <li><code>createIndex()</code> are invoked.</li>     * </ul>     * <P>     * <B>Result:</B>     * <ul>     * <li>no exceptions are thrown.</li>     * <li><code>createIndex()</code> returned not-<i>null</i> object.</li>     * </ul>     */    public void testCreateIndex() {        storage.open(new NullFile(), INFINITE_PAGE_POOL);        assertTrue(storage.isOpened());        Index<Root> idx = storage.createIndex(Root.class, false);        assertNotNull(idx);    }    /**     * <B>Goal:</B> To verify the functionality of the <CODE>createFieldIndex()</CODE> method.     * <P>     * <B>Conditions:</B>     * <ul>     * <li><code>createFieldIndex()</code> are invoked.</li>     * </ul>     * <P>     * <B>Result:</B>     * <ul>     * <li>no exceptions are thrown.</li>     * <li><code>createFieldIndex()</code> returned not-<i>null</i> object.</li>     * </ul>     */    public void testCreateFieldIndex() {        storage.open(new NullFile(), INFINITE_PAGE_POOL);        assertTrue(storage.isOpened());        FieldIndex<Root> idx = storage.createFieldIndex(Root.class, "i", false);        assertNotNull(idx);    }    /**     * <B>Goal:</B> To verify the functionality of the <CODE>createLink()</CODE> method.     * <P>     * <B>Conditions:</B>     * <ul>     * <li><code>createLink()</code> are invoked.</li>     * </ul>     * <P>     * <B>Result:</B>     * <ul>     * <li>no exceptions are thrown.</li>     * <li><code>createLink()</code> returned not-<i>null</i> object.</li>     * </ul>     */    public void testCreateLink() {        storage.open(new NullFile(), INFINITE_PAGE_POOL);        assertTrue(storage.isOpened());        Link<Root> l = storage.createLink();        assertNotNull(l);    }    /**     * <B>Goal:</B> To verify the functionality of the <CODE>createBlob()</CODE> method.     * <P>     * <B>Conditions:</B>     * <ul>     * <li><code>createBlob()</code> are invoked.</li>     * </ul>     * <P>     * <B>Result:</B>     * <ul>     * <li>no exceptions are thrown.</li>     * <li><code>createBlob()</code> returned not-<i>null</i> object.</li>     * </ul>     */    public void testCreateBlob() {        storage.open(new NullFile(), INFINITE_PAGE_POOL);        assertTrue(storage.isOpened());        Blob b = storage.createBlob();        assertNotNull(b);    }    /**     * <B>Goal:</B> To verify the functionality of the <CODE>createSet()</CODE> method.     * <P>     * <B>Conditions:</B>     * <ul>     * <li><code>createSet()</code> are invoked.</li>     * </ul>     * <P>     * <B>Result:</B>     * <ul>     * <li>no exceptions are thrown.</li>     * <li><code>createSet()</code> returned not-<i>null</i> object.</li>     * </ul>     */    public void testCreateSet(){        storage.open(new NullFile(), INFINITE_PAGE_POOL);        assertTrue(storage.isOpened());        IPersistentSet ps = storage.createSet();        assertNotNull(ps);    }    /**     * <B>Goal:</B> To verify the functionality of the <CODE>getRoot()</CODE> method.     * <P>     * <B>Conditions:</B>     * <ul>     * <li>The <code>getRoot()</code> method is invoked.</li>     * </ul>     * <P>     * <B>Result:</B>     * <ul>     * <li>no exceptions are thrown.</li>     * <li><code>getRoot()</code> returned <i>null</i>.</li>     * </ul>     */    public void testGetRoot(){        storage.open(new NullFile(), INFINITE_PAGE_POOL);        assertNull(storage.getRoot());    }    /**     * <B>Goal:</B> To verify the functionality of the <CODE>setRoot(...)</CODE> and     * <CODE>getRoot()</CODE> methods.     * <P>     * <B>Conditions:</B>     * <ul>     * <li>The <code>setRoot(root)</code> method is invoked.</li>     * <li>The <code>getRoot()</code> method is invoked.</li>     * </ul>     * <P>     * <B>Result:</B>     * <ul>     * <li>no exceptions are thrown.</li>     * <li><code>getRoot()</code> returned <i>root</i>.</li>     * </ul>     */    public void testSetRoot(){        storage.open(new NullFile(), INFINITE_PAGE_POOL);        Root root = new Root( (IPersistentSet)storage.createSet() );        storage.setRoot(root);        assertEquals(storage.getRoot(), root);    }    /**     * <B>Goal:</B> To verify the functionality of the <CODE>commit()</CODE> method.     * <P>     * <B>Conditions:</B>     * <ul>     * <li><code>root</code> object implements the <code>Persistent</code>     * interface.</li>     * <li>The <code>setRoot(root)</code> method is invoked.</li>     * <li>The <code>commit()</code> method is invoked.</li>     * <li>The <code>getRoot()</code> method is invoked.</li>     * </ul>     * <P>     * <B>Result:</B>     * <ul>     * <li>no exceptions are thrown.</li>     * <li><code>getRoot()</code> returned <i>root</i>.</li>     * </ul>     */    public void testCommit(){        storage.open(new NullFile(), INFINITE_PAGE_POOL);        Root root = new Root( (IPersistentSet) storage.createSet() );        root.i = 64;        storage.setRoot(root);        storage.commit();        root = (Root)storage.getRoot();        assertEquals(root.i, 64);    }    /**     * <B>Goal:</B> To verify the transaction functionality.     * <P>     * <B>Conditions:</B>     * <ul>     * <li>The <code>setRoot(root)</code> method is invoked.</li>     * <li>The <code>commit()</code> method is invoked.</li>     * <li>The <code>rollback()</code> method is invoked.</li>     * <li>The <code>getRoot()</code> method is invoked.</li>     * </ul>     * <P>     * <B>Result:</B>     * <ul>     * <li>no exceptions are thrown.</li>     * <li><code>getRoot()</code> returned <i>root</i>.</li>     * </ul>     */    public void testTransaction00(){        storage.open(new NullFile(), INFINITE_PAGE_POOL);        Root root = new Root( (IPersistentSet) storage.createSet() );        root.i = 128;        storage.setRoot(root);        storage.commit();        storage.rollback();        root = (Root)storage.getRoot();        assertEquals(root.i, 128);    }

⌨️ 快捷键说明

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