Skip to content

Commit

Permalink
Create REST-API tests
Browse files Browse the repository at this point in the history
  • Loading branch information
georgetarazevich committed Jan 10, 2024
1 parent 1f8d21a commit 6180fee
Show file tree
Hide file tree
Showing 99 changed files with 1,851 additions and 20 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/options-tests-with-docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Options tests with build rest:dev

on:
schedule:
- cron: "05 04 * * *"
push:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout the branch
uses: actions/checkout@v3

- name: Build and run Docker Image
run: |
docker build --build-arg GH_CHECKOUT=integration -t ghcr.io/verapdf/rest:dev . && docker run --user root -d -p 8080:8080 -p 8081:8081 -e VERAPDF_MAX_FILE_SIZE=1 -v /tmp:/home/Res_tmp ghcr.io/verapdf/rest:dev
echo whoami: $(docker inspect $(docker ps -q) --format '{{.Config.User}} {{.Name}}')
- name: Check Docker Container
run: |
docker images
docker ps
- name: Preparing Linux packages(Bats-core and more ...)
if: runner.os == 'Linux'
working-directory: ./tests
run: |
echo whoami: $(whoami)
mkdir ./results
sudo apt-get update -y
sudo apt install git -y
sudo apt-get install python3 -y
sudo apt-get install python3-pip -y
sudo pip install junit2html
echo $(pip list)
git --version
echo "Adding: bats-core.git, bats-support.git and bats-assert.git"
git clone https://github.com/bats-core/bats-core.git ./bats
git clone https://github.com/bats-core/bats-support.git ./bats-support
git clone https://github.com/bats-core/bats-assert.git ./bats-assert
./bats/bin/bats -v
- name: Running tests ... Options
working-directory: ./tests
run: |
echo pwd: $PWD
echo dir: $(ls ./)
./bats/bin/bats -r ./Options --show-output-of-passing-tests --print-output-on-failure --report-formatter junit --output ./results
- name: Generating report
if: always()
working-directory: ./tests/results
run: |
echo pwd: $PWD
junit2html report.xml --report-matrix report.html
- name: Uploading report
uses: actions/upload-artifact@v1
if: success() || failure()
with:
name: Results
path: "./tests/results"
46 changes: 46 additions & 0 deletions .github/workflows/rest-api-tests-with-ghcr-rest:dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Rest-api tests - ghcr.io/verapdf/rest:dev

on:
schedule:
- cron: "05 04 * * *"
push:

jobs:
test:
name: Rest-api tests running in Docker container
runs-on: ubuntu-latest
container: ubuntu
services:
verarest:
image: ghcr.io/verapdf/rest:dev
ports:
- 8080:8080
steps:
- uses: actions/checkout@v3

- name: Preparing Linux packages(Python and more ...)
if: runner.os == 'Linux'
run: |
echo pwd: $PWD
echo dir: $(ls ./)
apt-get update -y
apt-get install python3 -y
apt-get install python3-pip -y
pip install -r requirements.txt
echo $(pip list)
echo pwd: $PWD
- name: Running rest-api tests ...
run: |
mkdir ./results
echo dir: $(ls ./)
pytest --base_url=http://verarest:8080 --html=./results/report.html ./tests/
- name: Generating report
uses: actions/upload-artifact@v1
if: success() || failure()
with:
name: Results
path: "./results"
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,16 @@ bin/
# Ignore IDEA files
.idea/
*.iml

# Ignore pytest files
.pytest_cache

# Ignore external libraries
bats-assert/
bats-support/
verapdf/
*.pyc
*.log
*.html
*.css
*.code-workspace
11 changes: 11 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]

