RSAPublicKeySpecTest.java revision 561ee011997c6c2f1befbfaa9d5f0a99771c1d63
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
18/**
19* @author Vladimir N. Molotkov
20*/
21
22package org.apache.harmony.security.tests.java.security.spec;
23
24import java.math.BigInteger;
25import java.security.spec.KeySpec;
26import java.security.spec.RSAPublicKeySpec;
27
28import junit.framework.TestCase;
29
30/**
31 * Tests for <code>RSAPublicKeySpec</code> class fields and methods
32 *
33 */
34public class RSAPublicKeySpecTest extends TestCase {
35
36    /**
37     * Constructor for RSAPublicKeySpecTest.
38     * @param name
39     */
40    public RSAPublicKeySpecTest(String name) {
41        super(name);
42    }
43
44
45    /**
46     * Test #1 for <code>RSAPublicKeySpec</code> constructor
47     * Assertion: Constructs <code>RSAPublicKeySpec</code>
48     * object using valid parameters
49     */
50    public final void testRSAPublicKeySpec01() {
51        KeySpec ks =
52            new RSAPublicKeySpec(BigInteger.valueOf(1234567890L),
53                                 BigInteger.valueOf(3L));
54
55        assertTrue(ks instanceof RSAPublicKeySpec);
56    }
57
58    /**
59     * Test #2 for <code>RSAPublicKeySpec</code> constructor
60     * Assertion: Constructs <code>RSAPublicKeySpec</code>
61     * object using valid parameters
62     */
63    public final void testRSAPublicKeySpec02() {
64        KeySpec ks =
65            new RSAPublicKeySpec(null, null);
66
67        assertTrue(ks instanceof RSAPublicKeySpec);
68    }
69
70    /**
71     * Test for <code>getModulus()</code> method<br>
72     * Assertion: returns modulus
73     */
74    public final void testGetModulus() {
75        RSAPublicKeySpec rpks =
76            new RSAPublicKeySpec(BigInteger.valueOf(1234567890L),
77                                 BigInteger.valueOf(3L));
78        assertTrue(BigInteger.valueOf(1234567890L).equals(rpks.getModulus()));
79    }
80
81    /**
82     * Test for <code>getPublicExponent()</code> method<br>
83     * Assertion: returns public exponent
84     */
85    public final void testGetPublicExponent() {
86        RSAPublicKeySpec rpks =
87            new RSAPublicKeySpec(BigInteger.valueOf(3L),
88                                 BigInteger.valueOf(1234567890L));
89        assertTrue(BigInteger.valueOf(1234567890L).equals(rpks.getPublicExponent()));
90    }
91
92}
93