1313import no .digipost .signature .client .asice .ASiCEAttachable ;
1414import no .digipost .signature .client .core .DocumentType ;
1515import no .digipost .signature .client .security .KeyStoreConfig ;
16+ import no .digipost .signature .jaxb .JaxbMarshaller ;
1617import org .junit .jupiter .api .BeforeEach ;
1718import org .junit .jupiter .api .Test ;
1819
19- import javax .xml .bind .JAXBContext ;
20- import javax .xml .bind .JAXBException ;
21- import javax .xml .bind .Unmarshaller ;
22- import javax .xml .transform .stream .StreamSource ;
23-
24- import java .io .ByteArrayInputStream ;
2520import java .math .BigInteger ;
2621import java .time .Clock ;
2722import java .time .ZoneId ;
2823import java .time .ZonedDateTime ;
2924import java .util .Base64 ;
25+ import java .util .HashSet ;
3026import java .util .List ;
3127
3228import static java .util .Arrays .asList ;
3632import static org .hamcrest .Matchers .notNullValue ;
3733import static uk .co .probablyfine .matchers .Java8Matchers .where ;
3834
39- public class CreateSignatureTest {
35+ class CreateSignatureTest {
4036
4137 private CreateSignature createSignature ;
4238
@@ -48,16 +44,10 @@ public class CreateSignatureTest {
4844 private KeyStoreConfig noekkelpar ;
4945 private List <ASiCEAttachable > files ;
5046
51- private static final Unmarshaller unmarshaller ; static {
52- try {
53- unmarshaller = JAXBContext .newInstance (XAdESSignatures .class , QualifyingProperties .class ).createUnmarshaller ();
54- } catch (JAXBException e ) {
55- throw new RuntimeException (e );
56- }
57- }
47+ private static final JaxbMarshaller unmarshaller = new JaxbMarshaller (new HashSet <>(asList (XAdESSignatures .class , QualifyingProperties .class )));
5848
5949 @ BeforeEach
60- public void setUp () {
50+ void setUp () {
6151 noekkelpar = TestKonfigurasjon .CLIENT_KEYSTORE ;
6252 files = asList (
6353 file ("dokument.pdf" , "hoveddokument-innhold" .getBytes (), DocumentType .PDF .getMediaType ()),
@@ -69,7 +59,7 @@ public void setUp() {
6959 }
7060
7161 @ Test
72- public void test_generated_signatures () throws JAXBException {
62+ void test_generated_signatures () {
7363 /*
7464 * Expected signature value (Base-64 encoded) from the given keys, files, and time of the signing.
7565 * If this changes, something has changed in the signature implementation, and must be investigated!
@@ -81,7 +71,7 @@ public void test_generated_signatures() throws JAXBException {
8171 "nBa0FMipG5jtqUPYJJMTt56wIJlwQ95PhGIEYtdRYwxlgSau9Bw+wYmD4NU0K0hw6FgBQ/UDF87T5Zr7HTPWPMwpngkWg==" ;
8272
8373 Signature signature = createSignature .createSignature (files , noekkelpar );
84- XAdESSignatures xAdESSignatures = ( XAdESSignatures ) unmarshaller .unmarshal (new StreamSource ( new ByteArrayInputStream ( signature .getContent ())) );
74+ XAdESSignatures xAdESSignatures = unmarshaller .unmarshal (signature .getContent (), XAdESSignatures . class );
8575
8676 assertThat (xAdESSignatures , where (XAdESSignatures ::getSignatures , hasSize (1 )));
8777 no .digipost .signature .api .xml .thirdparty .xmldsig .Signature dSignature = xAdESSignatures .getSignatures ().get (0 );
@@ -91,10 +81,10 @@ public void test_generated_signatures() throws JAXBException {
9181 }
9282
9383 @ Test
94- public void test_xades_signed_properties () throws JAXBException {
84+ void test_xades_signed_properties () {
9585 Signature signature = createSignature .createSignature (files , noekkelpar );
9686
97- XAdESSignatures xAdESSignatures = ( XAdESSignatures ) unmarshaller .unmarshal (new StreamSource ( new ByteArrayInputStream ( signature .getContent ())) );
87+ XAdESSignatures xAdESSignatures = unmarshaller .unmarshal (signature .getContent (), XAdESSignatures . class );
9888 no .digipost .signature .api .xml .thirdparty .xmldsig .Object object = xAdESSignatures .getSignatures ().get (0 ).getObjects ().get (0 );
9989
10090 QualifyingProperties xadesProperties = (QualifyingProperties ) object .getContent ().get (0 );
@@ -106,14 +96,14 @@ public void test_xades_signed_properties() throws JAXBException {
10696 }
10797
10898 @ Test
109- public void should_support_filenames_with_spaces_and_other_characters () throws JAXBException {
99+ void should_support_filenames_with_spaces_and_other_characters () {
110100 List <ASiCEAttachable > otherFiles = asList (
111101 file ("dokument (2).pdf" , "hoveddokument-innhold" .getBytes (), DocumentType .PDF .getMediaType ()),
112102 file ("manifest.xml" , "manifest-innhold" .getBytes (), ASiCEAttachable .XML_MEDIATYPE )
113103 );
114104
115105 Signature signature = createSignature .createSignature (otherFiles , noekkelpar );
116- XAdESSignatures xAdESSignatures = ( XAdESSignatures ) unmarshaller .unmarshal (new StreamSource ( new ByteArrayInputStream ( signature .getContent ())) );
106+ XAdESSignatures xAdESSignatures = unmarshaller .unmarshal (signature .getContent (), XAdESSignatures . class );
117107 String uri = xAdESSignatures .getSignatures ().get (0 ).getSignedInfo ().getReferences ().get (0 ).getURI ();
118108 assertThat (uri , is ("dokument+%282%29.pdf" ));
119109 }
0 commit comments