01: package org.bouncycastle.asn1.test;
02:
03: import java.io.IOException;
04:
05: import org.bouncycastle.asn1.ASN1Encodable;
06: import org.bouncycastle.asn1.ASN1InputStream;
07: import org.bouncycastle.asn1.ASN1Sequence;
08: import org.bouncycastle.asn1.DERObjectIdentifier;
09: import org.bouncycastle.asn1.DERSequence;
10: import org.bouncycastle.asn1.esf.CommitmentTypeIdentifier;
11: import org.bouncycastle.asn1.esf.CommitmentTypeIndication;
12: import org.bouncycastle.util.test.SimpleTest;
13:
14: public class CommitmentTypeIndicationUnitTest extends SimpleTest {
15: public String getName() {
16: return "CommitmentTypeIndication";
17: }
18:
19: public void performTest() throws Exception {
20: CommitmentTypeIndication cti = new CommitmentTypeIndication(
21: CommitmentTypeIdentifier.proofOfOrigin);
22:
23: checkConstruction(cti, CommitmentTypeIdentifier.proofOfOrigin,
24: null);
25:
26: ASN1Sequence qualifier = new DERSequence(
27: new DERObjectIdentifier("1.2"));
28:
29: cti = new CommitmentTypeIndication(
30: CommitmentTypeIdentifier.proofOfOrigin, qualifier);
31:
32: checkConstruction(cti, CommitmentTypeIdentifier.proofOfOrigin,
33: qualifier);
34:
35: cti = CommitmentTypeIndication.getInstance(null);
36:
37: if (cti != null) {
38: fail("null getInstance() failed.");
39: }
40:
41: try {
42: CommitmentTypeIndication.getInstance(new Object());
43:
44: fail("getInstance() failed to detect bad object.");
45: } catch (IllegalArgumentException e) {
46: // expected
47: }
48: }
49:
50: private void checkConstruction(CommitmentTypeIndication mv,
51: DERObjectIdentifier commitmenttTypeId,
52: ASN1Encodable qualifier) throws IOException {
53: checkStatement(mv, commitmenttTypeId, qualifier);
54:
55: mv = CommitmentTypeIndication.getInstance(mv);
56:
57: checkStatement(mv, commitmenttTypeId, qualifier);
58:
59: ASN1InputStream aIn = new ASN1InputStream(mv.toASN1Object()
60: .getEncoded());
61:
62: ASN1Sequence seq = (ASN1Sequence) aIn.readObject();
63:
64: mv = CommitmentTypeIndication.getInstance(seq);
65:
66: checkStatement(mv, commitmenttTypeId, qualifier);
67: }
68:
69: private void checkStatement(CommitmentTypeIndication cti,
70: DERObjectIdentifier commitmentTypeId,
71: ASN1Encodable qualifier) {
72: if (!cti.getCommitmentTypeId().equals(commitmentTypeId)) {
73: fail("commitmentTypeIds don't match.");
74: }
75:
76: if (qualifier != null) {
77: if (!cti.getCommitmentTypeQualifier().equals(qualifier)) {
78: fail("qualifiers don't match.");
79: }
80: } else if (cti.getCommitmentTypeQualifier() != null) {
81: fail("qualifier found when none expected.");
82: }
83: }
84:
85: public static void main(String[] args) {
86: runTest(new CommitmentTypeIndicationUnitTest());
87: }
88: }
|