harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r454615 - /incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login/ConfigurationTest.java
Date Tue, 10 Oct 2006 04:51:32 GMT
Author: smishura
Date: Mon Oct  9 21:51:31 2006
New Revision: 454615

URL: http://svn.apache.org/viewvc?view=rev&rev=454615
Log:
Refactor testLoadDefaultProvider test case

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login/ConfigurationTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login/ConfigurationTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login/ConfigurationTest.java?view=diff&rev=454615&r1=454614&r2=454615
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login/ConfigurationTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login/ConfigurationTest.java
Mon Oct  9 21:51:31 2006
@@ -43,6 +43,9 @@
     // system property to specify another login configuration file 
     private static final String AUTH_LOGIN_CONFIG = "java.security.auth.login.config";
 
+    // security property to specify default configuration implementation 
+    private static final String LOGIN_CONFIG_PROVIDER = "login.configuration.provider";
+
 	/**
 	 * Easy the SecurityManager class
 	 */
@@ -164,30 +167,44 @@
 	 * Tests loading of a default provider, both valid and invalid class
 	 * references.
 	 */
-	public void testLoadDefaultProvider() {
-		String Configuration_PROVIDER = "login.configuration.provider";
-		String oldProvider = Security.getProperty(Configuration_PROVIDER);
-		try {
-			Security.setProperty(Configuration_PROVIDER, ConfTestProvider.class.getName());
-			Configuration.setConfiguration(null);
-			Configuration p = Configuration.getConfiguration();
-			assertNotNull(p);
-			assertEquals(ConfTestProvider.class.getName(), p.getClass().getName());
+    public void test_loadDefaultProvider() {
 
-			Security.setProperty(Configuration_PROVIDER, "a.b.c.D");
-			Configuration.setConfiguration(null);
+        String oldProvider = Security.getProperty(LOGIN_CONFIG_PROVIDER);
+        try {
+            // test: loading custom test provider
+            Security.setProperty(LOGIN_CONFIG_PROVIDER, ConfTestProvider.class
+                    .getName());
+            Configuration.setConfiguration(null); // reset config
+            assertEquals(ConfTestProvider.class, Configuration
+                    .getConfiguration().getClass());
+
+            // test: loading absent class as test provider
+            Security.setProperty(LOGIN_CONFIG_PROVIDER, "ThereIsNoSuchClass");
+            Configuration.setConfiguration(null); // reset config
             try {
-                p = Configuration.getConfiguration();
+                Configuration.getConfiguration();
                 fail("No SecurityException on failed provider");
-            } catch (Exception ok) {
+            } catch (SecurityException ok) {
                 assertTrue(ok.getCause() instanceof ClassNotFoundException);
             }
 
-		} finally {
-			Security.setProperty(Configuration_PROVIDER,
-					(oldProvider == null) ? "" : oldProvider);
-		}
-	}
+            // test: loading wrong class as test provider
+            // a name of this unit test is used as config provider
+            Security.setProperty(LOGIN_CONFIG_PROVIDER, this.getClass()
+                    .getName());
+            Configuration.setConfiguration(null);// reset config
+            try {
+                Configuration.getConfiguration();
+                fail("No expected ClassCastException");
+            } catch (ClassCastException ok) {
+            }
+
+        } finally {
+            //TODO reset security property if oldProvider==null
+            Security.setProperty(LOGIN_CONFIG_PROVIDER,
+                    (oldProvider == null) ? "" : oldProvider);
+        }
+    }
     
     public static void main(String[] args) {
         junit.textui.TestRunner.run(ConfigurationTest.class);



Mime
View raw message