1   /*
2    * DatabaseTest.java
3    * JUnit based test
4    *
5    * Created on May 5, 2004, 10:07 AM
6    */
7   
8   package gov.noaa.gdsg.xmldbremote.xmldbClient;
9   
10  import junit.framework.*;
11  import org.xmldb.api.base.Collection;
12  import org.xmldb.api.base.XMLDBException;
13  import org.xmldb.api.base.ErrorCodes;
14  import gov.noaa.gdsg.xmldbremote.xmldbClient.XmldbClientDatabase;
15  
16  /***
17   * Test case for testing the Database Class.  Before running be sure to set
18   * the static variable db.
19   * @author tns
20   * @version $Id: XmldbClientDatabaseTest.java,v 1.2 2004/12/29 01:08:05 mrxtravis Exp $
21   */
22  public class XmldbClientDatabaseTest extends TestCase {
23      
24      private String databaseEndpoint = "https://metadata-ssl.ngdc.noaa.gov/nmmr/services/nmmrdb";
25      private String acceptedURI = "xmldb:nmmr://metadata.ngdc.noaa.gov/nmmrdb/NGDC";
26      private String rejectedURI = "xmldb:blah ditty blah";
27      private String uriUsr = "guest";
28      private String uriPasswd = "guest";
29      
30      public static XmldbClientDatabase db = null;
31      
32      public XmldbClientDatabaseTest(java.lang.String testName) {
33          super(testName);
34      }
35      
36      public void setUp() throws Exception {
37          
38          db = new XmldbClientDatabase ();
39          db.setEndPointUrl(databaseEndpoint);
40          db.init();
41      }
42      
43      public static Test suite() {
44          TestSuite suite = new TestSuite(XmldbClientDatabaseTest.class);
45          return suite;
46      }
47      
48      /*** Test of acceptsURI method, of class gov.noaa.mm.xmldbImpl.BMSDatabase. */
49      public void testAcceptsURI() throws Exception {
50          System.out.println("testAcceptsURI");
51          
52          // Add your test code below by replacing the default call to fail.
53          boolean result = db.acceptsURI(acceptedURI);
54          assertTrue("Did not accept accepted URI",result);
55      }
56      
57      /*** Test of acceptsURI method, of class gov.noaa.mm.xmldbImpl.BMSDatabase. */
58      public void testRejectsURI() throws Exception {
59          System.out.println("testAcceptsURI");
60          boolean result = db.acceptsURI(rejectedURI);
61          assertFalse("Accept URI it shouldn't have",result);
62      }
63      
64      
65      
66      /*** Test of getCollection method, of class gov.noaa.mm.xmldbImpl.BMSDatabase. */
67      public void testGetCollection() throws Exception {
68          System.out.println("testGetCollection");
69          
70          // Add your test code below by replacing the default call to fail.
71          Collection collection = db.getCollection(acceptedURI, uriUsr,uriPasswd);
72          assertNotNull("Retrieval of collection with uir:" + acceptedURI,collection);
73          
74      }
75      
76      /*** Test of getCollection method, of class gov.noaa.mm.xmldbImpl.BMSDatabase. */
77      public void testGetInvalidCollection() throws Exception {
78          System.out.println("testGetInvalidCollection");
79          
80          // Add your test code below by replacing the default call to fail.
81          try {
82              Collection collection = db.getCollection("some kind of invalid collection", uriUsr,uriPasswd);
83              fail("Db did not throw exception on invalid collection request");
84          } catch (XMLDBException expected){
85  //            assertTrue("Exception thrown is not INVALID_COLLECTION " + e.getMessage()
86  //                , e.errorCode == ErrorCodes.INVALID_COLLECTION);
87          }
88      }
89      
90      /*** Test that a bag user name will not allow the retrieval of a collection **/
91      public void testGetPermissionDeniedGettingCollection() throws Exception {
92          System.out.println("testGetPermissionDeniedGettingCollection");
93          try {
94              Collection col = db.getCollection("acceptedURI", uriUsr, "some invalid passwordfljdfl;jlj");
95              fail("Request with bad password did not throw an exception");
96          } catch (XMLDBException e){
97  //            assertTrue("Exception thrown is not PERMISSION_DENIED " + e.getMessage()
98  //                , e.errorCode == ErrorCodes.PERMISSION_DENIED);
99          }
100     }
101     
102     
103     /*** Test of getConformanceLevel method, of class gov.noaa.mm.xmldbImpl.BMSDatabase. */
104     public void testGetConformanceLevel() throws Exception {
105         System.out.println("testGetConformanceLevel");
106         
107         // Add your test code below by replacing the default call to fail.
108         String conformanceLevel = db.getConformanceLevel();
109         assertNotNull("Conformance level is null",conformanceLevel);
110     }
111     
112     /*** Test of getName method, of class gov.noaa.mm.xmldbImpl.BMSDatabase. */
113     public void testGetName() throws Exception {
114         System.out.println("testGetName");
115         
116         // Add your test code below by replacing the default call to fail.
117         String name = db.getName();
118         assertNotNull("DB name is null",name);
119     }
120     
121     /*** Test of getProperty method, of class gov.noaa.mm.xmldbImpl.BMSDatabase. */
122     public void testGetProperty() throws Exception {
123         System.out.println("testGetProperty");
124         
125         // Add your test code below by replacing the default call to fail.
126         db.getProperty("blah");
127     }
128     
129     /*** Test of setProperty method, of class gov.noaa.mm.xmldbImpl.BMSDatabase. */
130     public void testSetProperty() throws Exception {
131         System.out.println("testSetProperty");
132         
133         // Add your test code below by replacing the default call to fail.
134         db.setProperty("blah", "blah");
135     }
136     
137     
138     
139     
140 }