diff options
author | Yuuta Liang <yuutaw@student.cs.ubc.ca> | 2023-10-25 03:30:45 +0800 |
---|---|---|
committer | Yuuta Liang <yuutaw@student.cs.ubc.ca> | 2023-10-25 03:30:45 +0800 |
commit | d7ff9d5e217873609d79efe279f2634e3a3dd8b4 (patch) | |
tree | 704729e5eed658728b521acd407c6ca767f7e865 /src/test/model/ca/TemplateTest.java | |
parent | 55df54e5dbf26e6824123410784d00aa793c3781 (diff) | |
download | jca-d7ff9d5e217873609d79efe279f2634e3a3dd8b4.tar jca-d7ff9d5e217873609d79efe279f2634e3a3dd8b4.tar.gz jca-d7ff9d5e217873609d79efe279f2634e3a3dd8b4.tar.bz2 jca-d7ff9d5e217873609d79efe279f2634e3a3dd8b4.zip |
Refactor: move all logics into CertificationAuthority
Signed-off-by: Yuuta Liang <yuutaw@student.cs.ubc.ca>
Diffstat (limited to 'src/test/model/ca/TemplateTest.java')
-rw-r--r-- | src/test/model/ca/TemplateTest.java | 55 |
1 files changed, 21 insertions, 34 deletions
diff --git a/src/test/model/ca/TemplateTest.java b/src/test/model/ca/TemplateTest.java index 4014599..1926078 100644 --- a/src/test/model/ca/TemplateTest.java +++ b/src/test/model/ca/TemplateTest.java @@ -13,48 +13,35 @@ import static org.junit.jupiter.api.Assertions.*; public class TemplateTest { @Test - void testConstructor() { - Template template = new Template("123", true, null, 123); + void testConstructor() throws ParseException { + Template template = new Template("123", true, (Name) null, 123); assertEquals("123", template.getName()); assertTrue(template.isEnabled()); assertNull(template.getSubject()); assertEquals(123, template.getValidity()); - } - @Test - void testSetSubject() throws ParseException { - Template template = new Template("123", true, null, 123); - template.setSubject("123"); - assertEquals("CN=123,C=CA", template.getSubject().toString()); - template.setSubject((String) null); - assertNull(template.getSubject()); - assertThrows(ParseException.class, () -> template.setSubject("*")); + template = new Template("123", true, + new Name(ASN1Object.TAG_SEQUENCE, null, new RelativeDistinguishedName[]{ + new RelativeDistinguishedName(ASN1Object.TAG_SET, null, new AttributeTypeAndValue[]{ + new AttributeTypeAndValue(ASN1Object.TAG_SEQUENCE, null, + new ObjectIdentifier(ObjectIdentifier.TAG, null, + ObjectIdentifier.OID_CN), + new PrintableString(PrintableString.TAG, null, "Test"))}), + new RelativeDistinguishedName(ASN1Object.TAG_SET, null, new AttributeTypeAndValue[]{ + new AttributeTypeAndValue(ASN1Object.TAG_SEQUENCE, null, + new ObjectIdentifier(ObjectIdentifier.TAG, null, + ObjectIdentifier.OID_C), + new PrintableString(PrintableString.TAG, null, "CA"))})}), + 123); + assertEquals("CN=Test,C=CA", template.getSubject().toString()); } @Test - void testSetters() throws ParseException { - Template template = new Template("123", true, null, 123); - - template.setName("114514"); - assertEquals("114514", template.getName()); - - template.setSubject(new Name(ASN1Object.TAG_SEQUENCE, null, new RelativeDistinguishedName[]{ - new RelativeDistinguishedName(ASN1Object.TAG_SET, null, new AttributeTypeAndValue[]{ - new AttributeTypeAndValue(ASN1Object.TAG_SEQUENCE, null, - new ObjectIdentifier(ObjectIdentifier.TAG, null, - ObjectIdentifier.OID_CN), - new PrintableString(PrintableString.TAG, null, "Test"))}), - new RelativeDistinguishedName(ASN1Object.TAG_SET, null, new AttributeTypeAndValue[]{ - new AttributeTypeAndValue(ASN1Object.TAG_SEQUENCE, null, - new ObjectIdentifier(ObjectIdentifier.TAG, null, - ObjectIdentifier.OID_C), - new PrintableString(PrintableString.TAG, null, "CA"))})})); - assertEquals("CN=Test,C=CA", template.getSubject().toString()); - - template.setEnabled(false); - assertFalse(template.isEnabled()); + void testSetSubject() throws ParseException { + Template template = new Template("123", true, "ABC", 123); + assertEquals("CN=ABC,C=CA", template.getSubject().toString()); - template.setValidity(233); - assertEquals(233, template.getValidity()); + assertThrows(ParseException.class, () -> new Template("123", true, "*", + 123)); } } |