01: package org.bouncycastle.asn1.test;
02:
03: import org.bouncycastle.asn1.ASN1InputStream;
04: import org.bouncycastle.asn1.DERString;
05: import org.bouncycastle.asn1.isismtt.x509.Restriction;
06: import org.bouncycastle.asn1.x500.DirectoryString;
07:
08: import java.io.IOException;
09:
10: public class RestrictionUnitTest extends ASN1UnitTest {
11: public String getName() {
12: return "Restriction";
13: }
14:
15: public void performTest() throws Exception {
16: DirectoryString res = new DirectoryString("test");
17: Restriction restriction = new Restriction(res.getString());
18:
19: checkConstruction(restriction, res);
20:
21: restriction = Restriction.getInstance(null);
22:
23: if (restriction != null) {
24: fail("null getInstance() failed.");
25: }
26:
27: try {
28: Restriction.getInstance(new Object());
29:
30: fail("getInstance() failed to detect bad object.");
31: } catch (IllegalArgumentException e) {
32: // expected
33: }
34: }
35:
36: private void checkConstruction(Restriction restriction,
37: DirectoryString res) throws IOException {
38: checkValues(restriction, res);
39:
40: restriction = Restriction.getInstance(restriction);
41:
42: checkValues(restriction, res);
43:
44: ASN1InputStream aIn = new ASN1InputStream(restriction
45: .toASN1Object().getEncoded());
46:
47: DERString str = (DERString) aIn.readObject();
48:
49: restriction = Restriction.getInstance(str);
50:
51: checkValues(restriction, res);
52: }
53:
54: private void checkValues(Restriction restriction,
55: DirectoryString res) {
56: checkMandatoryField("restriction", res, restriction
57: .getRestriction());
58: }
59:
60: public static void main(String[] args) {
61: runTest(new RestrictionUnitTest());
62: }
63: }
|