Search in sources :

Example 41 with ApiResponse

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

the class RuleEngineTests method shouldSendProgramRuleNotification.

@Test
public void shouldSendProgramRuleNotification() {
    JsonObject payload = new EventDataBuilder().addDataValue("ILRgzHhzFkg", "true").addDataValue("z3Z4TD3oBCP", "true").addDataValue("BuZ5LGNfGEU", "40").array(Constants.ORG_UNIT_IDS[0], eventProgramId, "Mt6Ac5brjoK");
    loginActions.loginAsAdmin();
    ApiResponse response = new RestApiActions("/messageConversations").get("", new QueryParamsBuilder().add("fields=*"));
    int size = response.getBody().getAsJsonArray("messageConversations").size();
    loginActions.loginAsSuperUser();
    trackerActions.postAndGetJobReport(payload).validateSuccessfulImport();
    loginActions.loginAsAdmin();
    messageConversationsActions.waitForNotification(size + 1);
    messageConversationsActions.get("", new QueryParamsBuilder().add("fields=*")).validate().statusCode(200).body("messageConversations", hasSize(size + 1)).body("messageConversations.subject", hasItem("Program rule triggered"));
}
Also used : RestApiActions(org.hisp.dhis.actions.RestApiActions) EventDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) ApiResponse(org.hisp.dhis.dto.ApiResponse) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 42 with ApiResponse

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

the class TrackerExportTests method shouldReturnRequestedFields.

@MethodSource()
@ParameterizedTest
public void shouldReturnRequestedFields(String endpoint, String fields, String fieldsToValidate) {
    ApiResponse response = trackerActions.get(endpoint + "?fields=" + fields);
    response.validate().statusCode(200);
    List<String> fieldList = fieldsToValidate == null ? splitFields(fields) : splitFields(fieldsToValidate);
    fieldList.forEach(p -> {
        response.validate().body(p, allOf(not(nullValue()), not(contains(nullValue())), not(emptyIterable())));
    });
}
Also used : ApiResponse(org.hisp.dhis.dto.ApiResponse) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 43 with ApiResponse

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

the class SystemSettingsTests method returnTranslationForUsersLocale.

@Test
public void returnTranslationForUsersLocale() {
    prepareData();
    ApiResponse response = systemSettingActions.get(APPLICATION_INTRO_KEY, ContentType.TEXT.toString(), ContentType.TEXT.toString(), new QueryParamsBuilder());
    response.validate().log().all().statusCode(200).body(containsString(ENGLISH_INTRO));
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Example 44 with ApiResponse

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

the class SystemSettingsTests method returnDefaultValueWhenUserIsNotLoggedIn.

@Test
@Disabled("This test is broken and will only return 200 OK because the servlet redirects to the login page. //TODO: Remove")
public void returnDefaultValueWhenUserIsNotLoggedIn() {
    prepareData();
    // I need to log out
    loginActions.removeAuthenticationHeader();
    ApiResponse response = systemSettingActions.get(APPLICATION_INTRO_KEY, ContentType.TEXT.toString(), ContentType.TEXT.toString(), new QueryParamsBuilder());
    response.validate().statusCode(200);
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest) Disabled(org.junit.jupiter.api.Disabled)

Example 45 with ApiResponse

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

the class TrackedEntityInstanceAclReadTests method setupUser.

/**
 * Takes a User object and retrieves information about the users from the
 * api. Updates the password of the user to allow access.
 *
 * @param user to setup
 */
private void setupUser(User user) {
    userActions.updateUserPassword(user.getUid(), user.getPassword());
    new LoginActions().loginAsUser(user.getUsername(), user.getPassword());
    // Get User information from /me
    ApiResponse apiResponse = new RestApiActions("/me").get();
    String asString = apiResponse.getAsString();
    Me me = apiResponse.as(Me.class);
    // Add userGroups
    user.setGroups(me.getUserGroups().stream().map(UserGroup::getId).collect(Collectors.toList()));
    // Add search-scope ous
    user.setSearchScope(me.getTeiSearchOrganisationUnits().stream().map(OrgUnit::getId).collect(Collectors.toList()));
    // Add capture-scope ous
    user.setCaptureScope(me.getOrganisationUnits().stream().map(OrgUnit::getId).collect(Collectors.toList()));
    // Add hasAllAuthority if user has ALL authority
    user.setAllAuthority(me.getAuthorities().contains("ALL"));
    // Setup map to decide what data can and cannot be read.
    setupAccessMap(user);
}
Also used : OrgUnit(org.hisp.dhis.dto.OrgUnit) RestApiActions(org.hisp.dhis.actions.RestApiActions) Me(org.hisp.dhis.dto.Me) LoginActions(org.hisp.dhis.actions.LoginActions) ApiResponse(org.hisp.dhis.dto.ApiResponse) UserGroup(org.hisp.dhis.dto.UserGroup)

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