package model.ca; import model.asn1.ASN1Object; import model.asn1.ObjectIdentifier; import model.asn1.PrintableString; import model.asn1.exceptions.ParseException; import model.x501.AttributeTypeAndValue; import model.x501.Name; import model.x501.RelativeDistinguishedName; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; public class TemplateTest { @Test void testConstructor() { Template template = new Template("123", true, 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("*")); } @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()); template.setValidity(233); assertEquals(233, template.getValidity()); } }