Welcome to mirror list, hosted at ThFree Co, Russian Federation.

NamingAuthorityUnitTest.java « test « asn1 « spongycastle « org « java « test « src « core - gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cf6d5a3752570cb558f840b968fc607d1d77e716 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package org.spongycastle.asn1.test;

import java.io.IOException;

import org.spongycastle.asn1.ASN1InputStream;
import org.spongycastle.asn1.ASN1ObjectIdentifier;
import org.spongycastle.asn1.ASN1Sequence;
import org.spongycastle.asn1.isismtt.x509.NamingAuthority;
import org.spongycastle.asn1.x500.DirectoryString;

public class NamingAuthorityUnitTest
    extends ASN1UnitTest
{
    public String getName()
    {
        return "NamingAuthority";
    }

    public void performTest()
        throws Exception
    {
        ASN1ObjectIdentifier namingAuthorityID = new ASN1ObjectIdentifier("1.2.3");
        String              namingAuthorityURL = "url";
        DirectoryString     namingAuthorityText = new DirectoryString("text");

        NamingAuthority auth =  new NamingAuthority(namingAuthorityID, namingAuthorityURL, namingAuthorityText);

        checkConstruction(auth, namingAuthorityID, namingAuthorityURL, namingAuthorityText);

        auth =  new NamingAuthority(null, namingAuthorityURL, namingAuthorityText);

        checkConstruction(auth, null, namingAuthorityURL, namingAuthorityText);

        auth =  new NamingAuthority(namingAuthorityID, null, namingAuthorityText);

        checkConstruction(auth, namingAuthorityID, null, namingAuthorityText);

        auth =  new NamingAuthority(namingAuthorityID, namingAuthorityURL, null);

        checkConstruction(auth, namingAuthorityID, namingAuthorityURL, null);

        auth = NamingAuthority.getInstance(null);

        if (auth != null)
        {
            fail("null getInstance() failed.");
        }

        try
        {
            NamingAuthority.getInstance(new Object());

            fail("getInstance() failed to detect bad object.");
        }
        catch (IllegalArgumentException e)
        {
            // expected
        }
    }

    private void checkConstruction(
        NamingAuthority auth,
        ASN1ObjectIdentifier namingAuthorityID,
        String              namingAuthorityURL,
        DirectoryString     namingAuthorityText)
        throws IOException
    {
        checkValues(auth, namingAuthorityID, namingAuthorityURL, namingAuthorityText);

        auth = NamingAuthority.getInstance(auth);

        checkValues(auth, namingAuthorityID, namingAuthorityURL, namingAuthorityText);

        ASN1InputStream aIn = new ASN1InputStream(auth.toASN1Object().getEncoded());

        ASN1Sequence seq = (ASN1Sequence)aIn.readObject();

        auth = NamingAuthority.getInstance(seq);

        checkValues(auth, namingAuthorityID, namingAuthorityURL, namingAuthorityText);
    }

    private void checkValues(
        NamingAuthority auth,
        ASN1ObjectIdentifier namingAuthorityId,
        String              namingAuthorityURL,
        DirectoryString     namingAuthorityText)
    {
        checkOptionalField("namingAuthorityId", namingAuthorityId, auth.getNamingAuthorityId());
        checkOptionalField("namingAuthorityURL", namingAuthorityURL, auth.getNamingAuthorityUrl());
        checkOptionalField("namingAuthorityText", namingAuthorityText, auth.getNamingAuthorityText());
    }

    public static void main(
        String[]    args)
    {
        runTest(new NamingAuthorityUnitTest());
    }
}