commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rsi...@apache.org
Subject cvs commit: jakarta-commons/discovery/src/test/org/apache/commons/discovery TestAll.java
Date Mon, 05 Aug 2002 22:48:30 GMT
rsitze      2002/08/05 15:48:30

  Modified:    discovery/src/test/org/apache/commons/discovery TestAll.java
  Log:
  Fixed test cases to be more 'exact'.
  
  Revision  Changes    Path
  1.5       +127 -18   jakarta-commons/discovery/src/test/org/apache/commons/discovery/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/discovery/src/test/org/apache/commons/discovery/TestAll.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestAll.java	1 Aug 2002 22:19:00 -0000	1.4
  +++ TestAll.java	5 Aug 2002 22:48:30 -0000	1.5
  @@ -80,6 +80,9 @@
     * @version $Revision$
    */
   public class TestAll extends TestCase {
  +    
  +    public static class MyFactory extends LogFactoryImpl {
  +    }
   
       public TestAll(String testName) {
           super(testName);
  @@ -88,36 +91,142 @@
       public static Test suite() {
           return new TestSuite(TestAll.class);
       }
  +
  +    public void testFindLogFactoryImplDefault() {
  +        LogFactory factory = null;
  +        
  +        try {
  +            factory = (LogFactory)Discovery.find(LogFactory.class,
  +                                                 LogFactoryImpl.class.getName());
  +
  +            assertTrue(factory.getClass().getName() + "!=" + LogFactoryImpl.class.getName(),
  +                       factory.getClass().getName().equals(LogFactoryImpl.class.getName()));
  +        } finally {
  +            if (factory != null)
  +                factory.releaseAll();
  +
  +            Discovery.release();
  +        }
  +    }
       
  -    public void testServiceFinder1() {
  +    public void testMyFactoryDefault() {
  +        LogFactory factory = null;
  +
           try {
  -            LogFactory factory =
  -                (LogFactory)Discovery.find(LogFactory.class,
  -                                               LogFactoryImpl.class.getName());
  -            Log log = factory.getLog(TestAll.class);
  -            log.info("got log!");
  +            factory = (LogFactory)Discovery.find(LogFactory.class,
  +                                                 MyFactory.class.getName());
  +
  +            assertTrue(factory.getClass().getName() + "!=" + MyFactory.class.getName(),
  +                       factory.getClass().getName().equals(MyFactory.class.getName()));
           } finally {
  -            LogFactory.releaseAll();
  +            if (factory != null)
  +                factory.releaseAll();
  +
               Discovery.release();
           }
       }
       
  -    public void testServiceFinder2() {
  -        Properties props = new Properties();
  +    public void testCache() {
  +        LogFactory factory = null;
           
  -        props.setProperty(LogFactory.class.getName(),
  -                          LogFactoryImpl.class.getName());
  -                          
  -        props.setProperty(Log.class.getName(), SimpleLog.class.getName());
  +        try {
  +            factory = (LogFactory)Discovery.find(LogFactory.class,
  +                                                 LogFactoryImpl.class.getName());
  +
  +            assertTrue("1. " + factory.getClass().getName() + "!=" + LogFactoryImpl.class.getName(),
  +                       factory.getClass().getName().equals(LogFactoryImpl.class.getName()));
  +            
  +            // no release, should get cached value..
  +            
  +            factory = (LogFactory)Discovery.find(LogFactory.class,
  +                                                 MyFactory.class.getName());
  +
  +            // factory should be cached LogFactoryImpl
  +            assertTrue("2. " + factory.getClass().getName() + "!=" + LogFactoryImpl.class.getName(),
  +                       factory.getClass().getName().equals(LogFactoryImpl.class.getName()));
  +        } finally {
  +            if (factory != null)
  +                factory.releaseAll();
  +
  +            Discovery.release();
  +        }
  +    }
  +    
  +    public void testRelease() {
  +        LogFactory factory = null;
           
           try {
  -            LogFactory factory =
  -                (LogFactory)Discovery.find(LogFactory.class, props);
  -            Log log = factory.getLog(TestAll.class);
  -            log.info("got log factory via service");
  +            factory = (LogFactory)Discovery.find(LogFactory.class,
  +                                                 LogFactoryImpl.class.getName());
  +
  +            assertTrue("1. " + factory.getClass().getName() + "!=" + LogFactoryImpl.class.getName(),
  +                       factory.getClass().getName().equals(LogFactoryImpl.class.getName()));
  +            
  +            Discovery.release();
  +            
  +            factory = (LogFactory)Discovery.find(LogFactory.class,
  +                                                 MyFactory.class.getName());
  +
  +            // Cache flushed, get new factory:
  +            assertTrue("2. " + factory.getClass().getName() + "!=" + MyFactory.class.getName(),
  +                       factory.getClass().getName().equals(MyFactory.class.getName()));
  +        } finally {
  +            if (factory != null)
  +                factory.releaseAll();
  +
  +            Discovery.release();
  +        }
  +    }
  +    
  +    public void testMyFactoryProperty() {
  +        LogFactory factory = null;
  +
  +        try {
  +            Properties props = new Properties();
  +            
  +            props.setProperty(LogFactory.class.getName(),
  +                              MyFactory.class.getName());
  +                              
  +            props.setProperty(Log.class.getName(),
  +                              SimpleLog.class.getName());
  +            
  +            factory = (LogFactory)Discovery.find(LogFactory.class, props);
  +
  +            assertTrue(factory.getClass().getName() + "!=" + MyFactory.class.getName(),
  +                       factory.getClass().getName().equals(MyFactory.class.getName()));
           } finally {
  -            LogFactory.releaseAll();
  +            if (factory != null)
  +                factory.releaseAll();
  +
  +            Discovery.release();
  +        }
  +    }
  +    
  +    public void testMyFactoryManagedProperty() {
  +        LogFactory factory = null;
  +
  +        try {
  +            ManagedProperties.setProperty(LogFactory.class.getName(),
  +                                          MyFactory.class.getName());
  +                              
  +            ManagedProperties.setProperty(Log.class.getName(),
  +                                          SimpleLog.class.getName());
  +            
  +            factory = (LogFactory)Discovery.find(LogFactory.class);
  +
  +            assertTrue(factory.getClass().getName() + "!=" + MyFactory.class.getName(),
  +                       factory.getClass().getName().equals(MyFactory.class.getName()));
  +        } finally {
  +            if (factory != null)
  +                factory.releaseAll();
  +
               Discovery.release();
  +            
  +            /**
  +             * Cleanup, don't want to affect next test..
  +             */
  +            ManagedProperties.setProperty(LogFactory.class.getName(), null);
  +            ManagedProperties.setProperty(Log.class.getName(), null);
           }
       }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message