use of org.hisp.dhis.webapi.json.domain.JsonErrorReport in project dhis2-core by dhis2.
the class AbstractCrudControllerTest method replaceTranslations_MissingLocale.
@Test
void replaceTranslations_MissingLocale() {
String id = assertStatus(HttpStatus.CREATED, POST("/dataSets/", "{'name':'My data set', 'periodType':'Monthly'}"));
JsonWebMessage message = assertWebMessage("Conflict", 409, "WARNING", "One more more errors occurred, please see full details in import report.", PUT("/dataSets/" + id + "/translations", "{'translations': [{'property':'name', 'value':'namn 1'}]}").content(HttpStatus.CONFLICT));
JsonErrorReport error = message.find(JsonErrorReport.class, report -> report.getErrorCode() == ErrorCode.E4000);
assertEquals("Missing required property `locale`.", error.getMessage());
}
use of org.hisp.dhis.webapi.json.domain.JsonErrorReport in project dhis2-core by dhis2.
the class MetadataWorkflowControllerTest method testMakeAddProposal_ConflictIllegalChange.
@Test
void testMakeAddProposal_ConflictIllegalChange() {
JsonWebMessage message = assertWebMessage("Conflict", 409, "WARNING", "One more more errors occurred, please see full details in import report.", POST("/metadata/proposals/", "{" + "'type':'ADD'," + "'target':'ORGANISATION_UNIT'," + "'change':{'name':'hasNoShortName', " + "'openingDate': '2020-01-01'" + "}" + "}").content(HttpStatus.CONFLICT));
JsonErrorReport error = message.find(JsonErrorReport.class, report -> report.getErrorCode() == ErrorCode.E4000);
assertEquals("Missing required property `shortName`.", error.getMessage());
assertEquals("shortName", error.getErrorProperties().get(0));
}
use of org.hisp.dhis.webapi.json.domain.JsonErrorReport in project dhis2-core by dhis2.
the class MetadataWorkflowControllerTest method testAcceptProposal_ConflictMissingAuthority.
@Test
void testAcceptProposal_ConflictMissingAuthority() {
User guest = switchToNewUser("guest");
String proposalId = postUpdateNameProposal(defaultTargetId, "New name");
JsonWebMessage message = assertWebMessage("Conflict", 409, "WARNING", "One more more errors occurred, please see full details in import report.", POST("/metadata/proposals/" + proposalId).content(HttpStatus.CONFLICT));
JsonErrorReport error = message.find(JsonErrorReport.class, report -> report.getErrorCode() == ErrorCode.E3001);
JsonMetadataProposal proposal = GET("/metadata/proposals/" + proposalId).content().as(JsonMetadataProposal.class);
assertEquals(String.format("E3001 User `guest guest [%s] (User)` is not allowed to update object `New name [%s] (OrganisationUnit)`.\n", guest.getUid(), defaultTargetId), proposal.getReason());
// but the system could accept the proposal
switchContextToUser(system);
assertStatus(HttpStatus.OK, PUT("/metadata/proposals/" + proposalId));
assertStatus(HttpStatus.OK, POST("/metadata/proposals/" + proposalId));
}
use of org.hisp.dhis.webapi.json.domain.JsonErrorReport in project dhis2-core by dhis2.
the class MetadataWorkflowControllerTest method testMakeUpdateProposal_ConflictIllegalChange.
@Test
void testMakeUpdateProposal_ConflictIllegalChange() {
JsonWebMessage message = assertWebMessage("Conflict", 409, "WARNING", "One more more errors occurred, please see full details in import report.", POST("/metadata/proposals/", "{" + "'type':'UPDATE'," + "'target':'ORGANISATION_UNIT'," + "'targetId': '" + defaultTargetId + "'," + "'change':[{'op':'not-json-patch-op'}]" + "}").content(HttpStatus.CONFLICT));
JsonErrorReport error = message.find(JsonErrorReport.class, report -> report.getErrorCode() == ErrorCode.E4031);
assertEquals("Property `change` requires a valid JSON payload, was given `[{\"op\":\"not-json-patch-op\"}]`.", error.getMessage());
assertEquals("change", error.getErrorProperties().get(0));
}
use of org.hisp.dhis.webapi.json.domain.JsonErrorReport in project dhis2-core by dhis2.
the class MetadataWorkflowControllerTest method testAcceptRemoveProposal_ConflictTargetAlreadyDeleted.
@Test
void testAcceptRemoveProposal_ConflictTargetAlreadyDeleted() {
String proposalId = postRemoveProposal(defaultTargetId);
assertStatus(HttpStatus.OK, DELETE("/organisationUnits/" + defaultTargetId));
JsonWebMessage message = assertWebMessage("Conflict", 409, "WARNING", "One more more errors occurred, please see full details in import report.", POST("/metadata/proposals/" + proposalId).content(HttpStatus.CONFLICT));
JsonErrorReport error = message.find(JsonErrorReport.class, report -> report.getErrorCode() == ErrorCode.E4015);
assertEquals("Property `targetId` refers to an object that does not exist, could not find `" + defaultTargetId + "`", error.getMessage());
assertEquals("targetId", error.getErrorProperties().get(0));
}
Aggregations