001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Vera Y. Petrashkova
020: * @version $Revision$
021: */package javax.crypto;
022:
023: import java.security.AlgorithmParameters;
024: import java.security.InvalidAlgorithmParameterException;
025: import java.security.InvalidKeyException;
026: import java.security.Key;
027: import java.security.spec.AlgorithmParameterSpec;
028:
029: import org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi;
030:
031: import junit.framework.TestCase;
032:
033: /**
034: * Tests for <code>ExemptionMechanismSpi</code> class constructors and
035: * methods.
036: *
037: */
038:
039: public class ExemptionMechanismSpiTest extends TestCase {
040: /**
041: * Constructor for ExemptionMechanismSpiTests.
042: *
043: * @param arg0
044: */
045: public ExemptionMechanismSpiTest(String arg0) {
046: super (arg0);
047: }
048:
049: /**
050: * Test for <code>ExemptionMechanismSpi</code> constructor Assertion:
051: * constructs ExemptionMechanismSpi
052: */
053: public void testExemptionMechanismSpi01()
054: throws ExemptionMechanismException, ShortBufferException,
055: InvalidKeyException, InvalidAlgorithmParameterException {
056: ExemptionMechanismSpi emSpi = new MyExemptionMechanismSpi();
057: int len = MyExemptionMechanismSpi.getLength();
058: byte[] bbRes = emSpi.engineGenExemptionBlob();
059: assertEquals("Incorrect length", bbRes.length, len);
060: assertEquals("Incorrect result", emSpi.engineGenExemptionBlob(
061: new byte[1], len), len);
062: assertEquals("Incorrect output size", 10, emSpi
063: .engineGetOutputSize(100));
064: Key key = null;
065: AlgorithmParameters params = null;
066: AlgorithmParameterSpec parSpec = null;
067: try {
068: emSpi.engineInit(key);
069: fail("InvalidKeyException must be thrown");
070: } catch (InvalidKeyException e) {
071: }
072: try {
073: emSpi.engineInit(key, params);
074: fail("InvalidKeyException must be thrown");
075: } catch (InvalidKeyException e) {
076: }
077: try {
078: emSpi.engineInit(key, parSpec);
079: fail("InvalidKeyException must be thrown");
080: } catch (InvalidKeyException e) {
081: }
082: key = ((MyExemptionMechanismSpi) emSpi).new tmp1Key("Proba",
083: new byte[0]);
084: try {
085: emSpi.engineInit(key);
086: fail("ExemptionMechanismException must be thrown");
087: } catch (ExemptionMechanismException e) {
088: }
089: try {
090: emSpi.engineInit(key, params);
091: fail("ExemptionMechanismException must be thrown");
092: } catch (ExemptionMechanismException e) {
093: }
094: try {
095: emSpi.engineInit(key, parSpec);
096: fail("ExemptionMechanismException must be thrown");
097: } catch (ExemptionMechanismException e) {
098: }
099: key = ((MyExemptionMechanismSpi) emSpi).new tmpKey("Proba",
100: new byte[0]);
101: emSpi.engineInit(key);
102: emSpi.engineInit(key, params);
103: emSpi.engineInit(key, parSpec);
104:
105: assertEquals("Incorrect result", 10, emSpi
106: .engineGetOutputSize(100));
107: }
108: }
|