From f1df7b745aa3242d7bb1d36c18a591b5a69668cd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Oct 2021 09:31:22 +0000 Subject: [PATCH 1/4] Bump org.owasp.dependencycheck from 6.2.2 to 6.3.2 Bumps org.owasp.dependencycheck from 6.2.2 to 6.3.2. --- updated-dependencies: - dependency-name: org.owasp.dependencycheck dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 121a60eb..f6ec8819 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ plugins { id 'checkstyle' id 'java' id 'maven-publish' - id "org.owasp.dependencycheck" version "6.2.2" + id "org.owasp.dependencycheck" version "6.3.2" id "org.sonarqube" version "3.3" } From e7024a5e793da3987295252f1c1a196186075243 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Oct 2021 09:41:20 +0000 Subject: [PATCH 2/4] Bump poipath from 1.0.0 to 1.1.1 Bumps poipath from 1.0.0 to 1.1.1. --- updated-dependencies: - dependency-name: com.docu-tools:poipath dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 4e03dfb0..329a5fea 100644 --- a/build.gradle +++ b/build.gradle @@ -43,7 +43,7 @@ dependencies { testImplementation('org.junit.jupiter:junit-jupiter:5.8.1') testImplementation("org.hamcrest:hamcrest:2.2") - testImplementation("com.docu-tools:poipath:1.0.0") + testImplementation("com.docu-tools:poipath:1.1.1") } tasks.withType(Checkstyle) { From 3b98147f4df29282f8ae8352af387d2d72b4cacd Mon Sep 17 00:00:00 2001 From: Anton Oellerer Date: Mon, 4 Oct 2021 11:46:09 +0200 Subject: [PATCH 3/4] Set OWASP CVSS threshold to 6 Up until now, a CVSS threshold of 9.0 was specified, which meant that it practically never triggers. Especially with the introduction of dependabot it is important to keep an eye on vulnerabilities. --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index f6ec8819..c8e23d13 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { } group 'com.docu-tools' -version = '1.2.3' +version = '1.2.5' sourceCompatibility = 17 targetCompatibility = 17 @@ -56,8 +56,8 @@ tasks.withType(Checkstyle) { dependencyCheck { format = 'ALL' - junitFailOnCVSS = 7.0 - failBuildOnCVSS = 9.0 + junitFailOnCVSS = 6.0 + failBuildOnCVSS = 6.0 suppressionFile = 'config/dependency-check/suppression.xml' } From bd6286a5f1bcaaba49b953b7822ade66da2af603 Mon Sep 17 00:00:00 2001 From: Anton Oellerer Date: Mon, 4 Oct 2021 12:04:35 +0200 Subject: [PATCH 4/4] Update tests to fit `poipath 1.0.0` In `poipath 1.0.0`, a few modifications have been done in the way paragraphs and tables are serviced. This commit updates the failing test so that they run successfully again. --- build.gradle | 2 +- .../jocument/impl/word/WordGeneratorTest.java | 120 +++++++++--------- 2 files changed, 63 insertions(+), 59 deletions(-) diff --git a/build.gradle b/build.gradle index 329a5fea..f9a1923e 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { } group 'com.docu-tools' -version = '1.2.4' +version = '1.2.6' sourceCompatibility = 17 targetCompatibility = 17 diff --git a/src/test/java/com/docutools/jocument/impl/word/WordGeneratorTest.java b/src/test/java/com/docutools/jocument/impl/word/WordGeneratorTest.java index 7a58e32b..74715893 100644 --- a/src/test/java/com/docutools/jocument/impl/word/WordGeneratorTest.java +++ b/src/test/java/com/docutools/jocument/impl/word/WordGeneratorTest.java @@ -1,26 +1,29 @@ package com.docutools.jocument.impl.word; -import com.docutools.jocument.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; + +import com.docutools.jocument.CustomPlaceholderRegistry; +import com.docutools.jocument.Document; +import com.docutools.jocument.PlaceholderResolver; +import com.docutools.jocument.Template; +import com.docutools.jocument.TestUtils; import com.docutools.jocument.impl.CustomPlaceholderRegistryImpl; import com.docutools.jocument.impl.ReflectionResolver; import com.docutools.jocument.sample.model.SampleModelData; import com.docutools.jocument.sample.placeholders.QuotePlaceholder; -import com.docutools.poipath.PoiPath; -import org.apache.poi.xwpf.usermodel.XWPFDocument; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - +import com.docutools.poipath.xwpf.XWPFDocumentWrapper; import java.io.IOException; import java.time.LocalDate; import java.time.Period; import java.time.format.DateTimeFormatter; import java.util.Locale; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; +import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; @DisplayName("Word Generator Tests") @Tag("automated") @@ -40,7 +43,7 @@ void cleanup() throws IOException { void shouldGenerateSimpleDocument() throws InterruptedException, IOException { // Arrange Template template = Template.fromClassPath("/templates/word/UserProfileTemplate.docx") - .orElseThrow(); + .orElseThrow(); PlaceholderResolver resolver = new ReflectionResolver(SampleModelData.PICARD_PERSON); // Act @@ -50,15 +53,15 @@ void shouldGenerateSimpleDocument() throws InterruptedException, IOException { // Assert assertThat(document.completed(), is(true)); xwpfDocument = TestUtils.getXWPFDocumentFromDocument(document); - var documentWrapper = PoiPath.xwpf(xwpfDocument); - assertThat(documentWrapper.paragraph(0).text(), equalTo("User Profile: Jean-Luc Picard")); - assertThat(documentWrapper.paragraph(2).text(), equalTo("Name: Jean-Luc")); - assertThat(documentWrapper.paragraph(3).text(), equalTo("Last Name: Picard")); - assertThat(documentWrapper.paragraph(4).text(), equalTo("Age: " - + Period.between(LocalDate.of(1948, 9, 23), LocalDate.now()).getYears() - + " (" - + DateTimeFormatter.ofPattern("dd.MM.yyyy", Locale.US).format(LocalDate.of(1948, 9, 23)) - + ")")); + var documentWrapper = new XWPFDocumentWrapper(xwpfDocument); + assertThat(documentWrapper.bodyElement(0).asParagraph().text(), equalTo("User Profile: Jean-Luc Picard")); + assertThat(documentWrapper.bodyElement(2).asParagraph().text(), equalTo("Name: Jean-Luc")); + assertThat(documentWrapper.bodyElement(3).asParagraph().text(), equalTo("Last Name: Picard")); + assertThat(documentWrapper.bodyElement(4).asParagraph().text(), equalTo("Age: " + + Period.between(LocalDate.of(1948, 9, 23), LocalDate.now()).getYears() + + " (" + + DateTimeFormatter.ofPattern("dd.MM.yyyy", Locale.US).format(LocalDate.of(1948, 9, 23)) + + ")")); } @Test @@ -66,7 +69,7 @@ void shouldGenerateSimpleDocument() throws InterruptedException, IOException { void shouldGenerateMultiLocaleDocument() throws InterruptedException, IOException { // Arrange Template template = Template.fromClassPath("/templates/word/UserProfileTemplateWithDifferentLocales.docx") - .orElseThrow(); + .orElseThrow(); PlaceholderResolver resolver = new ReflectionResolver(SampleModelData.PICARD_PERSON); // Act @@ -76,20 +79,20 @@ void shouldGenerateMultiLocaleDocument() throws InterruptedException, IOExceptio // Assert assertThat(document.completed(), is(true)); xwpfDocument = TestUtils.getXWPFDocumentFromDocument(document); - var documentWrapper = PoiPath.xwpf(xwpfDocument); - assertThat(documentWrapper.paragraph(0).text(), equalTo("User Profile: Jean-Luc Picard")); - assertThat(documentWrapper.paragraph(2).text(), equalTo("Name: Jean-Luc")); - assertThat(documentWrapper.paragraph(3).text(), equalTo("Last Name: Picard")); - assertThat(documentWrapper.paragraph(4).text(), equalTo("Age German: " - + Period.between(LocalDate.of(1948, 9, 23), LocalDate.now()).getYears() - + " (" - + DateTimeFormatter.ofPattern("dd.MM.yyyy", Locale.US).format(LocalDate.of(1948, 9, 23)) - + ")")); - assertThat(documentWrapper.paragraph(5).text(), equalTo("Age English: " - + Period.between(LocalDate.of(1948, 9, 23), LocalDate.now()).getYears() - + " (" - + DateTimeFormatter.ofPattern("dd.MM.yyyy", Locale.US).format(LocalDate.of(1948, 9, 23)) - + ")")); + var documentWrapper = new XWPFDocumentWrapper(xwpfDocument); + assertThat(documentWrapper.bodyElement(0).asParagraph().text(), equalTo("User Profile: Jean-Luc Picard")); + assertThat(documentWrapper.bodyElement(2).asParagraph().text(), equalTo("Name: Jean-Luc")); + assertThat(documentWrapper.bodyElement(3).asParagraph().text(), equalTo("Last Name: Picard")); + assertThat(documentWrapper.bodyElement(4).asParagraph().text(), equalTo("Age German: " + + Period.between(LocalDate.of(1948, 9, 23), LocalDate.now()).getYears() + + " (" + + DateTimeFormatter.ofPattern("dd.MM.yyyy", Locale.US).format(LocalDate.of(1948, 9, 23)) + + ")")); + assertThat(documentWrapper.bodyElement(5).asParagraph().text(), equalTo("Age English: " + + Period.between(LocalDate.of(1948, 9, 23), LocalDate.now()).getYears() + + " (" + + DateTimeFormatter.ofPattern("dd.MM.yyyy", Locale.US).format(LocalDate.of(1948, 9, 23)) + + ")")); } @Test @@ -97,7 +100,7 @@ void shouldGenerateMultiLocaleDocument() throws InterruptedException, IOExceptio void shouldReplacePlaceholdersInTables() throws InterruptedException, IOException { // Arrange Template template = Template.fromClassPath("/templates/word/UserProfileWithTableTemplate.docx") - .orElseThrow(); + .orElseThrow(); PlaceholderResolver resolver = new ReflectionResolver(SampleModelData.PICARD_PERSON); // Act @@ -107,8 +110,8 @@ void shouldReplacePlaceholdersInTables() throws InterruptedException, IOExceptio // Assert assertThat(document.completed(), is(true)); xwpfDocument = TestUtils.getXWPFDocumentFromDocument(document); - var documentWrapper = PoiPath.xwpf(xwpfDocument); - var table = documentWrapper.table(0); + var documentWrapper = new XWPFDocumentWrapper(xwpfDocument); + var table = documentWrapper.bodyElement(0).asTable(); var birthdate = DateTimeFormatter.ofPattern("dd.MM.yyyy", Locale.US).format(LocalDate.of(1948, 9, 23)); assertThat(table.row(0).cell(0).bodyElement(0).asParagraph().text(), equalTo("Name")); assertThat(table.row(0).cell(1).bodyElement(0).asParagraph().text(), equalTo("Value")); @@ -123,7 +126,7 @@ void shouldReplacePlaceholdersInTables() throws InterruptedException, IOExceptio void shouldResolveCollectionPlaceholders() throws InterruptedException, IOException { // Arrange Template template = Template.fromClassPath("/templates/word/CollectionsTemplate.docx") - .orElseThrow(); + .orElseThrow(); PlaceholderResolver resolver = new ReflectionResolver(SampleModelData.PICARD); // Act @@ -133,19 +136,19 @@ void shouldResolveCollectionPlaceholders() throws InterruptedException, IOExcept // Assert assertThat(document.completed(), is(true)); xwpfDocument = TestUtils.getXWPFDocumentFromDocument(document); - var documentWrapper = PoiPath.xwpf(xwpfDocument); - assertThat(documentWrapper.paragraph(0).text(), equalTo("Captain: Jean-Luc Picard")); - assertThat(documentWrapper.paragraph(2).text(), equalTo("First Officer")); - assertThat(documentWrapper.table(3).row(0).cell(0).bodyElement(0).asParagraph().text(), equalTo("Name")); - assertThat(documentWrapper.table(3).row(0).cell(1).bodyElement(0).asParagraph().text(), equalTo("Rank")); - assertThat(documentWrapper.table(3).row(0).cell(2).bodyElement(0).asParagraph().text(), equalTo("Uniform")); - assertThat(documentWrapper.table(3).row(1).cell(0).bodyElement(0).asParagraph().text(), equalTo("Riker")); - assertThat(documentWrapper.table(3).row(1).cell(1).bodyElement(0).asParagraph().text(), equalTo("3")); - assertThat(documentWrapper.table(3).row(1).cell(2).bodyElement(0).asParagraph().text(), equalTo("Red")); - assertThat(documentWrapper.paragraph(6).text(), equalTo("Services")); - assertThat(documentWrapper.paragraph(8).text(), equalTo("USS Enterprise")); - assertThat(documentWrapper.paragraph(9).text(), equalTo("US Defiant")); - assertThat(documentWrapper.paragraph(11).text(), equalTo("And that’s that.")); + var documentWrapper = new XWPFDocumentWrapper(xwpfDocument); + assertThat(documentWrapper.bodyElement(0).asParagraph().text(), equalTo("Captain: Jean-Luc Picard")); + assertThat(documentWrapper.bodyElement(2).asParagraph().text(), equalTo("First Officer")); + assertThat(documentWrapper.bodyElement(3).asTable().row(0).cell(0).bodyElement(0).asParagraph().text(), equalTo("Name")); + assertThat(documentWrapper.bodyElement(3).asTable().row(0).cell(1).bodyElement(0).asParagraph().text(), equalTo("Rank")); + assertThat(documentWrapper.bodyElement(3).asTable().row(0).cell(2).bodyElement(0).asParagraph().text(), equalTo("Uniform")); + assertThat(documentWrapper.bodyElement(3).asTable().row(1).cell(0).bodyElement(0).asParagraph().text(), equalTo("Riker")); + assertThat(documentWrapper.bodyElement(3).asTable().row(1).cell(1).bodyElement(0).asParagraph().text(), equalTo("3")); + assertThat(documentWrapper.bodyElement(3).asTable().row(1).cell(2).bodyElement(0).asParagraph().text(), equalTo("Red")); + assertThat(documentWrapper.bodyElement(6).asParagraph().text(), equalTo("Services")); + assertThat(documentWrapper.bodyElement(8).asParagraph().text(), equalTo("USS Enterprise")); + assertThat(documentWrapper.bodyElement(9).asParagraph().text(), equalTo("US Defiant")); + assertThat(documentWrapper.bodyElement(11).asParagraph().text(), equalTo("And that’s that.")); } @Test @@ -163,8 +166,8 @@ void shouldApplyCustomWordPlaceholder() throws InterruptedException, IOException // Assert assertThat(document.completed(), is(true)); xwpfDocument = TestUtils.getXWPFDocumentFromDocument(document); - var documentWrapper = PoiPath.xwpf(xwpfDocument); - assertThat(documentWrapper.paragraph(2).run(0).pictures().size(), equalTo(1)); + var documentWrapper = new XWPFDocumentWrapper(xwpfDocument); + assertThat(documentWrapper.bodyElement(2).asParagraph().run(0).pictures().size(), equalTo(1)); } @Test @@ -184,7 +187,8 @@ void shouldApplyForeignCustomWordPlaceholder() throws InterruptedException, IOEx // Assert assertThat(document.completed(), is(true)); xwpfDocument = TestUtils.getXWPFDocumentFromDocument(document); - var documentWrapper = PoiPath.xwpf(xwpfDocument); - assertThat(documentWrapper.paragraph(0).run(0).text(), equalTo("Live your life not celebrating victories, but overcoming defeats.")); + var documentWrapper = new XWPFDocumentWrapper(xwpfDocument); + assertThat(documentWrapper.bodyElement(0).asParagraph().run(0).text(), + equalTo("Live your life not celebrating victories, but overcoming defeats.")); } } \ No newline at end of file