harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r410243 [6/7] - in /incubator/harmony/enhanced/classlib/trunk/modules/crypto: make/common/ src/main/java/javax/crypto/ src/main/java/javax/crypto/spec/ src/main/java/org/apache/harmony/crypto/internal/ src/test/api/java.injected/javax/crypt...
Date Tue, 30 May 2006 11:35:46 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactory_Impl1Test.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactory_Impl1Test.java?rev=410243&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactory_Impl1Test.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactory_Impl1Test.java
Tue May 30 04:35:44 2006
@@ -0,0 +1,120 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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 permissions and
+ *  limitations under the License.
+ */
+
+/**
+* @author Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package org.apache.harmony.crypto.tests.javax.crypto;
+
+import java.security.InvalidKeyException;
+import java.security.Provider;
+
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.SecretKeySpec;
+
+import org.apache.harmony.security.SpiEngUtils;
+import junit.framework.TestCase;
+/**
+ * Tests for <code>SecretKeyFactory</code> class constructors and methods.
+ * 
+ */
+
+public class SecretKeyFactory_Impl1Test extends TestCase {
+    
+    public static final String srvSecretKeyFactory = "SecretKeyFactory";
+        
+    private static String defaultAlgorithm1 = "DESede";
+    private static String defaultAlgorithm2 = "DES";
+    
+    public static String defaultAlgorithm = null;
+
+    private static String defaultProviderName = null;
+
+    private static Provider defaultProvider = null;
+    
+    private static boolean DEFSupported = false;
+
+    private static final String NotSupportMsg = "Default algorithm is not supported";
+
+    static {
+        defaultProvider = SpiEngUtils.isSupport(defaultAlgorithm1,
+                srvSecretKeyFactory);
+        DEFSupported = (defaultProvider != null);
+        if (DEFSupported) {
+            defaultAlgorithm = defaultAlgorithm1;
+            defaultProviderName = defaultProvider.getName();
+        } else {
+            defaultProvider = SpiEngUtils.isSupport(defaultAlgorithm2,
+                    srvSecretKeyFactory);
+            DEFSupported = (defaultProvider != null);
+            if (DEFSupported) {
+                defaultAlgorithm = defaultAlgorithm2;
+                defaultProviderName = defaultProvider.getName();
+            } else {
+                defaultAlgorithm = null;
+                defaultProviderName = null;
+                defaultProvider = null;
+            }
+        }
+    }
+
+    protected SecretKeyFactory[] createSKFac() {
+        if (!DEFSupported) {
+            fail(defaultAlgorithm + " algorithm is not supported");
+            return null;
+        }
+        SecretKeyFactory[] skF = new SecretKeyFactory[3];
+        try {
+            skF[0] = SecretKeyFactory.getInstance(defaultAlgorithm);
+            skF[1] = SecretKeyFactory.getInstance(defaultAlgorithm,
+                    defaultProvider);
+            skF[2] = SecretKeyFactory.getInstance(defaultAlgorithm,
+                    defaultProviderName);
+            return skF;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    /**
+     * Test for <code>translateKey(SecretKey key)</code> method
+     * Assertion: 
+     * throw InvalidKeyException if parameter is inappropriate
+     */    
+    public void testSecretKeyFactory11() throws InvalidKeyException {
+        if (!DEFSupported) {
+            fail(NotSupportMsg);
+            return;
+        }
+        byte[] bb = new byte[10];
+        SecretKeySpec secKeySpec = new SecretKeySpec(bb,defaultAlgorithm);
+        SecretKeyFactory[] skF = createSKFac();
+        assertNotNull("SecretKeyFactory object were not created", skF);
+        for (int i = 0; i < skF.length; i++) {
+            try { 
+                skF[i].translateKey(null);
+                fail("InvalidKeyException must be thrown: " + i);
+            } catch (InvalidKeyException e) {
+            }
+
+            skF[i].translateKey(secKeySpec);
+        }
+    }
+}
+

Copied: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactory_ImplTest.java
(from r410238, incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/SecretKeyFactory_ImplTest.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactory_ImplTest.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactory_ImplTest.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/SecretKeyFactory_ImplTest.java&r1=410238&r2=410243&rev=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/SecretKeyFactory_ImplTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactory_ImplTest.java
Tue May 30 04:35:44 2006
@@ -19,7 +19,7 @@
 * @version $Revision$
 */
 
-package javax.crypto;
+package org.apache.harmony.crypto.tests.javax.crypto;
 
 import java.security.InvalidKeyException;
 import java.security.NoSuchAlgorithmException;
@@ -29,6 +29,9 @@
 import java.security.spec.InvalidKeySpecException;
 import java.security.spec.KeySpec;
 
+import javax.crypto.SecretKey;
+import javax.crypto.SecretKeyFactory;
+
 import org.apache.harmony.security.SpiEngUtils;
 import junit.framework.TestCase;
 
@@ -72,15 +75,6 @@
     protected void tearDown() throws Exception {
         super.tearDown();
         Security.removeProvider(mProv.getName());
-    }
-
-    /**
-     * Constructor for SecurityManagerFactoryTest2.
-     * 
-     * @param arg0
-     */
-    public SecretKeyFactory_ImplTest(String arg0) {
-        super(arg0);
     }
 
     private void checkResult(SecretKeyFactory skf) throws InvalidKeyException,



Mime
View raw message