View Javadoc
1   package de.dlr.shepard.integrationtests;
2   
3   import static io.restassured.RestAssured.given;
4   import static org.assertj.core.api.Assertions.assertThat;
5   
6   import de.dlr.shepard.context.collection.io.CollectionIO;
7   import io.quarkus.test.junit.QuarkusIntegrationTest;
8   import io.restassured.builder.RequestSpecBuilder;
9   import io.restassured.http.ContentType;
10  import io.restassured.specification.RequestSpecification;
11  import org.junit.jupiter.api.BeforeAll;
12  import org.junit.jupiter.api.Disabled;
13  import org.junit.jupiter.api.Test;
14  
15  /**
16   * This Integration test should check basic capabilities of our API, like responding 404 for undefined paths.
17   */
18  @QuarkusIntegrationTest
19  public class BasicApiIT extends BaseTestCaseIT {
20  
21    private static RequestSpecification requestSpecificationWithoutUser;
22  
23    @BeforeAll
24    public static void setUp() {
25      requestSpecificationWithoutUser = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
26    }
27  
28    @Test
29    public void getIndexRoute_notFound() {
30      given().spec(requestSpecificationWithoutUser).when().get("/").then().statusCode(404);
31      given().spec(requestSpecOfDefaultUser).when().get("/").then().statusCode(404);
32    }
33  
34    @Test
35    public void getCollections_pathsWithExtraSlashes_success() {
36      var responseWithCleanPath = given()
37        .spec(requestSpecOfDefaultUser)
38        .when()
39        .get("/collections")
40        .then()
41        .statusCode(200)
42        .extract()
43        .as(CollectionIO[].class);
44      var responseWithExtraSlash = given()
45        .spec(requestSpecOfDefaultUser)
46        .when()
47        .get("/collections/")
48        .then()
49        .statusCode(200)
50        .extract()
51        .as(CollectionIO[].class);
52  
53      assertThat(responseWithExtraSlash).isEqualTo(responseWithCleanPath);
54    }
55  
56    @Test
57    public void getCollections_twoLeadingSlashes_notFound() {
58      given().spec(requestSpecOfDefaultUser).when().get("//collections").then().statusCode(404);
59    }
60  
61    @Test
62    @Disabled
63    public void getCollectionTest_invalidId_badRequest() {
64      given().spec(requestSpecOfDefaultUser).when().get("/collections/-1").then().statusCode(400);
65      given().spec(requestSpecOfDefaultUser).when().get("/collections/abc").then().statusCode(400);
66    }
67  }