Search in sources :

Example 26 with ValidatableResponse

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

the class RestControllerV2APIIT method testGetI18nStrings.

@Test
public void testGetI18nStrings() {
    ValidatableResponse response = given().log().all().header(X_MOLGENIS_TOKEN, testUserToken).get(API_V2 + "i18n").then().log().all();
    validateGetI18nStrings(response);
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) Test(org.testng.annotations.Test)

Example 27 with ValidatableResponse

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

the class RestControllerV2APIIT method testRetrieveEntityExcludingCategoriesResultsInNoCategoricalOptions.

@Test
public void testRetrieveEntityExcludingCategoriesResultsInNoCategoricalOptions() {
    ValidatableResponse response = given().log().all().header(X_MOLGENIS_TOKEN, testUserToken).param("includeCategories", newArrayList("false")).param("attrs", newArrayList("xcategorical_value")).get(API_V2 + "V2_API_TypeTestAPIV2/1").then().log().all();
    response.statusCode(OKE);
    response.body("_meta.attributes[0].categoricalOptions", Matchers.nullValue());
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) Test(org.testng.annotations.Test)

Example 28 with ValidatableResponse

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

the class RestControllerV2APIIT method testRetrieveEntityWithAttributeFilter.

@Test
public void testRetrieveEntityWithAttributeFilter() {
    ValidatableResponse response = given().log().all().header(X_MOLGENIS_TOKEN, testUserToken).param("attrs", newArrayList("label")).get(API_V2 + "V2_API_TypeTestRefAPIV2/ref1").then().log().all();
    validateRetrieveEntityWithAttributeFilter(response);
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) Test(org.testng.annotations.Test)

Example 29 with ValidatableResponse

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

the class RestControllerV2APIIT method testRetrieveEntity.

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

Example 30 with ValidatableResponse

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

the class OneClickImporterControllerAPIIT method oneClickImportTest.

private void oneClickImportTest(String fileToImport) throws URISyntaxException, IOException {
    URL resourceUrl = getResource(RestControllerV2APIIT.class, fileToImport);
    File file = new File(new URI(resourceUrl.toString()).getPath());
    // Post the file to be imported
    ValidatableResponse response = given().log().all().header(X_MOLGENIS_TOKEN, testUserToken).multiPart(file).post(OneClickImporterController.URI + "/upload").then().log().all().statusCode(OKE);
    // Verify the post returns a job url
    String jobUrl = ((ValidatableResponseImpl) response).originalResponse().asString();
    assertTrue(jobUrl.startsWith("/api/v2/sys_job_OneClickImportJobExecution/"));
    String jobStatus = given().log().all().header(X_MOLGENIS_TOKEN, testUserToken).get(jobUrl).then().statusCode(OKE).extract().path("status");
    List<String> validJobStats = Arrays.asList("PENDING", "RUNNING", "SUCCESS");
    assertTrue(validJobStats.contains(jobStatus));
    await().pollDelay(500, MILLISECONDS).atMost(3, MINUTES).until(() -> pollJobForStatus(jobUrl), not(is("PENDING")));
    await().pollDelay(500, MILLISECONDS).atMost(10, SECONDS).until(() -> pollJobForStatus(jobUrl), is("SUCCESS"));
    // Extract the id of the entity created by the import
    ValidatableResponse completedJobResponse = given().log().all().header(X_MOLGENIS_TOKEN, testUserToken).get(jobUrl).then().statusCode(OKE);
    JsonArray entityTypeId = new Gson().fromJson(completedJobResponse.extract().jsonPath().get("entityTypes").toString(), JsonArray.class);
    String entityId = entityTypeId.get(0).getAsJsonObject().get("id").getAsString();
    String packageName = completedJobResponse.extract().path("package");
    String jobId = completedJobResponse.extract().path("identifier");
    // Store to use during cleanup
    importedEntities.add(entityId);
    importPackages.add(packageName);
    importJobIds.add(jobId);
    // Get the entity value to check the import
    ValidatableResponse entityResponse = given().log().all().header(X_MOLGENIS_TOKEN, testUserToken).get(API_V2 + entityId + "?attrs=~id,first_name,last_name,full_name,UMCG_employee,Age").then().log().all();
    entityResponse.statusCode(OKE);
    JSONAssert.assertEquals(Files.readFile(getClass().getResourceAsStream("users.json")), entityResponse.extract().body().asString(), false);
}
Also used : JsonArray(com.google.gson.JsonArray) ValidatableResponse(io.restassured.response.ValidatableResponse) Gson(com.google.gson.Gson) File(java.io.File) URI(java.net.URI) RestAssured.baseURI(io.restassured.RestAssured.baseURI) URL(java.net.URL)

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