01: package org.bouncycastle.asn1.test;
02:
03: import org.bouncycastle.asn1.ASN1InputStream;
04: import org.bouncycastle.asn1.ASN1Sequence;
05: import org.bouncycastle.asn1.DERObjectIdentifier;
06: import org.bouncycastle.asn1.isismtt.x509.Admissions;
07: import org.bouncycastle.asn1.isismtt.x509.NamingAuthority;
08: import org.bouncycastle.asn1.isismtt.x509.ProfessionInfo;
09: import org.bouncycastle.asn1.x500.DirectoryString;
10: import org.bouncycastle.asn1.x509.GeneralName;
11: import org.bouncycastle.asn1.x509.X509Name;
12:
13: import java.io.IOException;
14:
15: public class AdmissionsUnitTest extends ASN1UnitTest {
16: public String getName() {
17: return "Admissions";
18: }
19:
20: public void performTest() throws Exception {
21: GeneralName name = new GeneralName(new X509Name(
22: "CN=hello world"));
23: NamingAuthority auth = new NamingAuthority(
24: new DERObjectIdentifier("1.2.3"), "url",
25: new DirectoryString("fred"));
26: Admissions admissions = new Admissions(name, auth,
27: new ProfessionInfo[0]);
28:
29: checkConstruction(admissions, name, auth);
30:
31: admissions = Admissions.getInstance(null);
32:
33: if (admissions != null) {
34: fail("null getInstance() failed.");
35: }
36:
37: try {
38: Admissions.getInstance(new Object());
39:
40: fail("getInstance() failed to detect bad object.");
41: } catch (IllegalArgumentException e) {
42: // expected
43: }
44: }
45:
46: private void checkConstruction(Admissions admissions,
47: GeneralName name, NamingAuthority auth) throws IOException {
48: checkValues(admissions, name, auth);
49:
50: admissions = Admissions.getInstance(admissions);
51:
52: checkValues(admissions, name, auth);
53:
54: ASN1InputStream aIn = new ASN1InputStream(admissions
55: .toASN1Object().getEncoded());
56:
57: ASN1Sequence info = (ASN1Sequence) aIn.readObject();
58:
59: admissions = Admissions.getInstance(info);
60:
61: checkValues(admissions, name, auth);
62: }
63:
64: private void checkValues(Admissions admissions, GeneralName name,
65: NamingAuthority auth) {
66: checkMandatoryField("admissionAuthority", name, admissions
67: .getAdmissionAuthority());
68: checkMandatoryField("namingAuthority", auth, admissions
69: .getNamingAuthority());
70: }
71:
72: public static void main(String[] args) {
73: runTest(new AdmissionsUnitTest());
74: }
75: }
|