[requires]
python_version = "3.9"
20 changes: 20 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion kubernetes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ spec:
labels:
project: verapdf-rest
spec:
terminationGracePeriodSeconds: 300
containers:
- name : verapdf-rest
image: ghcr.io/verapdf/rest:dev
lifecycle:
preStop:
exec:
command: ["/bin/sleep", "300"]
resources:
requests:
cpu: "250m"
limits:
cpu: "250m"
cpu: "2000m"
ports:
- containerPort: 8080
name : rest-api-port
Expand Down
31 changes: 31 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
annotated-types==0.6.0
black==23.11.0
certifi==2023.7.22
charset-normalizer==3.3.2
click==8.1.7
exceptiongroup==1.1.3
idna==3.4
iniconfig==2.0.0
Jinja2==3.1.2
loguru==0.7.2
lxml==4.9.3
MarkupSafe==2.1.3
mypy-extensions==1.0.0
packaging==23.2
pathspec==0.11.2
platformdirs==3.11.0
pluggy==1.3.0
pydantic==2.4.2
pydantic-core==2.10.1
pydantic-xml==2.4.0
pydentic==0.0.1.dev3
pytest==7.4.3
pytest-html==4.1.1
pytest-metadata==3.0.0
python-stdnum==1.19
requests==2.31.0
soupsieve==2.5
tomli==2.0.1
typing-extensions==4.8.0
urllib3==2.0.7
xmltodict==0.13.0
12 changes: 6 additions & 6 deletions src/main/java/org/verapdf/rest/resources/ProfileResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static Set<PDFAFlavour> getFlavours() {
/**
* @param profileId
* the String id of the Validation profile (1b, 1a, 2b, 2a, 2u,
* 3b, 3a, 3u, 4, 4e, 4f or ua1)
* 3b, 3a, 3u, 4, 4e, 4f, ua1 or ua2)
* @return a validation profile selected by id
*/
@GET
Expand All @@ -108,15 +108,15 @@ public static Set<PDFAFlavour> getFlavours() {
)})})
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public static ValidationProfile getProfile(@Parameter(description = "the String id of the Validation profile " +
"(1b, 1a, 2b, 2a, 2u, 3b, 3a, 3u, 4, 4e, 4f or ua1)")
"(1b, 1a, 2b, 2a, 2u, 3b, 3a, 3u, 4, 4e, 4f, ua1 or ua2)")
@PathParam("profileId") String profileId) {
return DIRECTORY.getValidationProfileById(profileId);
}

