1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package org.apache.harmony.security.tests.java.security; 19 20import dalvik.annotation.TestTargetClass; 21import dalvik.annotation.TestTargets; 22import dalvik.annotation.TestLevel; 23import dalvik.annotation.TestTargetNew; 24 25import java.security.KeyFactorySpi; 26import java.security.PrivateKey; 27import java.security.spec.KeySpec; 28import java.security.PublicKey; 29import java.security.Key; 30 31import junit.framework.TestCase; 32 33/** 34 * Tests for <code>KeyFactorySpi</code> class constructors 35 * and methods. 36 * 37 */ 38@TestTargetClass(KeyFactorySpi.class) 39public class KeyFactorySpiTest extends TestCase { 40 41 /** 42 * Test for <code>KeyFactorySpi</code> constructor 43 * Assertion: constructs KeyFactorySpi 44 */ 45 @TestTargets({ 46 @TestTargetNew( 47 level = TestLevel.COMPLETE, 48 notes = "", 49 method = "KeyFactorySpi", 50 args = {} 51 ), 52 @TestTargetNew( 53 level = TestLevel.COMPLETE, 54 notes = "", 55 method = "engineGeneratePrivate", 56 args = {java.security.spec.KeySpec.class} 57 ), 58 @TestTargetNew( 59 level = TestLevel.COMPLETE, 60 notes = "", 61 method = "engineGeneratePublic", 62 args = {java.security.spec.KeySpec.class} 63 ), 64 @TestTargetNew( 65 level = TestLevel.COMPLETE, 66 notes = "", 67 method = "engineTranslateKey", 68 args = {java.security.Key.class} 69 ), 70 @TestTargetNew( 71 level = TestLevel.COMPLETE, 72 notes = "", 73 method = "engineGetKeySpec", 74 args = {java.security.Key.class, java.lang.Class.class} 75 ) 76 }) 77 public void testKeyFactorySpi() { 78 MyKeyFactorySpi keyFSpi = new MyKeyFactorySpi(); 79 assertTrue(keyFSpi instanceof KeyFactorySpi); 80 81 KeySpec ks = new MyKeySpec(); 82 KeySpec kss = new MyKeySpec(); 83 try { 84 keyFSpi.engineGeneratePrivate(ks); 85 keyFSpi.engineGeneratePublic(ks); 86 keyFSpi.engineGetKeySpec(null, java.lang.Class.class); 87 keyFSpi.engineTranslateKey(null); 88 } catch (Exception e) { 89 fail("Unexpected exception"); 90 } 91 } 92 93 public class MyKeyFactorySpi extends KeyFactorySpi { 94 protected PrivateKey engineGeneratePrivate(KeySpec keySpec){ 95 return null; 96 } 97 protected PublicKey engineGeneratePublic(KeySpec keySpec){ 98 return null; 99 } 100 protected KeySpec engineGetKeySpec(Key key, Class keySpec){ 101 return null; 102 } 103 protected Key engineTranslateKey(Key key){ 104 return null; 105 } 106 } 107 108 class MyKeySpec implements KeySpec {} 109} 110