Skip to content

Commit

Permalink
adds integration tests (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
codyfrehr committed Feb 25, 2024
1 parent 31a0127 commit 3fb7729
Show file tree
Hide file tree
Showing 21 changed files with 571 additions and 18 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ permissions:
jobs:
build-test-install:
name: Build, Test, and Install
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Setup JDK 8
uses: actions/setup-java@v4
Expand All @@ -26,6 +29,8 @@ jobs:
run: ./mvnw clean compile
- name: Test
run: ./mvnw test
- name: Integration Test
run: ./mvnw verify -DskipUTs=true
- name: License Check
run: ./mvnw license:check
- name: Install
Expand Down
8 changes: 7 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
= Xpdf API image:https://github.com/codyfrehr/xpdf-api/actions/workflows/ci.yml/badge.svg?event=push&branch=main[]
= Xpdf API
//TODO: look at other readme with .adoc structure, and see what other ways there are to format this. for example, spring boot has tabs for "Security" and "Code of Conduct" - pretty cool!
//TODO: add badge for maven https://search.maven.org/artifact/org.apache.commons/commons-lang3/3.14.0/jar?eh=
//TODO: add badge for javadocs https://javadoc.io/
//TODO: add badge for code coverage?
//TODO: add badge for codeQL?

image::https://github.com/codyfrehr/xpdf-api/actions/workflows/ci.yml/badge.svg?event=push&branch=main[]

Xpdf API is a collection of Java APIs for https://www.xpdfreader.com/about.html[Xpdf], the open source library for operating on PDF files written in C++.
Xpdf is an invaluable PDF toolkit, and this project aims to make it more accessible to the Java community.
Expand Down
5 changes: 3 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
- should make use of the term "RICH text" or "rich PDF" in your javadocs and readme, and make a special note about how this only works on PDF files with RICH TEXT
- test all code examples from readme and javadocs to ensure they are working!
- figure out how to get github pipeline to run 32-bit architecture (might need to use docker containers...)
- update github project "About" section, and other general settings for the repo
- setup namecheap xpdf.io domain to automatically redirect to github repo, until website built https://www.namecheap.com/support/knowledgebase/article.aspx/385/2237/how-to-set-up-a-url-redirect-for-a-domain/
but first, need to get hosting for site and install ssl cert
- request derek to add link to your library on their webpage
- reorganize SCRIBBLES into official supporting documents
- write CONTRIBUTING (is this standard name for developer instructions to contribute? DEVELOPERS seems like a better name for file maybe?)
- what other files?
- setup coverage check in pipeline
- setup cucumber integration tests
- setup coverage check in pipeline and codeQL check
- add CVE check to pipeline
- set up github issue management
- fix broken github links on resume and website
- figure out process to deploy to maven central repo
Expand Down
14 changes: 7 additions & 7 deletions common-api/src/main/java/io/xpdf/api/common/util/XpdfUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class XpdfUtils {
* @return executable resource name
* @since 1.0.0
*/
static public String getPdfTextExecutableResourceName() {
public static String getPdfTextExecutableResourceName() {
return String.format("xpdf/%s/%s", getTargetSystem(), getPdfTextExecutableName());
}

Expand All @@ -46,7 +46,7 @@ static public String getPdfTextExecutableResourceName() {
* @return executable path
* @since 1.0.0
*/
static public Path getPdfTextExecutablePath() {
public static Path getPdfTextExecutablePath() {
return getXpdfTempPath().resolve("pdf-text").resolve("bin").resolve(getPdfTextExecutableName());
}

Expand All @@ -56,7 +56,7 @@ static public Path getPdfTextExecutablePath() {
* @return temporary directory
* @since 1.0.0
*/
static public Path getPdfTextTempOutputPath() {
public static Path getPdfTextTempOutputPath() {
return getXpdfTempPath().resolve("pdf-text").resolve("out");
}

Expand All @@ -66,7 +66,7 @@ static public Path getPdfTextTempOutputPath() {
* @return timeout length in seconds for process
* @since 1.0.0
*/
static public Integer getPdfTextTimeoutSeconds() {
public static Integer getPdfTextTimeoutSeconds() {
return 30;
}

Expand All @@ -75,7 +75,7 @@ static public Integer getPdfTextTimeoutSeconds() {
*
* @return executable name
*/
static protected String getPdfTextExecutableName() {
protected static String getPdfTextExecutableName() {
return String.format("pdftotext%s", getTargetSystem().contains("windows") ? ".exe" : "");
}

Expand All @@ -84,7 +84,7 @@ static protected String getPdfTextExecutableName() {
*
* @return temporary directory
*/
static protected Path getXpdfTempPath() {
protected static Path getXpdfTempPath() {
return Paths.get(System.getProperty("java.io.tmpdir")).resolve( "xpdf-api");
}

Expand All @@ -94,7 +94,7 @@ static protected Path getXpdfTempPath() {
*
* @return representation of OS and bits
*/
static protected String getTargetSystem() {
protected static String getTargetSystem() {
// get JVM bit architecture
val bit = System.getProperty("sun.arch.data.model");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class PdfTextToolAutoConfigurationTest {
// given
val executableFile = mockk<File> {
every { exists() } returns true
every { setExecutable(any()) } returns true
}
val executablePath = mockk<Path> {
every { toFile() } returns executableFile
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* PdfText API Starter - A Spring Boot starter for PdfText API.
* Copyright © 2024 xpdf.io (info@xpdf.io)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.xpdf.api.pdftext.autoconfigure

import io.xpdf.api.pdftext.PdfTextTool
import org.springframework.boot.test.context.TestConfiguration
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ComponentScan

@TestConfiguration
@ComponentScan
open class PdfTextToolTestConfig {

@Bean
open fun pdfTextTool(): PdfTextTool = PdfTextTool.builder().build()

}
12 changes: 12 additions & 0 deletions pdf-text-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,22 @@
<inceptionYear>2024</inceptionYear>

<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
</dependency>
<dependency>
<groupId>io.xpdf</groupId>
<artifactId>common-api</artifactId>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-engine</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
10 changes: 8 additions & 2 deletions pdf-text-api/src/main/java/io/xpdf/api/pdftext/PdfTextTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,17 @@ protected File configureExecutableFile() {
throw new XpdfRuntimeException("Unable to copy executable from resources to local system");
}
}
if (!executablePath.toFile().setExecutable(true)) {
throw new XpdfRuntimeException("Unable to set execute permissions on executable");
}
return executablePath.toFile();
} else {
if (!executableFile.exists()) {
throw new XpdfRuntimeException("The configured executable does not exist");
}
if (!executableFile.setExecutable(true)) {
throw new XpdfRuntimeException("Unable to set execute permissions on executable");
}
return executableFile;
}
}
Expand Down Expand Up @@ -168,8 +174,8 @@ public PdfTextResponse process(PdfTextRequest request) throws XpdfException {

// wait for process finish
if (process.waitFor(timeoutSeconds, TimeUnit.SECONDS)) {
val standardOutput = IOUtils.toString(process.getInputStream(), Charset.defaultCharset());
val errorOutput = IOUtils.toString(process.getErrorStream(), Charset.defaultCharset());
val standardOutput = StringUtils.trimToNull(IOUtils.toString(process.getInputStream(), Charset.defaultCharset()));
val errorOutput = StringUtils.trimToNull(IOUtils.toString(process.getErrorStream(), Charset.defaultCharset()));
log.debug("Invocation completed; exit code: {}, standard output: {}", process.exitValue(), standardOutput);

// handle process finished
Expand Down
Empty file modified pdf-text-api/src/main/resources/xpdf/linux/bin32/pdftotext
100644 → 100755
Empty file.
Empty file modified pdf-text-api/src/main/resources/xpdf/linux/bin64/pdftotext
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* PdfText API - An API for accessing a native pdftotext library.
* Copyright © 2024 xpdf.io (info@xpdf.io)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.xpdf.api.pdftext

import io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME
import org.junit.platform.suite.api.ConfigurationParameter
import org.junit.platform.suite.api.SelectClasspathResource
import org.junit.platform.suite.api.Suite

@Suite
@SelectClasspathResource("io/xpdf/api/pdftext")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "io.xpdf.api.pdftext" )
class PdfTextToolCucumberIT

0 comments on commit 3fb7729

Please sign in to comment.