Search in sources :

Example 16 with ValidatableResponse

use of io.restassured.response.ValidatableResponse in project molgenis by molgenis.

the class RestControllerV2APIIT method testRetrieveEntityPost.

@Test
public void testRetrieveEntityPost() {
    ValidatableResponse response = given().log().all().header(X_MOLGENIS_TOKEN, testUserToken).post(API_V2 + "V2_API_TypeTestRefAPIV2/ref1?_method=GET").then().log().all();
    validateRetrieveEntityWithoutAttributeFilter(response);
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) Test(org.testng.annotations.Test)

Example 17 with ValidatableResponse

use of io.restassured.response.ValidatableResponse in project molgenis by molgenis.

the class RestControllerV2APIIT method testRetrieveEntityAttributeMeta.

@Test
public void testRetrieveEntityAttributeMeta() {
    ValidatableResponse response = given().log().all().header(X_MOLGENIS_TOKEN, testUserToken).get(API_V2 + "V2_API_TypeTestRefAPIV2/meta/value").then().log().all();
    validateRetrieveEntityAttributeMeta(response);
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) Test(org.testng.annotations.Test)

Example 18 with ValidatableResponse

use of io.restassured.response.ValidatableResponse in project molgenis by molgenis.

the class TwoFactorAuthenticationAPIIT method test2faEnabled.

@Test
public void test2faEnabled() {
    toggle2fa(this.adminToken, TwoFactorAuthenticationSetting.ENABLED);
    Gson gson = new Gson();
    Map<String, String> loginBody = new HashMap<>();
    loginBody.put("username", testUserName);
    loginBody.put("password", TWO_FA_AUTH_TEST_USER_PASSWORD);
    ValidatableResponse response = given().contentType(APPLICATION_JSON).body(gson.toJson(loginBody)).when().post(PATH + "login").then().statusCode(OKE);
    testUserToken = response.extract().path("token");
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) Test(org.testng.annotations.Test)

Example 19 with ValidatableResponse

use of io.restassured.response.ValidatableResponse in project okapi by folio-org.

the class ModuleTest method testNotFound.

