Search in sources :

Example 6 with ApiResponse

use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.

the class OptionSetTests method shouldRemoveOptions.

@Test
public void shouldRemoveOptions() {
    // arrange
    createOption(createdOptionSet);
    ApiResponse response = optionActions.optionSetActions.get(createdOptionSet);
    JsonObject object = response.getBody();
    object.remove("options");
    // act
    response = optionActions.optionSetActions.update(createdOptionSet, object);
    response.validate().statusCode(200);
    // assert
    response = optionActions.optionSetActions.get(createdOptionSet);
    response.validate().statusCode(200).body("options", hasSize(0));
}
Also used : JsonObject(com.google.gson.JsonObject) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Example 7 with ApiResponse

use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.

the class MetadataImportBasedOnSchemasTest method postBasedOnSchema.

@ParameterizedTest
@MethodSource("getSchemaEndpoints")
public void postBasedOnSchema(String endpoint, String schema) {
    RestApiActions apiActions = new RestApiActions(endpoint);
    List<String> blacklistedEndpoints = Arrays.asList("jobConfigurations", "relationshipTypes", "messageConversations", "users", "organisationUnitLevels", "programRuleActions", "programRuleVariables", "eventCharts", // blacklisted because contains
    "programStages");
    // conditionally required properties, which
    // are not marked as required
    List<SchemaProperty> schemaProperties = schemasActions.getRequiredProperties(schema);
    Assumptions.assumeFalse(blacklistedEndpoints.contains(endpoint), "N/A test case - blacklisted endpoint.");
    Assumptions.assumeFalse(schemaProperties.stream().anyMatch(schemaProperty -> schemaProperty.getPropertyType() == PropertyType.COMPLEX), "N/A test case - body would require COMPLEX objects.");
    // post
    JsonObject object = DataGenerator.generateObjectMatchingSchema(schemaProperties);
    ApiResponse response = apiActions.post(object);
    // validate response;
    ResponseValidationHelper.validateObjectCreation(response);
    // validate removal;
    response = apiActions.delete(response.extractUid());
    ResponseValidationHelper.validateObjectRemoval(response, endpoint + " was not deleted");
}
Also used : DataGenerator(org.hisp.dhis.utils.DataGenerator) JsonObject(com.google.gson.JsonObject) Arrays(java.util.Arrays) SchemaProperty(org.hisp.dhis.dto.schemas.SchemaProperty) ResponseValidationHelper(org.hisp.dhis.helpers.ResponseValidationHelper) Matchers(org.hamcrest.Matchers) Arguments(org.junit.jupiter.params.provider.Arguments) ApiResponse(org.hisp.dhis.dto.ApiResponse) ArrayList(java.util.ArrayList) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) Assumptions(org.junit.jupiter.api.Assumptions) BeforeAll(org.junit.jupiter.api.BeforeAll) RestApiActions(org.hisp.dhis.actions.RestApiActions) ApiTest(org.hisp.dhis.ApiTest) SchemasActions(org.hisp.dhis.actions.SchemasActions) PropertyType(org.hisp.dhis.dto.schemas.PropertyType) LoginActions(org.hisp.dhis.actions.LoginActions) MethodSource(org.junit.jupiter.params.provider.MethodSource) RestApiActions(org.hisp.dhis.actions.RestApiActions) SchemaProperty(org.hisp.dhis.dto.schemas.SchemaProperty) JsonObject(com.google.gson.JsonObject) ApiResponse(org.hisp.dhis.dto.ApiResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 8 with ApiResponse

use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.

the class MetadataImportBasedOnSchemasTest method getMatchesSchema.

@ParameterizedTest
@MethodSource("getSchemaEndpoints")
public // todo add better schema validation when spec is ready
void getMatchesSchema(String endpoint, String schema) {
    RestApiActions apiActions = new RestApiActions(endpoint);
    ApiResponse response = apiActions.get("?fields=*");
    response.validate().statusCode(200).body(endpoint, Matchers.notNullValue());
    Object firstObject = response.extract(endpoint + "[0]");
    if (firstObject == null) {
        return;
    }
    schemasActions.validateObjectAgainstSchema(schema, firstObject).validate().statusCode(200);
}
Also used : RestApiActions(org.hisp.dhis.actions.RestApiActions) JsonObject(com.google.gson.JsonObject) ApiResponse(org.hisp.dhis.dto.ApiResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 9 with ApiResponse

use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.

the class MetadataImportTest method shouldSkipSharing.

@Test
public void shouldSkipSharing() {
    JsonObject metadata = generateMetadataObjectWithInvalidSharing();
    ApiResponse response = metadataActions.post(metadata, new QueryParamsBuilder().add("skipSharing=true"));
    response.validate().statusCode(200).rootPath("response").body("status", is(oneOf("SUCCESS", "OK"))).body("stats.created", equalTo(1));
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ApiTest(org.hisp.dhis.ApiTest)

Example 10 with ApiResponse

use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.

the class MetadataImportTest method shouldReturnImportSummariesWhenImportingInvalidMetadataAsync.

@Test
public void shouldReturnImportSummariesWhenImportingInvalidMetadataAsync() throws Exception {
    // arrange
    QueryParamsBuilder queryParamsBuilder = new QueryParamsBuilder();
    queryParamsBuilder.addAll("async=true", "importReportMode=DEBUG", "importStrategy=CREATE_AND_UPDATE", "atomicMode=NONE");
    JsonObject metadata = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/metadata/uniqueMetadata.json"));
    metadata.getAsJsonArray("organisationUnits").get(0).getAsJsonObject().addProperty("shortName", RandomStringUtils.random(51));
    // act
    ApiResponse response = metadataActions.post(metadata, queryParamsBuilder);
    response.validate().statusCode(200).body(notNullValue()).body("response.name", equalTo("metadataImport")).body("response.jobType", equalTo("METADATA_IMPORT"));
    String taskId = response.extractString("response.id");
    // Validate that job was successful
    systemActions.waitUntilTaskCompleted("METADATA_IMPORT", taskId).validate().body("message", hasItem(containsString("Import:Start"))).body("message", hasItem(containsString("Import:Done")));
    // validate task summaries were created
    systemActions.waitForTaskSummaries("METADATA_IMPORT", taskId).validate().body(notNullValue()).body("status", equalTo("WARNING")).body("typeReports", notNullValue()).rootPath("typeReports").body("stats.total", everyItem(greaterThan(0))).body("stats.ignored", hasSize(greaterThanOrEqualTo(1))).body("objectReports", notNullValue()).body("objectReports", hasSize(greaterThanOrEqualTo(1))).body("objectReports.errorReports", notNullValue());
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ApiTest(org.hisp.dhis.ApiTest)

Aggregations

ApiResponse (org.hisp.dhis.dto.ApiResponse)145 Test (org.junit.jupiter.api.Test)75 JsonObject (com.google.gson.JsonObject)63 ApiTest (org.hisp.dhis.ApiTest)63 QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)49 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)48 File (java.io.File)25 TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)18 FileReaderUtils (org.hisp.dhis.helpers.file.FileReaderUtils)18 ValueSource (org.junit.jupiter.params.provider.ValueSource)16 MethodSource (org.junit.jupiter.params.provider.MethodSource)14 JsonObjectBuilder (org.hisp.dhis.helpers.JsonObjectBuilder)11 TrackerNtiApiTest (org.hisp.dhis.tracker.TrackerNtiApiTest)11 RestApiActions (org.hisp.dhis.actions.RestApiActions)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 JsonArray (com.google.gson.JsonArray)5 ImportSummary (org.hisp.dhis.dto.ImportSummary)5 LoginActions (org.hisp.dhis.actions.LoginActions)4 MetadataApiResponse (org.hisp.dhis.dto.MetadataApiResponse)4 ArrayList (java.util.ArrayList)3