use of org.hisp.dhis.actions.RestApiActions 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");
}
use of org.hisp.dhis.actions.RestApiActions 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);
}
use of org.hisp.dhis.actions.RestApiActions in project dhis2-core by dhis2.
the class TestCleanUp method deleteEntity.
public boolean deleteEntity(String resource, String id) {
ApiResponse response = new RestApiActions(resource).delete(id + "?force=true");
if (response.statusCode() == 200 || response.statusCode() == 404) {
logger.info(String.format("Entity from resource %s with id %s deleted", resource, id));
if (response.containsImportSummaries()) {
return response.extract("response.importCount.deleted").equals(1);
}
return true;
}
logger.warning(String.format("Entity from resource %s with id %s was not deleted. Status code: %s", resource, id, response.statusCode()));
return false;
}
use of org.hisp.dhis.actions.RestApiActions 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"));
}
use of org.hisp.dhis.actions.RestApiActions 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);
}
Aggregations