harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r505260 - in /harmony/enhanced/classlib/trunk/modules/security/src/test: api/java/org/apache/harmony/security/tests/java/security/SecurityTest.java impl/java.injected/java/security/Security_ImplTest.java
Date Fri, 09 Feb 2007 11:50:12 GMT
Author: smishura
Date: Fri Feb  9 03:50:11 2007
New Revision: 505260

URL: http://svn.apache.org/viewvc?view=rev&rev=505260
Log:
Move to 'api' and refactor tests for Security.getProviders()

Two test cases were not moved. They are subject for discussion: to resolve as non-bug difference
or fix Harmony implementation

Modified:
    harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecurityTest.java
    harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java.injected/java/security/Security_ImplTest.java

Modified: harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecurityTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecurityTest.java?view=diff&rev=505260&r1=505259&r2=505260
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecurityTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecurityTest.java
Fri Feb  9 03:50:11 2007
@@ -22,12 +22,21 @@
 
 package org.apache.harmony.security.tests.java.security;
 
-import java.security.*;
-
-import org.apache.harmony.security.tests.support.TestKeyPair;
+import java.security.InvalidParameterException;
+import java.security.KeyFactory;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.Provider;
+import java.security.Security;
+import java.security.Signature;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
 
 import junit.framework.TestCase;
 
+import org.apache.harmony.security.tests.support.TestKeyPair;
+
 /**
  * Tests for <code>Security</code> constructor and methods
  */
@@ -176,6 +185,91 @@
             Security.addProvider(p);
 
             assertSame(p, Security.getProvider(p.getName()));