/**
* @param profileId
* the String id of the Validation profile (1b, 1a, 2b, 2a, 2u,
* 3b, 3a, 3u, 4, 4e, 4f or ua1)
* 3b, 3a, 3u, 4, 4e, 4f, ua1 or ua2)
* @return the {@link java.util.Set} of
* {@link org.verapdf.pdfa.validation.profiles.RuleId}s for the selected
* Validation Profile
Expand All @@ -133,7 +133,7 @@ public static ValidationProfile getProfile(@Parameter(description = "the String
)})})
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public static Set<RuleId> getProfileRules(@Parameter(description = "the String id of the Validation profile " +
"(1b, 1a, 2b, 2a, 2u, 3b, 3a, 3u, 4, 4e, 4f or ua1)")
"(1b, 1a, 2b, 2a, 2u, 3b, 3a, 3u, 4, 4e, 4f, ua1 or ua2)")
@PathParam("profileId") String profileId) {
SortedSet<RuleId> ids = new TreeSet<>(new Profiles.RuleIdComparator());
for (Rule rule : DIRECTORY.getValidationProfileById(profileId).getRules()) {
Expand All @@ -145,7 +145,7 @@ public static Set<RuleId> getProfileRules(@Parameter(description = "the String i
/**
* @param profileId
* the String id of the Validation profile (1b, 1a, 2b, 2a, 2u,
* 3b, 3a, 3u, 4, 4e, 4f or ua1)
* 3b, 3a, 3u, 4, 4e, 4f, ua1 or ua2)
* @param clause
* a {@link java.lang.String} identifying the profile clause to
* return the Rules for
Expand All @@ -165,7 +165,7 @@ public static Set<RuleId> getProfileRules(@Parameter(description = "the String i
)})})
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public static Set<Rule> getRulesForClause(@Parameter(description = "the String id of the Validation profile " +
"(1b, 1a, 2b, 2a, 2u, 3b, 3a, 3u, 4, 4e, 4f or ua1)")
"(1b, 1a, 2b, 2a, 2u, 3b, 3a, 3u, 4, 4e, 4f, ua1 or ua2)")
@PathParam("profileId") String profileId,
@Parameter(description = "a string identifying the profile clause to return the rules for")
@PathParam("clause") String clause) {
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/org/verapdf/rest/resources/ValidateResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static ComponentDetails getDetails() {
* @param profileId
* the String id of the Validation profile
* (auto, 1b, 1a, 2b, 2a, 2u,
* 3b, 3a, 3u, 4, 4e, 4f or ua1)
* 3b, 3a, 3u, 4, 4e, 4f, ua1 or ua2)
* @param uploadedInputStream
* a {@link java.io.InputStream} to the PDF to
* be validated
Expand All @@ -108,7 +108,7 @@ public static ComponentDetails getDetails() {
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({MediaType.APPLICATION_XML})
public static InputStream validateXml(@Parameter(description = "the String id of the Validation profile " +
"(auto, 1b, 1a, 2b, 2a, 2u, 3b, 3a, 3u, 4, 4e, 4f or ua1)")
"(auto, 1b, 1a, 2b, 2a, 2u, 3b, 3a, 3u, 4, 4e, 4f, ua1 or ua2)")
@PathParam("profileId") String profileId,
@Parameter(name = "file", schema = @Schema(implementation = File.class),
style = ParameterStyle.FORM, description = "an InputStream of the PDF to be validated")
Expand All @@ -123,7 +123,7 @@ public static InputStream validateXml(@Parameter(description = "the String id of
* @param profileId
* the String id of the Validation profile
* (auto, 1b, 1a, 2b, 2a, 2u,
* 3b, 3a, 3u, 4, 4e, 4f or ua1)
* 3b, 3a, 3u, 4, 4e, 4f, ua1 or ua2)
* @param sha1Hex
* the hex String representation of the file's
* SHA-1 hash
Expand All @@ -149,7 +149,7 @@ public static InputStream validateXml(@Parameter(description = "the String id of
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({MediaType.APPLICATION_XML})
public static InputStream validateXml(@Parameter(description = "the String id of the Validation profile " +
"(auto, 1b, 1a, 2b, 2a, 2u, 3b, 3a, 3u, 4, 4e, 4f or ua1)")
"(auto, 1b, 1a, 2b, 2a, 2u, 3b, 3a, 3u, 4, 4e, 4f, ua1 or ua2)")
@PathParam("profileId") String profileId,
@Parameter(description = "the hex String representation of the file's SHA-1 hash")
@FormDataParam("sha1Hex") String sha1Hex,
Expand Down Expand Up @@ -177,7 +177,7 @@ public static InputStream validateXml(@Parameter(description = "the String id of
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({MediaType.APPLICATION_XML})
public static InputStream validateXml(@Parameter(description = "the String id of the Validation profile " +
"(auto, 1b, 1a, 2b, 2a, 2u, 3b, 3a, 3u, 4, 4e, 4f or ua1)")
"(auto, 1b, 1a, 2b, 2a, 2u, 3b, 3a, 3u, 4, 4e, 4f, ua1 or ua2)")
@PathParam("profileId") String profileId,
@Parameter(description = "a URL of PDF to be validated")
@FormDataParam("url") String urlLink,
Expand All @@ -190,7 +190,7 @@ public static InputStream validateXml(@Parameter(description = "the String id of
* @param profileId
* the String id of the Validation profile
* (auto, 1b, 1a, 2b, 2a, 2u,
* 3b, 3a, 3u, 4, 4e, 4f or ua1)
* 3b, 3a, 3u, 4, 4e, 4f, ua1 or ua2)
* @param uploadedInputStream
* a {@link java.io.InputStream} to the PDF to
* be validated
Expand All @@ -203,7 +203,7 @@ public static InputStream validateXml(@Parameter(description = "the String id of
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({MediaType.APPLICATION_JSON})
public static InputStream validateJson(@Parameter(description = "the String id of the Validation profile " +
"(auto, 1b, 1a, 2b, 2a, 2u, 3b, 3a, 3u, 4, 4e, 4f or ua1)")
"(auto, 1b, 1a, 2b, 2a, 2u, 3b, 3a, 3u, 4, 4e, 4f, ua1 or ua2)")
@PathParam("profileId") String profileId,
@Parameter(name = "file", schema = @Schema(implementation = File.class),
style = ParameterStyle.FORM, description = "an InputStream of the PDF to be validated")
Expand All @@ -218,7 +218,7 @@ public static InputStream validateJson(@Parameter(description = "the String id o
* @param profileId
* the String id of the Validation profile
* (auto, 1b, 1a, 2b, 2a, 2u,
* 3b, 3a, 3u, 4, 4e, 4f or ua1)
* 3b, 3a, 3u, 4, 4e, 4f, ua1 or ua2)
* @param sha1Hex
* the hex String representation of the file's
* SHA-1 hash
Expand All @@ -234,7 +234,7 @@ public static InputStream validateJson(@Parameter(description = "the String id o
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({MediaType.APPLICATION_JSON})
public static InputStream validateJson(@Parameter(description = "the String id of the Validation profile " +
"(auto, 1b, 1a, 2b, 2a, 2u, 3b, 3a, 3u, 4, 4e, 4f or ua1)")
"(auto, 1b, 1a, 2b, 2a, 2u, 3b, 3a, 3u, 4, 4e, 4f, ua1 or ua2)")
@PathParam("profileId") String profileId,
@Parameter(description = "the hex String representation of the file's SHA-1 hash")
@FormDataParam("sha1Hex") String sha1Hex,
Expand All @@ -253,7 +253,7 @@ public static InputStream validateJson(@Parameter(description = "the String id o
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({MediaType.APPLICATION_JSON})
public static InputStream validateJson(@Parameter(description = "the String id of the Validation profile " +
"(auto, 1b, 1a, 2b, 2a, 2u, 3b, 3a, 3u, 4, 4e, 4f or ua1)")
"(auto, 1b, 1a, 2b, 2a, 2u, 3b, 3a, 3u, 4, 4e, 4f, ua1 or ua2)")
@PathParam("profileId") String profileId,
@Parameter(description = "a URL of PDF to be validated")
@FormDataParam("url") String urlLink,
Expand All @@ -266,7 +266,7 @@ public static InputStream validateJson(@Parameter(description = "the String id o
* @param profileId
* the String id of the Validation profile
* (auto, 1b, 1a, 2b, 2a, 2u,
* 3b, 3a, 3u, 4, 4e, 4f or ua1)
* 3b, 3a, 3u, 4, 4e, 4f, ua1 or ua2)
* @param uploadedInputStream
* a {@link java.io.InputStream} to the PDF to
* be validated
Expand All @@ -291,7 +291,7 @@ public static InputStream validateHtml(@PathParam("profileId") String profileId,
* @param profileId
* the String id of the Validation profile
* (auto, 1b, 1a, 2b, 2a, 2u,
* 3b, 3a, 3u, 4, 4e, 4f or ua1)
* 3b, 3a, 3u, 4, 4e, 4f, ua1 or ua2)
* @param sha1Hex
* the hex String representation of the file's
* SHA-1 hash
Expand Down Expand Up @@ -322,7 +322,7 @@ public static InputStream validateHtml(@PathParam("profileId") String profileId,
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({MediaType.TEXT_HTML})
public static InputStream validateHtml(@Parameter(description = "the String id of the Validation profile " +
"(auto, 1b, 1a, 2b, 2a, 2u, 3b, 3a, 3u, 4, 4e, 4f or ua1)")
"(auto, 1b, 1a, 2b, 2a, 2u, 3b, 3a, 3u, 4, 4e, 4f, ua1 or ua2)")
@PathParam("profileId") String profileId,
@Parameter(description = "a URL of PDF to be validated")
@FormDataParam("url") String urlLink,
Expand Down
Loading

0 comments on commit 6180fee

Please sign in to comment.