01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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:
18: /**
19: * @author Vera Y. Petrashkova
20: * @version $Revision$
21: */package javax.crypto;
22:
23: import java.security.InvalidAlgorithmParameterException;
24: import java.security.InvalidKeyException;
25: import java.security.Key;
26: import java.security.NoSuchAlgorithmException;
27: import java.security.SecureRandom;
28: import java.security.spec.AlgorithmParameterSpec;
29:
30: import org.apache.harmony.crypto.tests.support.MyKeyAgreementSpi;
31:
32: import junit.framework.TestCase;
33:
34: /**
35: * Tests for <code>KeyAgreementSpi</code> class constructors and methods.
36: *
37: */
38:
39: public class KeyAgreementSpiTest extends TestCase {
40: /**
41: * Constructor for KeyAgreementSpiTests.
42: *
43: * @param arg0
44: */
45: public KeyAgreementSpiTest(String arg0) {
46: super (arg0);
47: }
48:
49: /**
50: * Test for <code>KeyAgreementSpi</code> constructor Assertion: constructs
51: * KeyAgreementSpi
52: */
53: public void testKeyAgreementSpi01() throws InvalidKeyException,
54: ShortBufferException, NoSuchAlgorithmException,
55: InvalidAlgorithmParameterException {
56: KeyAgreementSpi kaSpi = new MyKeyAgreementSpi();
57:
58: assertNull("Not null result", kaSpi.engineDoPhase(null, true));
59: try {
60: kaSpi.engineDoPhase(null, false);
61: fail("IllegalStateException must be thrown");
62: } catch (IllegalStateException e) {
63: }
64: byte[] bb = kaSpi.engineGenerateSecret();
65: assertEquals("Length is not 0", bb.length, 0);
66: assertEquals("Returned integer is not 0", kaSpi
67: .engineGenerateSecret(new byte[1], 10), -1);
68: assertNull("Not null result", kaSpi.engineGenerateSecret("aaa"));
69: try {
70: kaSpi.engineGenerateSecret("");
71: fail("NoSuchAlgorithmException must be thrown");
72: } catch (NoSuchAlgorithmException e) {
73: }
74: Key key = null;
75: try {
76: kaSpi.engineInit(key, new SecureRandom());
77: fail("IllegalArgumentException must be thrown");
78: } catch (IllegalArgumentException e) {
79: }
80: AlgorithmParameterSpec params = null;
81: try {
82: kaSpi.engineInit(key, params, new SecureRandom());
83: fail("IllegalArgumentException must be thrown");
84: } catch (IllegalArgumentException e) {
85: }
86: }
87: }
|