1package tests.security.cert;
2
3import junit.framework.TestCase;
4
5import org.apache.harmony.security.tests.support.cert.MyCertPath;
6import org.apache.harmony.security.tests.support.cert.MyCertPath.MyCertPathRep;
7
8import java.io.ObjectStreamException;
9import java.security.cert.CertPath;
10
11public class CertPathCertPathRepTest extends TestCase {
12
13    private static final byte[] testEncoding = new byte[] { (byte) 1, (byte) 2,
14            (byte) 3, (byte) 4, (byte) 5 };
15
16    protected void setUp() throws Exception {
17        super.setUp();
18    }
19
20    protected void tearDown() throws Exception {
21        super.tearDown();
22    }
23
24    /**
25     * Test for <code>CertPath.CertPathRep(String type, byte[] data)</code>
26     * method<br>
27     */
28    public final void testCertPathCertPathRep() {
29        MyCertPath cp = new MyCertPath(testEncoding);
30        MyCertPathRep rep = cp.new MyCertPathRep("MyEncoding", testEncoding);
31        assertEquals(testEncoding, rep.getData());
32        assertEquals("MyEncoding", rep.getType());
33
34        try {
35            cp.new MyCertPathRep(null, null);
36        } catch (Exception e) {
37            fail("Unexpected exeption " + e.getMessage());
38        }
39
40    }
41
42    public final void testReadResolve() {
43        MyCertPath cp = new MyCertPath(testEncoding);
44        MyCertPathRep rep = cp.new MyCertPathRep("MyEncoding", testEncoding);
45
46        try {
47            Object obj = rep.readResolve();
48            fail("ObjectStreamException was not thrown.");
49        } catch (ObjectStreamException e) {
50            //expected
51        }
52
53        rep = cp.new MyCertPathRep("MyEncoding", new byte[] {(byte) 1, (byte) 2, (byte) 3 });
54        try {
55            rep.readResolve();
56            fail("ObjectStreamException expected");
57        } catch (ObjectStreamException e) {
58            // expected
59            System.out.println(e);
60        }
61    }
62}
63