Search in sources :

Example 1 with QueryParamsBuilder

use of org.hisp.dhis.helpers.QueryParamsBuilder 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 2 with QueryParamsBuilder

use of org.hisp.dhis.helpers.QueryParamsBuilder 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)

Example 3 with QueryParamsBuilder

use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.

the class MetadataImportTest method shouldImportUniqueMetadataAndReturnObjectReports.

@Test
public void shouldImportUniqueMetadataAndReturnObjectReports() throws Exception {
    // arrange
    JsonObject object = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/metadata/uniqueMetadata.json"));
    // act
    ApiResponse response = metadataActions.post(object, new QueryParamsBuilder().addAll("async=false", "importReportMode=DEBUG", "importStrategy=CREATE"));
    // assert
    response.validate().statusCode(200).rootPath("response").body("stats", notNullValue()).body("stats.total", greaterThan(0)).body("typeReports", notNullValue()).body("typeReports.stats", notNullValue()).body("typeReports.objectReports", Matchers.notNullValue());
    List<HashMap> stats = response.extractList("response.typeReports.stats");
    stats.forEach(x -> {
        assertEquals(x.get("total"), x.get("created"));
    });
    List<ObjectReport> objectReports = getObjectReports(response.getTypeReports());
    assertNotNull(objectReports);
    validateCreatedEntities(objectReports);
}
Also used : HashMap(java.util.HashMap) FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) ObjectReport(org.hisp.dhis.dto.ObjectReport) 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)

Example 4 with QueryParamsBuilder

use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.

the class LoginTests method shouldBeAbleToGetRefreshToken.

@Test
public void shouldBeAbleToGetRefreshToken() {
    loginActions.addAuthenticationHeader(oauthClientId, secret);
    JsonObject object = new JsonObject();
    object.addProperty("password", password);
    object.addProperty("grant_type", "password");
    object.addProperty("username", userName);
    ApiResponse passwordGrantTypeResponse = uaaActions.post("oauth/token", new JsonObject(), new QueryParamsBuilder().addAll("password=" + password, "username=" + userName, "grant_type=password"));
    passwordGrantTypeResponse.validate().statusCode(200);
    loginActions.addAuthenticationHeader(oauthClientId, secret);
    ApiResponse refreshTokenResponse = uaaActions.post("oauth/token", new JsonObject(), new QueryParamsBuilder().addAll("grant_type=refresh_token", "refresh_token=" + passwordGrantTypeResponse.extractString("refresh_token")));
    refreshTokenResponse.validate().statusCode(200).body("access_token", notNullValue()).body("token_type", notNullValue()).body("refresh_token", notNullValue()).body("expires_in", notNullValue()).body("scope", notNullValue()).body("access_token", not(equalTo(passwordGrantTypeResponse.extractString("access_token"))));
}
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)

Example 5 with QueryParamsBuilder

use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.

the class AnalyticsDimensionsTest method shouldOrder.

@MethodSource
@ParameterizedTest
public void shouldOrder(String property, String direction) {
    QueryParamsBuilder queryParamsBuilder = new QueryParamsBuilder().add("order", String.format("%s:%s", property, direction));
    analyticsEnrollmentsActions.query().getDimensions(trackerProgram.getUid(), queryParamsBuilder).validate().body("dimensions", hasSize(greaterThanOrEqualTo(1))).body("dimensions." + property, Sorted.by(direction));
    analyticsEventActions.query().getDimensions(trackerProgram.getProgramStages().get(0), queryParamsBuilder).validate().body("dimensions", hasSize(greaterThanOrEqualTo(1))).body("dimensions." + property, Sorted.by(direction));
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)90 JsonObject (com.google.gson.JsonObject)54 Test (org.junit.jupiter.api.Test)51 ApiResponse (org.hisp.dhis.dto.ApiResponse)49 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)43 ApiTest (org.hisp.dhis.ApiTest)27 TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)21 File (java.io.File)20 TrackerNtiApiTest (org.hisp.dhis.tracker.TrackerNtiApiTest)20 FileReaderUtils (org.hisp.dhis.helpers.file.FileReaderUtils)14 MethodSource (org.junit.jupiter.params.provider.MethodSource)13 ValueSource (org.junit.jupiter.params.provider.ValueSource)9 JsonObjectBuilder (org.hisp.dhis.helpers.JsonObjectBuilder)8 EventDataBuilder (org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder)6 TeiDataBuilder (org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder)5 ProgramActions (org.hisp.dhis.actions.metadata.ProgramActions)4 JsonArray (com.google.gson.JsonArray)3 HashMap (java.util.HashMap)3 ProgramStageActions (org.hisp.dhis.actions.metadata.ProgramStageActions)3 ImportSummary (org.hisp.dhis.dto.ImportSummary)3