Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ repos:
- id: end-of-file-fixer
- id: check-yaml
- id: check-json
exclude: ^src/test/resources/malformed\.json$
- id: check-xml
- id: check-added-large-files
- repo: local
Expand Down
71 changes: 71 additions & 0 deletions src/test/java/ch/psi/ord/api/ValidateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.hamcrest.Matchers.is;

import io.quarkus.test.junit.QuarkusTest;
import jakarta.ws.rs.core.MediaType;
import java.io.IOException;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -222,4 +223,74 @@ public void test09() throws IOException {
.body("errors[0]", hasEntry("message", "No suitable entity found in the graph"))
.body("errors[0]", hasEntry("type", "NoEntityFound"));
}

@Test
@DisplayName("Malformed metadata descriptor (JSON-LD)")
public void test10() throws IOException {
given()
.when()
.header("Content-Type", ExtraMediaType.APPLICATION_JSONLD)
.body(getClass().getClassLoader().getResourceAsStream("malformed.json").readAllBytes())
.post("/ro-crate/validate")
.then()
.statusCode(400)
.contentType(is(CONTENT_TYPE_JSON_RES))
.body(is("Failed to parse the metadata descriptor"));
}

@Test
@DisplayName("Malformed metadata descriptor (ZIP)")
public void test11() throws IOException {
given()
.when()
.header("Content-Type", ExtraMediaType.APPLICATION_ZIP)
.body(zipResource("malformed.json"))
.post("/ro-crate/validate")
.then()
.statusCode(400)
.contentType(is(CONTENT_TYPE_JSON_RES))
.body(is("Failed to parse the metadata descriptor"));
}

@Test
@DisplayName("Malformed zip archive (ZIP)")
public void test12() throws IOException {
given()
.when()
.header("Content-Type", ExtraMediaType.APPLICATION_ZIP)
.body(new byte[0])
.post("/ro-crate/validate")
.then()
.statusCode(400)
.contentType(is(CONTENT_TYPE_JSON_RES))
.body(is("Invalid or empty zip archive"));
}

@Test
@DisplayName("Invalid Accept header (JSON-LD)")
public void test13() throws IOException {
given()
.when()
.accept(MediaType.APPLICATION_XML)
.header("Content-Type", ExtraMediaType.APPLICATION_JSONLD)
.post("/ro-crate/validate")
.then()
.statusCode(406)
.contentType(is(CONTENT_TYPE_JSON_RES))
.body(is("Failed to parse the metadata descriptor"));
}

@Test
@DisplayName("Invalid Accept header (ZIP)")
public void test14() throws IOException {
given()
.when()
.accept(MediaType.APPLICATION_XML)
.header("Content-Type", ExtraMediaType.APPLICATION_ZIP)
.post("/ro-crate/validate")
.then()
.statusCode(406)
.contentType(is(CONTENT_TYPE_JSON_RES))
.body(is("Failed to parse the metadata descriptor"));
}
}
1 change: 1 addition & 0 deletions src/test/resources/malformed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{
Loading