Skip to content

Commit f53ec57

Browse files
committed
✅ Improved OutputService GeneratedPrintedOutput tests
1 parent acf5d45 commit f53ec57

2 files changed

Lines changed: 67 additions & 49 deletions

File tree

fluentforms/core/src/test/java/com/_4point/aem/fluentforms/impl/output/OutputServiceImplTest.java

Lines changed: 64 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.Locale;
1010

1111
import org.junit.jupiter.api.BeforeEach;
12-
import org.junit.jupiter.api.Disabled;
1312
import org.junit.jupiter.api.DisplayName;
1413
import org.junit.jupiter.api.Test;
1514
import org.junit.jupiter.api.extension.ExtendWith;
@@ -24,9 +23,11 @@
2423
import com._4point.aem.fluentforms.api.output.OutputService;
2524
import com._4point.aem.fluentforms.api.output.OutputService.OutputServiceException;
2625
import com._4point.aem.fluentforms.api.output.PDFOutputOptions;
26+
import com._4point.aem.fluentforms.api.output.PrintConfig;
2727
import com._4point.aem.fluentforms.api.output.PrintedOutputOptions;
2828
import com._4point.aem.fluentforms.impl.UsageContext;
2929
import com.adobe.fd.output.api.AcrobatVersion;
30+
import com.adobe.fd.output.api.PaginationOverride;
3031

3132
import io.wcm.testing.mock.aem.junit5.AemContextExtension;
3233

