1   /*
2    * Created on Feb 21, 2003
3    *
4    * To change this generated comment go to 
5    * Window>Preferences>Java>Code Generation>Code Template
6    */
7   package test.net.sf.fastxmldb;
8   
9   import net.sf.fastxmldb.impl.CollectionBroker;
10  import net.sf.fastxmldb.impl.LocalCollectionManagementService;
11  import net.sf.fastxmldb.utils.FastXMLDBConstants;
12  
13  import org.xmldb.api.DatabaseManager;
14  import org.xmldb.api.base.Collection;
15  import org.xmldb.api.base.Database;
16  import org.xmldb.api.base.XMLDBException;
17  import org.xmldb.api.modules.CollectionManagementService;
18  
19  import junit.framework.TestCase;
20  
21  /***
22   * @author jbirchfield
23   */
24  public class LocalCollectionManagementServiceTest extends TestCase {
25  
26      /***
27       * Constructor for LocalCollectionManagementServiceTest.
28       * @param arg0
29       */
30      public LocalCollectionManagementServiceTest(String arg0) {
31          super(arg0);
32      }
33  
34      /***
35       * @see TestCase#setUp()
36       */
37      protected void setUp() throws Exception {
38          super.setUp();
39          //since this is a singleton, clear it out first
40          CollectionBroker.getInstance().clearCollections();
41          Database database =
42              (Database) Class
43                  .forName(FastXMLDBConstants.FAST_XMLDB_DATABASE_CLASSNAME)
44                  .newInstance();
45  
46          DatabaseManager.registerDatabase(database);
47  
48      }
49  
50      /***
51       * @see TestCase#tearDown()
52       */
53      protected void tearDown() throws Exception {
54          super.tearDown();
55      }
56  
57      public void testCreateCollection() {
58          String collectionName = "test";
59          String testCollectionURI =
60              FastXMLDBConstants.DEFAULT_COLLECTION_URI + collectionName;
61          Collection col = null;
62          try {
63              col =
64                  DatabaseManager.getCollection(
65                      FastXMLDBConstants.DEFAULT_COLLECTION_URI);
66              CollectionManagementService service =
67                  (CollectionManagementService) col.getService(
68                      "CollectionManagementService",
69                      "1.0");
70              service.createCollection(collectionName);
71              Collection returnedCollection =
72                  DatabaseManager.getCollection(testCollectionURI);
73              assertEquals(returnedCollection.getName(), collectionName);
74          } catch (XMLDBException e) {
75              fail(e.getMessage());
76          } finally {
77              try {
78                  if (col != null) {
79                      col.close();
80                  }
81              } catch (XMLDBException e) {
82                  fail(e.getMessage());
83              }
84          }
85      }
86  
87      public void testGetName() {
88          Collection col = null;
89          try {
90              col =
91                  DatabaseManager.getCollection(
92                      FastXMLDBConstants.DEFAULT_COLLECTION_URI);
93              CollectionManagementService service =
94                  (CollectionManagementService) col.getService(
95                      "CollectionManagementService",
96                      "1.0");
97              assertEquals(
98                  service.getName(),
99                  LocalCollectionManagementService
100                     .COLLECTION_MANAGEMENT_SERVICE_NAME);
101         } catch (XMLDBException e) {
102             fail(e.getMessage());
103         } finally {
104             try {
105                 if (col != null) {
106                     col.close();
107                 }
108             } catch (XMLDBException e) {
109                 fail(e.getMessage());
110             }
111         }
112     }
113 
114     public void testGetVersion() {
115         Collection col = null;
116         try {
117             col =
118                 DatabaseManager.getCollection(
119                     FastXMLDBConstants.DEFAULT_COLLECTION_URI);
120             CollectionManagementService service =
121                 (CollectionManagementService) col.getService(
122                     "CollectionManagementService",
123                     "1.0");
124             assertEquals(
125                 service.getVersion(),
126                 LocalCollectionManagementService
127                     .COLLECTION_MANAGEMENT_SERVICE_VERSION);
128         } catch (XMLDBException e) {
129             fail(e.getMessage());
130         } finally {
131             try {
132                 if (col != null) {
133                     col.close();
134                 }
135             } catch (XMLDBException e) {
136                 fail(e.getMessage());
137             }
138         }
139     }
140 
141 }
This page was automatically generated by Maven