Author: akarasulu
Date: Wed Apr 28 23:36:52 2004
New Revision: 10418
Added:
incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/application/JeApplicationFactoryTest.java
(contents, props changed)
Log:
preliminary test case
Added: incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/application/JeApplicationFactoryTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/application/JeApplicationFactoryTest.java
Wed Apr 28 23:36:52 2004
@@ -0,0 +1,322 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permission and
+ * limitations under the License.
+ *
+ */
+package org.apache.rms.je.application ;
+
+
+import com.sleepycat.je.* ;
+
+import org.apache.rms.RmsException ;
+import org.apache.rms.je.AbstractJeTest ;
+import org.apache.rms.je.sequence.Sequence ;
+import org.apache.rms.je.sequence.JeSequenceDao ;
+import org.apache.rms.je.sequence.JeSequenceFactory ;
+
+import java.util.Iterator ;
+
+
+/**
+ * Tests the JeApplicationDAO class.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JeApplicationFactoryTest extends AbstractJeTest
+{
+ JeApplicationDAO dao ;
+ JeApplicationFactory factory ;
+
+
+ protected void setUp() throws Exception
+ {
+ DatabaseConfig conf = new DatabaseConfig() ;
+ conf.setAllowCreate( true ) ;
+ setupDb( "seqDb", conf ) ;
+ super.setUp() ;
+
+ SecondaryConfig sconf = new SecondaryConfig() ;
+ sconf.setAllowCreate( true ) ;
+ sconf.setAllowDuplicates( true ) ;
+ sconf.setKeyCreator( new JeAppNameKeyCreator() ) ;
+ env.openSecondaryDatabase( null, JeApplicationDAO.APP_SECDB,
+ sconf, db ) ;
+
+ JeSequenceDao seqDAO = new JeSequenceDao( getDb( "seqDb" ) ) ;
+ JeSequenceFactory seqFactory = new JeSequenceFactory( seqDAO ) ;
+ Sequence seq = seqFactory.create( "applicationSeq" ) ;
+ dao = new JeApplicationDAO( db, seq ) ;
+ dao.setMonitor( new LoggingApplicationDAOMonitor() ) ;
+ factory = new JeApplicationFactory( dao ) ;
+ }
+
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown() ;
+ dao = null ;
+ }
+
+
+ public void testCreateAndGet() throws Exception
+ {
+ try
+ {
+ factory.getApplication( "app1" ) ;
+ fail( "should never get here because of an exception" ) ;
+ }
+ catch ( RmsException e )
+ {
+ e.printStackTrace();
+ }
+
+ factory.createApplication( "app1" ) ;
+ factory.createApplication( "app2" ) ;
+ factory.createApplication( "app3" ) ;
+ factory.createApplication( "app4" ) ;
+
+ assertNotNull( factory.getApplication( "app1" ) ) ;
+ assertNotNull( factory.getApplication( "app2" ) ) ;
+ assertNotNull( factory.getApplication( "app3" ) ) ;
+ assertNotNull( factory.getApplication( "app4" ) ) ;
+
+ try
+ {
+ factory.getApplication( "app5" ) ;
+ fail( "should never get here because of an exception" ) ;
+ }
+ catch ( RmsException e )
+ {
+ }
+ }
+
+
+ public void testCreateHasAndDelete() throws Exception
+ {
+ try
+ {
+ factory.getApplication( "app1" ) ;
+ fail( "should never get here because of an exception" ) ;
+ }
+ catch ( RmsException e )
+ {
+ e.printStackTrace();
+ }
+
+ factory.createApplication( "app1" ) ;
+ factory.createApplication( "app2" ) ;
+ factory.createApplication( "app3" ) ;
+ factory.createApplication( "app4" ) ;
+
+ assertNotNull( factory.getApplication( "app1" ) ) ;
+ assertNotNull( factory.getApplication( "app2" ) ) ;
+ assertNotNull( factory.getApplication( "app3" ) ) ;
+ assertNotNull( factory.getApplication( "app4" ) ) ;
+
+ try
+ {
+ factory.getApplication( "app5" ) ;
+ fail( "should never get here because of an exception" ) ;
+ }
+ catch ( RmsException e )
+ {
+ }
+
+ factory.deleteApplication( "app1" ); ;
+ factory.deleteApplication( "app2" ) ;
+ factory.deleteApplication( "app3" ) ;
+ factory.deleteApplication( "app4" ) ;
+
+ try
+ {
+ factory.getApplication( "app1" ) ;
+ fail( "should never get here because of an exception" ) ;
+ }
+ catch ( RmsException e )
+ {
+ }
+
+ try
+ {
+ factory.getApplication( "app2" ) ;
+ fail( "should never get here because of an exception" ) ;
+ }
+ catch ( RmsException e )
+ {
+ }
+
+ try
+ {
+ factory.getApplication( "app3" ) ;
+ fail( "should never get here because of an exception" ) ;
+ }
+ catch ( RmsException e )
+ {
+ }
+
+ try
+ {
+ factory.getApplication( "app4" ) ;
+ fail( "should never get here because of an exception" ) ;
+ }
+ catch ( RmsException e )
+ {
+ }
+ }
+
+
+ public void testCreateHasAndRename() throws Exception
+ {
+ try
+ {
+ factory.getApplication( "app1" ) ;
+ fail( "should never get here because of an exception" ) ;
+ }
+ catch ( RmsException e )
+ {
+ e.printStackTrace();
+ }
+
+ factory.createApplication( "app1" ) ;
+ factory.createApplication( "app2" ) ;
+ factory.createApplication( "app3" ) ;
+ factory.createApplication( "app4" ) ;
+
+ assertNotNull( factory.getApplication( "app1" ) ) ;
+ assertNotNull( factory.getApplication( "app2" ) ) ;
+ assertNotNull( factory.getApplication( "app3" ) ) ;
+ assertNotNull( factory.getApplication( "app4" ) ) ;
+
+ try
+ {
+ factory.getApplication( "app5" ) ;
+ fail( "should never get here because of an exception" ) ;
+ }
+ catch ( RmsException e )
+ {
+ }
+
+ factory.renameApplication( "app1", "app5" ); ;
+ factory.renameApplication( "app2", "app6" ) ;
+ factory.renameApplication( "app3", "app7" ) ;
+ factory.renameApplication( "app4", "app8" ) ;
+
+ try
+ {
+ factory.getApplication( "app1" ) ;
+ fail( "should never get here because of an exception" ) ;
+ }
+ catch ( RmsException e )
+ {
+ }
+
+ try
+ {
+ factory.getApplication( "app2" ) ;
+ fail( "should never get here because of an exception" ) ;
+ }
+ catch ( RmsException e )
+ {
+ }
+
+ try
+ {
+ factory.getApplication( "app3" ) ;
+ fail( "should never get here because of an exception" ) ;
+ }
+ catch ( RmsException e )
+ {
+ }
+
+ try
+ {
+ factory.getApplication( "app4" ) ;
+ fail( "should never get here because of an exception" ) ;
+ }
+ catch ( RmsException e )
+ {
+ }
+
+ assertNotNull( factory.getApplication( "app5" ) ); ;
+ assertNotNull( factory.getApplication( "app6" ) ); ;
+ assertNotNull( factory.getApplication( "app7" ) ); ;
+ assertNotNull( factory.getApplication( "app8" ) ); ;
+
+ try
+ {
+ factory.renameApplication( "app1", "app5" ); ;
+ fail( "should never get here because of an exception" ) ;
+ }
+ catch ( RmsException e )
+ {
+ }
+ }
+
+
+ public void testCreateAndList() throws Exception
+ {
+ try
+ {
+ factory.getApplication( "app1" ) ;
+ fail( "should never get here because of an exception" ) ;
+ }
+ catch ( RmsException e )
+ {
+ e.printStackTrace();
+ }
+
+ factory.createApplication( "app1" ) ;
+ factory.createApplication( "app2" ) ;
+ factory.createApplication( "app3" ) ;
+ factory.createApplication( "app4" ) ;
+
+ assertNotNull( factory.getApplication( "app1" ) ) ;
+ assertNotNull( factory.getApplication( "app2" ) ) ;
+ assertNotNull( factory.getApplication( "app3" ) ) ;
+ assertNotNull( factory.getApplication( "app4" ) ) ;
+
+ try
+ {
+ factory.getApplication( "app5" ) ;
+ fail( "should never get here because of an exception" ) ;
+ }
+ catch ( RmsException e )
+ {
+ }
+
+ Iterator list = null ;
+ String appName = null ;
+
+ list = factory.getApplicationNames() ;
+
+ appName = ( String ) list.next() ;
+ assertNotNull( appName ) ;
+ assertEquals( "app1", appName ) ;
+
+ appName = ( String ) list.next() ;
+ assertNotNull( appName ) ;
+ assertEquals( "app2", appName ) ;
+
+ appName = ( String ) list.next() ;
+ assertNotNull( appName ) ;
+ assertEquals( "app3", appName ) ;
+
+ appName = ( String ) list.next() ;
+ assertNotNull( appName ) ;
+ assertEquals( "app4", appName ) ;
+
+ assertFalse( list.hasNext() ) ;
+ }
+}
\ No newline at end of file
|