|
| 1 | +/* |
| 2 | + * The contents of this file are subject to the terms of the Common Development and |
| 3 | + * Distribution License (the License). You may not use this file except in compliance with the |
| 4 | + * License. |
| 5 | + * |
| 6 | + * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the |
| 7 | + * specific language governing permission and limitations under the License. |
| 8 | + * |
| 9 | + * When distributing Covered Software, include this CDDL Header Notice in each file and include |
| 10 | + * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL |
| 11 | + * Header, with the fields enclosed by brackets [] replaced by your own identifying |
| 12 | + * information: "Portions copyright [year] [name of copyright owner]". |
| 13 | + * |
| 14 | + * Copyright 2026 3A Systems, LLC. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.openidentityplatform.doc.maven; |
| 18 | + |
| 19 | +import org.apache.commons.io.FileUtils; |
| 20 | +import org.apache.maven.execution.MavenSession; |
| 21 | +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; |
| 22 | +import org.apache.maven.plugin.testing.AbstractMojoTestCase; |
| 23 | +import org.apache.maven.project.MavenProject; |
| 24 | +import org.codehaus.plexus.util.xml.Xpp3Dom; |
| 25 | + |
| 26 | +import java.io.File; |
| 27 | +import java.io.Reader; |
| 28 | +import java.nio.charset.StandardCharsets; |
| 29 | +import java.nio.file.Files; |
| 30 | + |
| 31 | +import static org.assertj.core.api.Assertions.assertThat; |
| 32 | + |
| 33 | +public class AsciidocToPdfMojoConfigurationTest extends AbstractMojoTestCase { |
| 34 | + |
| 35 | + private File buildDirectory; |
| 36 | + |
| 37 | + @Override |
| 38 | + protected void setUp() throws Exception { |
| 39 | + super.setUp(); |
| 40 | + buildDirectory = Files.createTempDirectory("pdf-configuration").toFile(); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + protected void tearDown() throws Exception { |
| 45 | + try { |
| 46 | + FileUtils.deleteDirectory(buildDirectory); |
| 47 | + } finally { |
| 48 | + super.tearDown(); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + public void testEmptyPomEntryOverridesProjectVersion() throws Exception { |
| 53 | + MavenProject project = readProject(); |
| 54 | + AsciidocToPdfMojo mojo = (AsciidocToPdfMojo) lookupConfiguredMojo(project, "asciidoc-to-pdf"); |
| 55 | + assertPreparedLinks(mojo, ""); |
| 56 | + } |
| 57 | + |
| 58 | + public void testPomVersionsReachPreparedPdfSource() throws Exception { |
| 59 | + MavenProject project = readProject(); |
| 60 | + Xpp3Dom configuration = (Xpp3Dom) project.getBuildPlugins().get(0).getConfiguration(); |
| 61 | + Xpp3Dom versions = configuration.getChild("componentDocVersions"); |
| 62 | + versions.removeChild(versions.getChild("openam")); |
| 63 | + AsciidocToPdfMojo mojo = (AsciidocToPdfMojo) lookupConfiguredMojo(project, "asciidoc-to-pdf"); |
| 64 | + assertPreparedLinks(mojo, "15.2/"); |
| 65 | + } |
| 66 | + |
| 67 | + public void testMavenUserPropertySelectsHistoricalVersion() throws Exception { |
| 68 | + MavenProject project = readProject(); |
| 69 | + Xpp3Dom configuration = (Xpp3Dom) project.getBuildPlugins().get(0).getConfiguration(); |
| 70 | + configuration.removeChild(configuration.getChild("docVersion")); |
| 71 | + Xpp3Dom versions = configuration.getChild("componentDocVersions"); |
| 72 | + versions.removeChild(versions.getChild("openam")); |
| 73 | + MavenSession session = newMavenSession(project); |
| 74 | + session.getUserProperties().setProperty("docVersion", "15.2"); |
| 75 | + AsciidocToPdfMojo mojo = (AsciidocToPdfMojo) lookupConfiguredMojo(session, |
| 76 | + newMojoExecution("asciidoc-to-pdf")); |
| 77 | + assertPreparedLinks(mojo, "15.2/"); |
| 78 | + } |
| 79 | + |
| 80 | + private MavenProject readProject() throws Exception { |
| 81 | + File pom = getTestFile("src/test/resources/asciidoc-to-pdf/pom.xml"); |
| 82 | + try (Reader reader = Files.newBufferedReader(pom.toPath(), StandardCharsets.UTF_8)) { |
| 83 | + MavenProject project = new MavenProject(new MavenXpp3Reader().read(reader)); |
| 84 | + project.setFile(pom); |
| 85 | + project.getBuild().setDirectory(buildDirectory.getAbsolutePath()); |
| 86 | + return project; |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + private void assertPreparedLinks(AsciidocToPdfMojo mojo, String versionPrefix) throws Exception { |
| 91 | + FileUtils.writeStringToFile(new File(mojo.getAsciidocBuildSourceDirectory(), "how-to/page.adoc"), |
| 92 | + "xref:reference:page.adoc#a[A] xref:opendj::index.adoc[B]", StandardCharsets.UTF_8); |
| 93 | + mojo.execute(); |
| 94 | + assertThat(new File(mojo.getPdfSourceDirectory(), "how-to/page.adoc")).hasContent( |
| 95 | + "link:https://doc.openidentityplatform.org/openam/" + versionPrefix + "reference/page.html#a[A] " |
| 96 | + + "link:https://doc.openidentityplatform.org/opendj/4.10/index.html[B]"); |
| 97 | + } |
| 98 | +} |
0 commit comments