@Test
public void testNotFound(TestContext context) {
    async = context.async();
    Response r;
    ValidatableResponse then;
    final String docTenantRoskilde = "{" + LS + "  \"id\" : \"" + okapiTenant + "\"," + LS + "  \"name\" : \"" + okapiTenant + "\"," + LS + "  \"description\" : \"Roskilde bibliotek\"" + LS + "}";
    r = given().header("Content-Type", "application/json").body(docTenantRoskilde).post("/_/proxy/tenants").then().statusCode(201).body(equalTo(docTenantRoskilde)).extract().response();
    final String locationTenantRoskilde = r.getHeader("Location");
    final String docLaunch1 = "{" + LS + "  \"srvcId\" : \"sample-module-1\"," + LS + "  \"nodeId\" : \"localhost\"," + LS + "  \"descriptor\" : {" + LS + "    \"exec\" : " + "\"java -Dport=%p -jar ../okapi-test-module/target/okapi-test-module-fat.jar\"" + LS + "  }" + LS + "}";
    r = given().header("Content-Type", "application/json").body(docLaunch1).post("/_/discovery/modules").then().statusCode(201).extract().response();
    locationSampleDeployment = r.getHeader("Location");
    for (String type : Arrays.asList("request-response", "request-only", "headers")) {
        final String docSampleModule = "{" + LS + "  \"id\" : \"sample-module-1\"," + LS + "  \"filters\" : [ {" + LS + "    \"methods\" : [ \"GET\", \"POST\" ]," + LS + "    \"path\" : \"/test2\"," + LS + "    \"level\" : \"20\"," + LS + "    \"type\" : \"" + type + "\"" + LS + "  } ]" + LS + "}";
        r = given().header("Content-Type", "application/json").body(docSampleModule).post("/_/proxy/modules").then().statusCode(201).extract().response();
        final String locationSampleModule = r.getHeader("Location");
        final String docEnableSample = "{" + LS + "  \"id\" : \"sample-module-1\"" + LS + "}";
        r = given().header("Content-Type", "application/json").body(docEnableSample).post("/_/proxy/tenants/" + okapiTenant + "/modules").then().statusCode(201).body(equalTo(docEnableSample)).extract().response();
        final String enableLoc = r.getHeader("Location");
        given().header("X-Okapi-Tenant", okapiTenant).body("bar").post("/test2").then().statusCode(404);
        given().delete(enableLoc).then().statusCode(204);
        given().delete(locationSampleModule).then().statusCode(204);
    }
    given().delete(locationSampleDeployment).then().statusCode(204);
    locationSampleDeployment = null;
    given().delete(locationTenantRoskilde).then().statusCode(204);
    async.complete();
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) Response(io.restassured.response.Response) ValidatableResponse(io.restassured.response.ValidatableResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 20 with ValidatableResponse

use of io.restassured.response.ValidatableResponse in project okapi by folio-org.

the class ModuleTest method testHeader.

@Test
public void testHeader(TestContext context) {
    async = context.async();
    Response r;
    ValidatableResponse then;
    final String docLaunch1 = "{" + LS + "  \"srvcId\" : \"sample-module-5\"," + LS + "  \"nodeId\" : \"localhost\"," + LS + "  \"descriptor\" : {" + LS + "    \"exec\" : " + "\"java -Dport=%p -jar ../okapi-test-module/target/okapi-test-module-fat.jar\"" + LS + "  }" + LS + "}";
    r = given().header("Content-Type", "application/json").body(docLaunch1).post("/_/discovery/modules").then().statusCode(201).extract().response();
    locationSampleDeployment = r.getHeader("Location");
    final String docLaunch2 = "{" + LS + "  \"srvcId\" : \"header-module-1\"," + LS + "  \"nodeId\" : \"localhost\"," + LS + "  \"descriptor\" : {" + LS + "    \"exec\" : " + "\"java -Dport=%p -jar ../okapi-test-header-module/target/okapi-test-header-module-fat.jar\"" + LS + "  }" + LS + "}";
    r = given().header("Content-Type", "application/json").body(docLaunch2).post("/_/discovery/modules").then().statusCode(201).extract().response();
    locationHeaderDeployment = r.getHeader("Location");
    final String docSampleModule = "{" + LS + "  \"id\" : \"sample-module-5\"," + LS + "  \"filters\" : [ {" + LS + "    \"methods\" : [ \"GET\", \"POST\" ]," + LS + "    \"path\" : \"/testb\"," + LS + "    \"level\" : \"20\"," + LS + "    \"type\" : \"request-response\"" + LS + "  } ]" + LS + "}";
    r = given().header("Content-Type", "application/json").body(docSampleModule).post("/_/proxy/modules").then().statusCode(201).extract().response();
    final String locationSampleModule = r.getHeader("Location");
    final String docHeaderModule = "{" + LS + "  \"id\" : \"header-module-1\"," + LS + "  \"filters\" : [ {" + LS + "    \"methods\" : [ \"GET\", \"POST\" ]," + LS + "    \"path\" : \"/testb\"," + LS + "    \"level\" : \"10\"," + LS + "    \"type\" : \"headers\"" + LS + "  } ]" + LS + "}";
    r = given().header("Content-Type", "application/json").body(docHeaderModule).post("/_/proxy/modules").then().statusCode(201).extract().response();
    final String locationHeaderModule = r.getHeader("Location");
    final String docTenantRoskilde = "{" + LS + "  \"id\" : \"" + okapiTenant + "\"," + LS + "  \"name\" : \"" + okapiTenant + "\"," + LS + "  \"description\" : \"Roskilde bibliotek\"" + LS + "}";
    r = given().header("Content-Type", "application/json").body(docTenantRoskilde).post("/_/proxy/tenants").then().statusCode(201).body(equalTo(docTenantRoskilde)).extract().response();
    final String locationTenantRoskilde = r.getHeader("Location");
    final String docEnableSample = "{" + LS + "  \"id\" : \"sample-module-5\"" + LS + "}";
    given().header("Content-Type", "application/json").body(docEnableSample).post("/_/proxy/tenants/" + okapiTenant + "/modules").then().statusCode(201).body(equalTo(docEnableSample));
    final String docEnableHeader = "{" + LS + "  \"id\" : \"header-module-1\"" + LS + "}";
    given().header("Content-Type", "application/json").body(docEnableHeader).post("/_/proxy/tenants/" + okapiTenant + "/modules").then().statusCode(201).body(equalTo(docEnableHeader));
    given().header("X-Okapi-Tenant", okapiTenant).body("bar").post("/testb").then().statusCode(200).body(equalTo("Hello foobar")).extract().response();
    given().delete("/_/proxy/tenants/" + okapiTenant + "/modules/sample-module-5").then().statusCode(204);
    given().delete(locationSampleModule).then().statusCode(204);
    final String docSampleModule2 = "{" + LS + "  \"id\" : \"sample-module-5\"," + LS + "  \"filters\" : [ {" + LS + "    \"methods\" : [ \"GET\", \"POST\" ]," + LS + "    \"path\" : \"/testb\"," + LS + "    \"level\" : \"5\"," + LS + "    \"type\" : \"request-response\"" + LS + "  } ]" + LS + "}";
    given().header("Content-Type", "application/json").body(docSampleModule2).post("/_/proxy/modules").then().statusCode(201).extract().response();
    final String locationSampleModule2 = r.getHeader("Location");
    given().header("Content-Type", "application/json").body(docEnableSample).post("/_/proxy/tenants/" + okapiTenant + "/modules").then().statusCode(201).body(equalTo(docEnableSample));
    given().header("X-Okapi-Tenant", okapiTenant).body("bar").post("/testb").then().statusCode(200).body(equalTo("Hello foobar")).extract().response();
    logger.debug("testHeader cleaning up");
    given().delete(locationTenantRoskilde).then().statusCode(204);
    given().delete(locationSampleModule).then().statusCode(204);
    given().delete(locationSampleDeployment).then().statusCode(204);
    locationSampleDeployment = null;
    given().delete(locationHeaderDeployment).then().statusCode(204);
    locationHeaderDeployment = null;
    given().delete(locationHeaderModule).then().statusCode(204);
    checkDbIsEmpty("testHeader done", context);
    async.complete();
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) Response(io.restassured.response.Response) ValidatableResponse(io.restassured.response.ValidatableResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

ValidatableResponse (io.restassured.response.ValidatableResponse)33 Test (org.testng.annotations.Test)24 File (java.io.File)4 Path (java.nio.file.Path)3 EntityTypeRequest (org.molgenis.data.rest.EntityTypeRequest)3 Gson (com.google.gson.Gson)2 Response (io.restassured.response.Response)2 URL (java.net.URL)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Test (org.junit.Test)2 EntityCollectionRequest (org.molgenis.data.rest.EntityCollectionRequest)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ProcessingException (com.github.fge.jsonschema.core.exceptions.ProcessingException)1 JsonArray (com.google.gson.JsonArray)1 Param (de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.config.Param)1 RestAssured.baseURI (io.restassured.RestAssured.baseURI)1 RequestSpecification (io.restassured.specification.RequestSpecification)1 IOException (java.io.IOException)1