@@ -47,7 +48,7 @@ void setUp() throws Exception {
4748
@Test
4849
@DisplayName("Test GeneratePDFOutput(Document,...) Happy Path.")
4950
void testGeneratePDFOutputDocumentDocumentPDFOutputOptions() throws Exception {
50-
MockPdfOutputService svc = new MockPdfOutputService();
51+
MockPdfOutputService svc = new MockPdfOutputService(adobeOutputService);
5152

5253
Document template = Mockito.mock(Document.class);
5354
Document data = Mockito.mock(Document.class);
@@ -95,7 +96,7 @@ void testRenderPDFOutputDocument__OutputServiceExceptionThrown() throws Exceptio
9596
@Test
9697
@DisplayName("Test GeneratePDFOutput(Path,...) Happy Path, No Context Root.")
9798
void testGeneratePDFOutputPathDocumentDefaultPDFOutputOptions() throws Exception {
98-
MockPdfOutputService svc = new MockPdfOutputService();
99+
MockPdfOutputService svc = new MockPdfOutputService(adobeOutputService);
99100

100101
Path filename = TestUtils.SAMPLE_FORM;
101102
Document data = Mockito.mock(Document.class);
@@ -113,7 +114,7 @@ void testGeneratePDFOutputPathDocumentDefaultPDFOutputOptions() throws Exception
113114
@Test
114115
@DisplayName("Test GeneratePDFOutput(Path,...) Happy Path, with Context Root.")
115116
void testGeneratePDFOutputPathDocumentNonDefaultPDFOutputOptions() throws Exception {
116-
MockPdfOutputService svc = new MockPdfOutputService();
117+
MockPdfOutputService svc = new MockPdfOutputService(adobeOutputService);
117118

118119
Path filename = TestUtils.SAMPLE_FORM.getFileName();
119120
Document data = Mockito.mock(Document.class);
@@ -180,7 +181,7 @@ void testGeneratePDFOutputPath__BadTemplate() throws Exception {
180181
@Test
181182
@DisplayName("Test GeneratePDFOutput(URL,...) Happy Path, no contentRoot.")
182183
void testGeneratePDFOutputUrlDocumentDefaultPDFOutputOptions() throws Exception {
183-
MockPdfOutputService svc = new MockPdfOutputService();
184+
MockPdfOutputService svc = new MockPdfOutputService(adobeOutputService);
184185

185186
String expectedTemplateFilename = "bar.xdp";
186187
String expectedContextRoot = "http://www.example.com/foo/";
@@ -200,7 +201,7 @@ void testGeneratePDFOutputUrlDocumentDefaultPDFOutputOptions() throws Exception
200201
@Test
201202
@DisplayName("Test GeneratePDFOutput(URL,...) Happy Path, with contentRoot.")
202203
void testGeneratePDFOutputUrlDocumentWithPDFOutputOptions() throws Exception {
203-
MockPdfOutputService svc = new MockPdfOutputService();
204+
MockPdfOutputService svc = new MockPdfOutputService(adobeOutputService);
204205

205206
String expectedTemplateFilename = "http://www.example.com/foo/bar.xdp";
206207
String expectedContextRoot = "http://www.otherexample.com/foo/";
@@ -254,7 +255,7 @@ void testGeneratePDFOutputUrl__FormsServiceExceptionThrown() throws Exception {
254255
@Test
255256
@DisplayName("Test GeneratePDFOutput(PathOrUrl,...) Happy Path with no contentRoot.")
256257
void testGeneratePDFOutputPathOrUrlDocumentDefaultPDFOutputOptions() throws Exception {
257-
MockPdfOutputService svc = new MockPdfOutputService();
258+
MockPdfOutputService svc = new MockPdfOutputService(adobeOutputService);
258259

259260
String expectedTemplateFilename = "bar.xdp";
260261
String expectedContextRoot = "file:foo/";
@@ -274,7 +275,7 @@ void testGeneratePDFOutputPathOrUrlDocumentDefaultPDFOutputOptions() throws Exce
274275
@Test
275276
@DisplayName("Test GeneratePDFOutput(PathOrUrl,...) Happy Path with contentRoot.")
276277
void testGeneratePDFOutputPathOrUrlDocumentWithPDFOutputOptions() throws Exception {
277-
MockPdfOutputService svc = new MockPdfOutputService();
278+
MockPdfOutputService svc = new MockPdfOutputService(adobeOutputService);
278279

279280
String expectedTemplateFilename = "file:foo/bar.xdp";
280281
String expectedContextRoot = "file:notfoo/";
@@ -295,7 +296,7 @@ void testGeneratePDFOutputPathOrUrlDocumentWithPDFOutputOptions() throws Excepti
295296
@Test
296297
@DisplayName("Test GeneratePDFOutput(Crx PathOrUrl,...) Happy Path with no contextRoot.")
297298
void testGeneratePDFOutputCrxUrlDocumentDefaultPDFOutputOptions() throws Exception {
298-
MockPdfOutputService svc = new MockPdfOutputService();
299+
MockPdfOutputService svc = new MockPdfOutputService(adobeOutputService);
299300

300301
String expectedTemplateFilename = "bar.xdp";
301302
String expectedContextRoot = "crx:/content/dam/formsanddocuments/foo/";
@@ -315,7 +316,7 @@ void testGeneratePDFOutputCrxUrlDocumentDefaultPDFOutputOptions() throws Excepti
315316
@Test
316317
@DisplayName("Test GeneratePDFOutput(Crx PathOrUrl,...) Happy Path with contextRoot.")
317318
void testGeneratePDFOutputCrxUrlDocumentWithPDFOutputOptions() throws Exception {
318-
MockPdfOutputService svc = new MockPdfOutputService();
319+
MockPdfOutputService svc = new MockPdfOutputService(adobeOutputService);
319320

320321
String expectedTemplateFilename = "crx:/content/dam/formsanddocuments/foo/bar.xdp";
321322
String expectedContextRoot = "crx:/othercontent/dam/foo/bar/";
@@ -357,7 +358,7 @@ void testGeneratePDFOutputPathOrUrl_nullArguments() throws Exception {
357358

358359
@Test
359360
void testGeneratePDFOutputDocument() throws Exception {
360-
MockPdfOutputService svc = new MockPdfOutputService();
361+
MockPdfOutputService svc = new MockPdfOutputService(adobeOutputService);
361362

362363
Document template = Mockito.mock(Document.class);
363364
Document data = Mockito.mock(Document.class);
@@ -385,7 +386,7 @@ void testGeneratePDFOutputDocument() throws Exception {
385386

386387
@Test
387388
void testGeneratePDFOutputPath() throws Exception {
388-
MockPdfOutputService svc = new MockPdfOutputService();
389+
MockPdfOutputService svc = new MockPdfOutputService(adobeOutputService);
389390

390391
Path contentRoot = TestUtils.SAMPLE_FORM.getParent().getParent();
391392
Path filename = contentRoot.relativize(TestUtils.SAMPLE_FORM);
@@ -415,7 +416,7 @@ void testGeneratePDFOutputPath() throws Exception {
415416

416417
@Test
417418
void testGeneratePDFOutputUrl() throws Exception {
418-
MockPdfOutputService svc = new MockPdfOutputService();
419+
MockPdfOutputService svc = new MockPdfOutputService(adobeOutputService);
419420

420421
PathOrUrl filename = PathOrUrl.from("file:foo/bar.xdp");
421422
Document data = Mockito.mock(Document.class);
@@ -443,7 +444,7 @@ void testGeneratePDFOutputUrl() throws Exception {
443444

444445
@Test
445446
void testGeneratePDFOutputPathOrUrl() throws Exception {
446-
MockPdfOutputService svc = new MockPdfOutputService();
447+
MockPdfOutputService svc = new MockPdfOutputService(adobeOutputService);
447448

448449
PathOrUrl filename = PathOrUrl.from("file:foo/bar.xdp");
449450
Document data = Mockito.mock(Document.class);
@@ -471,7 +472,7 @@ void testGeneratePDFOutputPathOrUrl() throws Exception {
471472

472473
@Test
473474
void testGeneratePDFOutputCrxUrl() throws Exception {
474-
MockPdfOutputService svc = new MockPdfOutputService();
475+
MockPdfOutputService svc = new MockPdfOutputService(adobeOutputService);
475476

476477
PathOrUrl filename = PathOrUrl.from("crx:/content/dam/formsanddocuments/foo/bar.xdp");
477478
Document data = Mockito.mock(Document.class);
@@ -497,14 +498,15 @@ void testGeneratePDFOutputCrxUrl() throws Exception {
497498
PDFOutputOptionsImplTest.assertNotEmpty(svc.getOptionsArg());
498499
}
499500

500-
@Disabled
501+
@Test
502+
@DisplayName("Test GeneratePrintedOutputBatch() throws UnsupportedOperationException.")
501503
void testGeneratePDFOutputBatch() {
502-
fail("Not yet implemented");
504+
assertThrows(UnsupportedOperationException.class, ()->underTest.generatePDFOutputBatch(null, null, null, null));
503505
}
504506

505507
@Test
506508
void testGeneratePrintedOutputDocumentDocumentPrintedOutputOptions() throws Exception {
507-
MockPrintedOutputService svc = new MockPrintedOutputService();
509+
MockPrintedOutputService svc = new MockPrintedOutputService(adobeOutputService);
508510

509511
Document template = Mockito.mock(Document.class);
510512
Document data = Mockito.mock(Document.class);
@@ -553,7 +555,7 @@ void testRenderPrintedOutputDocument__OutputServiceExceptionThrown() throws Exce
553555
@Test
554556
@DisplayName("Test GeneratePrintedOutput(Path,...) Happy Path, No Context Root.")
555557
void testGeneratePrintedOutputPathDocumentDefaultPrintedOutputOptions() throws Exception {
556-
MockPrintedOutputService svc = new MockPrintedOutputService();
558+
MockPrintedOutputService svc = new MockPrintedOutputService(adobeOutputService);
557559

558560
Path filename = TestUtils.SAMPLE_FORM;
559561
Document data = Mockito.mock(Document.class);
@@ -571,7 +573,7 @@ void testGeneratePrintedOutputPathDocumentDefaultPrintedOutputOptions() throws E
571573
@Test
572574
@DisplayName("Test GeneratePrintedOutput(Path,...) Happy Path, with Context Root.")
573575
void testGeneratePrintedOutputPathDocumentNonDefaultPrintedOutputOptions() throws Exception {
574-
MockPrintedOutputService svc = new MockPrintedOutputService();
576+
MockPrintedOutputService svc = new MockPrintedOutputService(adobeOutputService);
575577

576578
Path filename = TestUtils.SAMPLE_FORM.getFileName();
577579
Document data = Mockito.mock(Document.class);
@@ -608,7 +610,7 @@ void testGeneratePrintedOutputPath_nullArguments() throws Exception {
608610
@Test
609611
@DisplayName("Test GeneratePrintedOutput(Document,...) null arguments.")
610612
void testRenderPrintedOutputDocument_nullArguments() throws Exception {
611-
//MockPrintedOutputService svc = new MockPrintedOutputService();
613+
//MockPrintedOutputService svc = new MockPrintedOutputService(adobeOutputService);
612614

613615
Document template = Mockito.mock(Document.class);
614616
Document data = Mockito.mock(Document.class);
@@ -626,7 +628,7 @@ void testRenderPrintedOutputDocument_nullArguments() throws Exception {
626628
@Test
627629
@DisplayName("Test GeneratePrintedOutput(Path,...) path argument.")
628630
void testRenderPrintedOutputDocumentPathOrUrl_PathInput() throws Exception {
629-
MockPrintedOutputService svc = new MockPrintedOutputService();
631+
MockPrintedOutputService svc = new MockPrintedOutputService(adobeOutputService);
630632

631633
Path filename = TestUtils.SAMPLE_FORM;
632634

@@ -639,21 +641,11 @@ void testRenderPrintedOutputDocumentPathOrUrl_PathInput() throws Exception {
639641

640642
}
641643

642-
@Disabled("Not currently working, needs investigation. Not a big issue, since generatePrintedOutput is not implemented elsewhere yet.")
643-
@Test
644-
@DisplayName("Test GeneratePrintedOutput(Path,...) path argument.")
645-
void testRenderPrintedOutputDocumentPathOrUrl_MockPathInput() throws Exception {
646-
PathOrUrl pathOrUrl = Mockito.mock(PathOrUrl.class);
647-
Document data = Mockito.mock(Document.class);
648-
PrintedOutputOptions printedOutputOptions = Mockito.mock(PrintedOutputOptions.class);
649-
IllegalArgumentException ex1 = assertThrows
650-
(IllegalArgumentException.class, ()->underTest.generatePrintedOutput(pathOrUrl, data, printedOutputOptions));
651-
652-
}
644+
653645
@Test
654646
@DisplayName("Test GeneratePrintedOutput(Url,...) path argument.")
655647
void testRenderPrintedOutputDocumentPathOrUrl_URLInput() throws Exception {
656-
MockPrintedOutputService svc = new MockPrintedOutputService();
648+
MockPrintedOutputService svc = new MockPrintedOutputService(adobeOutputService);
657649
String expectedTemplateFilename = "bar.xdp";
658650
String expectedContextRoot = "http://www.example.com/foo/";
659651
URL url = new URL(expectedContextRoot + expectedTemplateFilename);
@@ -666,22 +658,48 @@ void testRenderPrintedOutputDocumentPathOrUrl_URLInput() throws Exception {
666658
assertSame(resultURL, svc.getResult(), "Expected the document to be the same - Url input.");
667659
}
668660

669-
@Disabled("Not currently working, needs investigation. Not a big issue, since generatePrintedOutput is not implemented elsewhere yet.")
661+
@Test
662+
@DisplayName("Test GeneratePrintedOutput(Document,...) with non-default options.")
663+
void testGeneratePrintedOutputDocument() throws Exception {
664+
MockPrintedOutputService svc = new MockPrintedOutputService(adobeOutputService);
665+
666+
Document template = Mockito.mock(Document.class);
667+
Document data = Mockito.mock(Document.class);
668+
Document result = underTest.generatePrintedOutput()
669+
.setContentRoot(Paths.get("foo", "bar"))
670+
.setCopies(2)
671+
.setDebugDir(Paths.get("bar", "foo"))
672+
.setLocale(Locale.CANADA_FRENCH)
673+
.setPaginationOverride(PaginationOverride.duplexLongEdge)
674+
.setPrintConfig(PrintConfig.HP_PCL_5e)
675+
.xci()
676+
.embedPclFonts(false)
677+
.done()
678+
.executeOn(template, data);
679+
680+
// Verify that all the results are correct.
681+
assertEquals(template, svc.getTemplateDocArg(), "Expected the template filename passed to AEM would match the filename used.");
682+
assertTrue(svc.getDataArg() == data, "Expected the data Document passed to AEM would match the data Document used.");
683+
assertTrue(result == svc.getResult(), "Expected the Document returned by AEM would match the Document result.");
684+
PrintedOutputOptionsImplTest.assertNotEmpty(svc.getOptionsArg());
685+
}
686+
687+
688+
@DisplayName("Test GeneratePrintedOutput(CrxUrl,...) throws FileNotFoundException.")
670689
@Test
671690
void testGeneratePrintedOutputCrxUrl() throws Exception {
672-
MockPrintedOutputService svc = new MockPrintedOutputService();
691+
MockPrintedOutputService svc = new MockPrintedOutputService(adobeOutputService);
673692

674693
PathOrUrl filename = PathOrUrl.from("crx:/content/dam/formsanddocuments/foo/bar.xdp");
675694
Document data = Mockito.mock(Document.class);
676695

677-
PrintedOutputOptions printedOutputOptions = Mockito.mock(PrintedOutputOptions.class);
678-
679-
Document resultCrx = underTest.generatePrintedOutput(filename, data, printedOutputOptions);
696+
Document resultCrx = underTest.generatePrintedOutput().executeOn(filename, data);
680697

681698
// Verify that all the results are correct.
682-
assertEquals(filename.toString(), svc.getTemplateStringArg(), "Expected the template filename passed to AEM would match the filename used.");
699+
assertEquals(filename.getFilename().orElseThrow().toString(), svc.getTemplateStringArg(), "Expected the template filename passed to AEM would match the filename used.");
683700
assertSame(data, svc.getDataArg(), "Expected the data Document passed to AEM would match the data Document used.");
684701
assertSame(resultCrx, svc.getResult(), "Expected the Document returned by AEM would match the Document result.");
702+
PrintedOutputOptionsImplTest.assertEmpty(svc.getOptionsArg(), filename.getParent().orElseThrow().getCrxUrl());
685703
}
686704

687705
@Test
@@ -710,9 +728,10 @@ void testGeneratePrintedOutputPath__FormsServiceExceptionThrown() throws Excepti
710728
assertThrows(OutputServiceException.class, ()->underTest.generatePrintedOutput(filename, data, printedFormRenderOptions));
711729
}
712730

713-
@Disabled
731+
@Test
732+
@DisplayName("Test GeneratePrintedOutputBatch() throws UnsupportedOperationException.")
714733
void testGeneratePrintedOutputBatch() {
715-
fail("Not yet implemented");
734+
assertThrows(UnsupportedOperationException.class, ()->underTest.generatePrintedOutputBatch(null, null, null, null));
716735
}
717736

718737
private class MockPdfOutputService {
@@ -722,8 +741,7 @@ private class MockPdfOutputService {
722741
private final ArgumentCaptor<Document> dataArg = ArgumentCaptor.forClass(Document.class);
723742
private final ArgumentCaptor<PDFOutputOptions> optionsArg = ArgumentCaptor.forClass(PDFOutputOptions.class);
724743

725-
protected MockPdfOutputService() throws OutputServiceException {
726-
super();
744+
protected MockPdfOutputService(TraditionalOutputService adobeOutputService) throws OutputServiceException {
727745
// These are "lenient" because we only expect one or the other to be called. Also, in some of the exceptional cases,
728746
// neither are called.
729747
Mockito.lenient().when(adobeOutputService.generatePDFOutput(templateStringArg.capture(), dataArg.capture(), optionsArg.capture())).thenReturn(result);
@@ -751,15 +769,14 @@ protected PDFOutputOptions getOptionsArg() {
751769
}
752770
}
753771

754-
private class MockPrintedOutputService {
772+
private static class MockPrintedOutputService {
755773
private final Document result = Mockito.mock(Document.class);
756774
private final ArgumentCaptor<String> templateStringArg = ArgumentCaptor.forClass(String.class);
757775
private final ArgumentCaptor<Document> templateDocArg = ArgumentCaptor.forClass(Document.class);
758776
private final ArgumentCaptor<Document> dataArg = ArgumentCaptor.forClass(Document.class);
759777
private final ArgumentCaptor<PrintedOutputOptions> optionsArg = ArgumentCaptor.forClass(PrintedOutputOptions.class);
760778

761-
protected MockPrintedOutputService() throws OutputServiceException {
762-
super();
779+
protected MockPrintedOutputService(TraditionalOutputService adobeOutputService) throws OutputServiceException {
763780
// These are "lenient" because we only expect one or the other to be called. Also, in some of the exceptional cases,
764781
// neither are called.
765782
Mockito.lenient().when(adobeOutputService.generatePrintedOutput(templateStringArg.capture(), dataArg.capture(), optionsArg.capture())).thenReturn(result);

fluentforms/core/src/test/java/com/_4point/aem/fluentforms/impl/output/PrintedOutputOptionsImplTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.junit.jupiter.api.Test;
1010

1111
import com._4point.aem.fluentforms.api.output.PrintConfig;
12+
import com._4point.aem.fluentforms.api.output.PrintedOutputOptions;
1213
import com._4point.aem.fluentforms.impl.XciImpl;
1314
import com.adobe.fd.output.api.PaginationOverride;
1415

@@ -24,7 +25,7 @@ void testToAdobePrintedOutputOptions_NoChanges() {
2425
assertEmpty(underTest, null);
2526
}
2627

27-
private static void assertEmpty(PrintedOutputOptionsImpl printedOutputOptions, String contentRoot) {
28+
/* package */ static void assertEmpty(PrintedOutputOptions printedOutputOptions, String contentRoot) {
2829
com.adobe.fd.output.api.PrintedOutputOptions adobePrintedOutputOptions = AdobeOutputServiceAdapter.toAdobePrintedOutputOptions(printedOutputOptions);
2930
assertEquals(contentRoot, adobePrintedOutputOptions.getContentRoot()); // We modify the content root, so we expect it to be different than the empty version (which would be null).
3031
assertEquals(emptyPrintedOutputOptions.getCopies(), adobePrintedOutputOptions.getCopies());
@@ -54,7 +55,7 @@ void testToAdobePrintedOutputOptions_AllChanges() {
5455
assertNotEmpty(underTest);
5556
}
5657

57-
/* package */ static void assertNotEmpty(PrintedOutputOptionsImpl printedOutputOptions) {
58+
/* package */ static void assertNotEmpty(PrintedOutputOptions printedOutputOptions) {
5859
com.adobe.fd.output.api.PrintedOutputOptions adobePrintedOutputOptions = AdobeOutputServiceAdapter.toAdobePrintedOutputOptions(printedOutputOptions);
5960
assertNotEquals(emptyPrintedOutputOptions.getContentRoot(), adobePrintedOutputOptions.getContentRoot());
6061
assertNotEquals(emptyPrintedOutputOptions.getCopies(), adobePrintedOutputOptions.getCopies());

0 commit comments

Comments
 (0)