001: package org.bouncycastle.asn1.test;
002:
003: import org.bouncycastle.asn1.ASN1InputStream;
004: import org.bouncycastle.asn1.ASN1Sequence;
005: import org.bouncycastle.asn1.DERObjectIdentifier;
006: import org.bouncycastle.asn1.DEROctetString;
007: import org.bouncycastle.asn1.isismtt.x509.NamingAuthority;
008: import org.bouncycastle.asn1.isismtt.x509.ProcurationSyntax;
009: import org.bouncycastle.asn1.isismtt.x509.ProfessionInfo;
010: import org.bouncycastle.asn1.x500.DirectoryString;
011:
012: import java.io.IOException;
013:
014: public class ProfessionInfoUnitTest extends ASN1UnitTest {
015: public String getName() {
016: return "ProfessionInfo";
017: }
018:
019: public void performTest() throws Exception {
020: NamingAuthority auth = new NamingAuthority(
021: new DERObjectIdentifier("1.2.3"), "url",
022: new DirectoryString("fred"));
023: DirectoryString[] professionItems = { new DirectoryString(
024: "substitution") };
025: DERObjectIdentifier[] professionOids = { new DERObjectIdentifier(
026: "1.2.3") };
027: String registrationNumber = "12345";
028: DEROctetString addProfInfo = new DEROctetString(new byte[20]);
029:
030: ProfessionInfo info = new ProfessionInfo(auth, professionItems,
031: professionOids, registrationNumber, addProfInfo);
032:
033: checkConstruction(info, auth, professionItems, professionOids,
034: registrationNumber, addProfInfo);
035:
036: info = new ProfessionInfo(null, professionItems,
037: professionOids, registrationNumber, addProfInfo);
038:
039: checkConstruction(info, null, professionItems, professionOids,
040: registrationNumber, addProfInfo);
041:
042: info = new ProfessionInfo(auth, professionItems, null,
043: registrationNumber, addProfInfo);
044:
045: checkConstruction(info, auth, professionItems, null,
046: registrationNumber, addProfInfo);
047:
048: info = new ProfessionInfo(auth, professionItems,
049: professionOids, null, addProfInfo);
050:
051: checkConstruction(info, auth, professionItems, professionOids,
052: null, addProfInfo);
053:
054: info = new ProfessionInfo(auth, professionItems,
055: professionOids, registrationNumber, null);
056:
057: checkConstruction(info, auth, professionItems, professionOids,
058: registrationNumber, null);
059:
060: info = ProfessionInfo.getInstance(null);
061:
062: if (info != null) {
063: fail("null getInstance() failed.");
064: }
065:
066: try {
067: ProcurationSyntax.getInstance(new Object());
068:
069: fail("getInstance() failed to detect bad object.");
070: } catch (IllegalArgumentException e) {
071: // expected
072: }
073: }
074:
075: private void checkConstruction(ProfessionInfo profInfo,
076: NamingAuthority auth, DirectoryString[] professionItems,
077: DERObjectIdentifier[] professionOids,
078: String registrationNumber, DEROctetString addProfInfo)
079: throws IOException {
080: checkValues(profInfo, auth, professionItems, professionOids,
081: registrationNumber, addProfInfo);
082:
083: profInfo = ProfessionInfo.getInstance(profInfo);
084:
085: checkValues(profInfo, auth, professionItems, professionOids,
086: registrationNumber, addProfInfo);
087:
088: ASN1InputStream aIn = new ASN1InputStream(profInfo
089: .toASN1Object().getEncoded());
090:
091: ASN1Sequence seq = (ASN1Sequence) aIn.readObject();
092:
093: profInfo = ProfessionInfo.getInstance(seq);
094:
095: checkValues(profInfo, auth, professionItems, professionOids,
096: registrationNumber, addProfInfo);
097: }
098:
099: private void checkValues(ProfessionInfo profInfo,
100: NamingAuthority auth, DirectoryString[] professionItems,
101: DERObjectIdentifier[] professionOids,
102: String registrationNumber, DEROctetString addProfInfo) {
103: checkOptionalField("auth", auth, profInfo.getNamingAuthority());
104: checkMandatoryField("professionItems", professionItems[0],
105: profInfo.getProfessionItems()[0]);
106: if (professionOids != null) {
107: checkOptionalField("professionOids", professionOids[0],
108: profInfo.getProfessionOIDs()[0]);
109: }
110: checkOptionalField("registrationNumber", registrationNumber,
111: profInfo.getRegistrationNumber());
112: checkOptionalField("addProfessionInfo", addProfInfo, profInfo
113: .getAddProfessionInfo());
114: }
115:
116: public static void main(String[] args) {
117: runTest(new ProfessionInfoUnitTest());
118: }
119: }
|