+        } finally { //clean up
+            Security.removeProvider(p.getName());
+        }
+    }
+
+    /**
+     * @tests java.security.Security#getProviders(String)
+     */
+    public void test_getProvidersLjava_lang_String() {
+
+        try {
+            Security.getProviders("");
+            fail("No expected InvalidParameterException");
+        } catch (InvalidParameterException e) {
+        }
+
+        try {
+            Security.getProviders((String) null);
+            fail("No expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+
+        Provider p = new MyProvider();
+        try {
+            Security.addProvider(p);
+
+            String filter = "MyService.MyAlgorithm";
+            assertTrue(filter, Arrays.equals(new Provider[] { p }, Security
+                    .getProviders(filter)));
+
+            filter = "MyService.MyAlgorithm KeySize:512";
+            assertTrue(filter, Arrays.equals(new Provider[] { p }, Security
+                    .getProviders(filter)));
+
+            filter = "MyService.MyAlgorithm KeySize:1025";
+            assertNull(filter, Security.getProviders(filter));
+        } finally { //clean up
+            Security.removeProvider(p.getName());
+        }
+    }
+
+    /**
+     * @tests java.security.Security#getProviders(java.util.Map)
+     */
+    public void test_getProvidersLjava_util_Map() {
+
+        Map<String, String> m = new HashMap<String, String>();
+        Security.getProviders(m);
+
+        assertNull("Not null result on empty map", Security.getProviders(m));
+
+        try {
+            Security.getProviders((Map<String, String>) null);
+            fail("No expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+
+        m.put("AAA.BBB.CCC", "aaaa"); // key has dot instead of space
+        try {
+            Security.getProviders(m);
+            fail("No expected InvalidParameterException");
+        } catch (InvalidParameterException e) {
+        }
+
+        Provider p = new MyProvider();
+        try {
+            Security.addProvider(p);
+
+            m.clear();
+            m.put("MyService.MyAlgorithm", "");
+            m.put("MessageDigest.SHA-1", "");
+            assertTrue("MyService.MyAlgorithm", Arrays.equals(
+                    new Provider[] { p }, Security.getProviders(m)));
+
+            m.clear();
+            m.put("MyService.MyAlgorithm KeySize", "512");
+            m.put("MessageDigest.SHA-1", "");
+            assertTrue("MyService.MyAlgorithm KeySize:512", Arrays.equals(
+                    new Provider[] { p }, Security.getProviders(m)));
+
+            m.clear();
+            m.put("MyService.MyAlgorithm KeySize", "1025");
+            m.put("MessageDigest.SHA-1", "");
+            assertNull("MyService.MyAlgorithm KeySize:1025", Security
+                    .getProviders(m));
         } finally { //clean up
             Security.removeProvider(p.getName());
         }

Modified: harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java.injected/java/security/Security_ImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java.injected/java/security/Security_ImplTest.java?view=diff&rev=505260&r1=505259&r2=505260
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java.injected/java/security/Security_ImplTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java.injected/java/security/Security_ImplTest.java
Fri Feb  9 03:50:11 2007
@@ -71,121 +71,24 @@
      * Class under test for Provider[] getProviders(String)
      */
     public final void testGetProvidersString() {
-        Provider[] providers;
-        try {
-            Security.getProviders("");
-            fail("No expected InvalidParameterException");
-        } catch (InvalidParameterException e) {
-        }
-
-        try {
-            Security.getProviders((String) null);
-            fail("No expected NullPointerException");
-        } catch (NullPointerException e) {
-        }
-
         try {
             Security.getProviders("AAA.BBB CCC");
             fail("AAA.BBB CCC: No expected InvalidParameterException");
         } catch (InvalidParameterException e) {
         }
-
-        Provider p = new MyProvider();
-
-        try {
-            Security.addProvider(p);
-            providers = Security.getProviders("MyService.MyAlgorithm");
-            assertTrue("failed for MyService.MyAlgorithm", providers != null);
-            assertEquals("failed for MyService.MyAlgorithm", 1,
-                    providers.length);
-            assertEquals("failed for MyService.MyAlgorithm", p, providers[0]);
-            if (providers == null || providers.length != 1 || providers[0] != p) {
-                fail("fail for MyService.MyAlgorithm");
-            }
-
-            providers = Security
-                    .getProviders("MyService.MyAlgorithm KeySize:512");
-            assertTrue("failed for MyService.MyAlgorithm KeySize:512",
-                    providers != null);
-            assertEquals("failed for MyService.MyAlgorithm KeySize:512", 1,
-                    providers.length);
-            assertEquals("failed for MyService.MyAlgorithm KeySize:512", p,
-                    providers[0]);
-
-            providers = Security
-                    .getProviders("MyService.MyAlgorithm KeySize:1025");
-            assertNull("failed for MyService.MyAlgorithm KeySize:1025",
-                    providers);
-
-        } finally { //clean up
-            Security.removeProvider(p.getName());
-        }
     }
 
     /*
      * Class under test for Provider[] getProviders(Map)
      */
     public final void testGetProvidersMap() {
-        Provider[] providers;
         Map m = new Properties();
-        Security.getProviders(m);
-        assertNull("Not null result on empty map", Security.getProviders(m));
-
-        try {
-            Security.getProviders((Map)null);
-            fail("No expected NullPointerException");
-        } catch (NullPointerException e) {    
-        }
-
-        m.clear();
         m.put("AAA.BBB CCC", "");
         m.put("AAA.BBB", "");
         try {
             Security.getProviders(m);
             fail("attribute value is empty string: No expected InvalidParameterException");
         } catch (InvalidParameterException  e) {    
-        }
-
-        m.clear();
-        m.put("AAA.BBB.CCC", "aaaa");
-        m.put("AAA.BBB", "");
-        try {
-            Security.getProviders(m);
-            fail("value associated with the key is not an empty string: No expected InvalidParameterException");
-        } catch (InvalidParameterException  e) {    
-        }
-
-        Provider p = new MyProvider();
-        try {
-            Security.addProvider(p);
-            m.clear();
-            m.put("MyService.MyAlgorithm", "");
-            m.put("MessageDigest.SHA-1", "");
-            providers = Security.getProviders(m);
-            assertNotNull("failed for MyService.MyAlgorithm", providers);
-            assertEquals("failed for MyService.MyAlgorithm", 1,
-                    providers.length);
-            assertEquals("failed for MyService.MyAlgorithm", p, providers[0]);
-            
-            m.clear();
-            m.put("MyService.MyAlgorithm KeySize", "512");
-            m.put("MessageDigest.SHA-1", "");
-            providers = Security.getProviders(m);
-            assertNotNull("failed for MyService.MyAlgorithm KeySize:512",
-                    providers);
-            assertEquals("failed for MyService.MyAlgorithm KeySize:512", 1,
-                    providers.length);
-            assertEquals("failed for MyService.MyAlgorithm KeySize:512", p,
-                    providers[0]);
-            
-            m.clear();
-            m.put("MyService.MyAlgorithm KeySize", "1025");
-            m.put("MessageDigest.SHA-1", "");
-            providers = Security.getProviders(m);
-            assertNull("failed for MyService.MyAlgorithm KeySize:1025",
-                    providers);
-        } finally { //clean up
-            Security.removeProvider(p.getName());
         }
     }
 



Mime
View raw message