1 package test.xmldb.other; 8 9 import junit.framework.Test; 10 import junit.framework.TestCase; 11 import junit.framework.TestSuite; 12 import org.ozoneDB.ExternalDatabase; 13 import org.ozoneDB.OzoneInterface; 14 import org.ozoneDB.xml.core.XMLCollection; 15 import org.ozoneDB.xml.core.XMLCollectionImpl; 16 import org.xmldb.api.base.Collection; 17 import org.xmldb.api.base.Database; 18 19 24 public class ConnectionTest extends TestCase { 25 26 ExternalDatabase db = null; 27 Database xmlDB = null; 28 String databaseClass = "org.ozoneDB.xml.cli.DatabaseImpl"; 29 String dbURI = "ozonedb:remote://localhost:3333"; 30 String collectionName="per"; 31 32 String collectionURI = "xmldb:ozonexml://localhost:3333?" + collectionName; 41 42 45 public ConnectionTest(String name) { 46 super(name); 47 } 48 49 public static Test suite() { 50 return new TestSuite(ConnectionTest.class); 51 } 52 61 64 public void testCycle() { 65 try { 66 create(); 67 get(); 68 delete(); 69 } catch (Exception e) { 70 fail( e.getMessage( ) ); 71 } 72 } 73 74 private void connect() throws Exception { 75 if (db == null || !db.isOpen()) { 76 xmlDB = (Database)Class.forName(databaseClass).newInstance(); 78 db = ExternalDatabase.openDatabase(dbURI); 79 db.reloadClasses(); 80 } 81 } 82 private void create() throws Exception { 83 connect(); 84 assertNotNull(db); 85 XMLCollection root = (XMLCollection)db.createObject( XMLCollectionImpl.class.getName(), OzoneInterface.Public, collectionName); 87 root.setName(collectionName); 88 db.close(); 89 assertTrue(!db.isOpen()); 90 } 91 private void delete() throws Exception { 92 connect(); 93 assertNotNull(db); 94 db.deleteObject(db.objectForName(collectionName)); 95 db.close(); 96 assertTrue(!db.isOpen()); 97 } 98 private void get() throws Exception { 99 connect(); 100 assertNotNull(db); 101 Collection rootCol = xmlDB.getCollection(collectionURI); 102 103 assertTrue(rootCol instanceof org.ozoneDB.xml.cli.CollectionImpl); 105 assertEquals(collectionName, rootCol.getName()); 106 } 107 108 } | Popular Tags |