77import static com ._4point .testing .matchers .javalang .ExceptionMatchers .*;
88
99import java .io .IOException ;
10- import java .nio .file .Files ;
1110import java .util .Collections ;
12- import java .util .HashMap ;
1311import java .util .Map ;
1412import java .util .Map .Entry ;
1513
1816import org .junit .jupiter .api .DisplayName ;
1917import org .junit .jupiter .api .Tag ;
2018import org .junit .jupiter .api .Test ;
19+ import org .opentest4j .MultipleFailuresError ;
2120
2221import com ._4point .aem .docservices .rest_services .client .RestClient .ContentType ;
2322import com ._4point .aem .docservices .rest_services .client .assembler .RestServicesDocAssemblerServiceAdapter ;
@@ -70,47 +69,45 @@ void setUp() throws Exception {
7069 @ Test
7170 @ DisplayName ("Test AssembleDocuments() Happy Path." )
7271 void testAssembleDocuments () throws Exception {
73- byte [] samplePdf1 = Files .readAllBytes (SAMPLE_FORM_WITHOUT_DATA_PDF );
74- byte [] samplePdf2 = Files .readAllBytes (SAMPLE_FORM_WITHOUT_DATA_PDF );
75-
7672 AssemblerResult assemblerResult = underTest .invoke ()
77- .add ("File0.pdf" , DOC_FACTORY .create (samplePdf1 ))
78- .add ("File1.pdf" , DOC_FACTORY .create (samplePdf2 ).setContentType ("application/pdf" ))
73+ .add ("File0.pdf" , DOC_FACTORY .create (SAMPLE_FORM_WITHOUT_DATA_PDF ))
74+ .add ("File1.pdf" , DOC_FACTORY .create (SAMPLE_FORM_WITHOUT_DATA_PDF ).setContentType ("application/pdf" ))
7975 .executeOn (DOC_FACTORY .create (SAMPLE_FORM_DDX ));
8076
8177 Map <String , Document > resultDocuments = assemblerResult .getDocuments ();
8278 validateResultMap (resultDocuments );
8379 }
8480
85- private void validateResultMap (Map <String , Document > resultDocument ) throws IOException , PdfException {
86- for (Entry <String , Document > entry : resultDocument .entrySet ()){
81+ private void validateResultMap (Map <String , Document > resultMap ) throws IOException , PdfException {
82+ for (Entry <String , Document > entry : resultMap .entrySet ()){
8783 if (entry .getKey ().equals ("concatenatedPDF.pdf" )) {
88- byte [] resultByte = entry .getValue ().getInlineData ();
89- assertNotNull (resultByte );
90- Pdf pdfResult = Pdf .from (resultByte ); // Validate that it's a real PDF.
91- assertAll (
92- ()->assertEquals (ContentType .APPLICATION_PDF .contentType (), entry .getValue ().getContentType ()),
93- ()->assertThat (pdfResult .getProducer (), not (emptyOrNullString ()))
94- );
84+ validateResultDoc (entry .getValue ());
9585 }
9686 }
9787 }
88+
89+ private static void validateResultDoc (Document resultDoc ) throws IOException , PdfException , MultipleFailuresError {
90+ byte [] resultByte = resultDoc .getInputStream ().readAllBytes ();
91+ assertNotNull (resultByte );
92+ Pdf pdfResult = Pdf .from (resultByte ); // Validate that it's a real PDF.
93+ assertAll (
94+ ()->assertEquals (ContentType .APPLICATION_PDF .contentType (), resultDoc .getContentType ()),
95+ ()->assertThat (pdfResult .getProducer (), not (emptyOrNullString ()))
96+ );
97+ }
9898
9999 @ Test
100100 @ DisplayName ("Test AssembleDocuments() with all arguments Happy Path." )
101101 void testAssembleDocuments_withAllArgs () throws Exception {
102- byte [] samplePdf1 = Files .readAllBytes (SAMPLE_FORM_WITHOUT_DATA_PDF );
103- byte [] samplePdf2 = Files .readAllBytes (SAMPLE_FORM_WITHOUT_DATA_PDF );
104-
105102 AssemblerResult assemblerResult = underTest .invoke ()
106103 .setDefaultStyle ("" )
107104 .setFailOnError (Boolean .FALSE )
108105 .setFirstBatesNumber (0 )
109106 .setLogLevel (LogLevel .ALL )
110107 .setTakeOwnership (Boolean .FALSE )
111108 .setValidateOnly (Boolean .FALSE )
112- .add ("File0.pdf" , DOC_FACTORY .create (samplePdf1 ).setContentType ("application/pdf" ))
113- .add ("File1.pdf" , DOC_FACTORY .create (samplePdf2 ))
109+ .add ("File0.pdf" , DOC_FACTORY .create (SAMPLE_FORM_WITHOUT_DATA_PDF ).setContentType ("application/pdf" ))
110+ .add ("File1.pdf" , DOC_FACTORY .create (SAMPLE_FORM_WITHOUT_DATA_PDF ))
114111 .executeOn (DOC_FACTORY .create (SAMPLE_FORM_DDX ));
115112
116113 Map <String , Document > resultDocuments = assemblerResult .getDocuments ();
@@ -120,11 +117,9 @@ void testAssembleDocuments_withAllArgs() throws Exception {
120117 @ Test
121118 @ DisplayName ("Test testAssembleDocuments with bad data." )
122119 void testAssembleDocuments_BadData () throws Exception {
123- byte [] samplePdf1 = Files .readAllBytes (SAMPLE_FORM_PDF );
124- byte [] samplePdf2 = Files .readAllBytes (SAMPLE_FORM_PDF );
125- Map <String , Object > sourceDocuments = new HashMap <String , Object >();
126- sourceDocuments .put ("File0.pdf" , DOC_FACTORY .create (samplePdf1 ));
127- sourceDocuments .put ("File1.pdf" , DOC_FACTORY .create (samplePdf2 ));
120+ Map <String , Object > sourceDocuments = Map .of ("File0.pdf" , DOC_FACTORY .create (SAMPLE_FORM_PDF ),
121+ "File1.pdf" , DOC_FACTORY .create (SAMPLE_FORM_PDF )
122+ );
128123 AssemblerOptionsSpecImpl assemblerOptionsSpecImpl = new AssemblerOptionsSpecImpl ();
129124 assemblerOptionsSpecImpl .setLogLevel (LogLevel .ALL );
130125 AssemblerServiceException ex = assertThrows (AssemblerServiceException .class , ()->underTest .invoke (DOC_FACTORY .create (SAMPLE_FORM_DOCX ), sourceDocuments , assemblerOptionsSpecImpl ));
0 commit comments