Search in sources :

Example 6 with JsonErrorReport

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());
}
Also used : JsonWebMessage(org.hisp.dhis.webapi.json.domain.JsonWebMessage) JsonErrorReport(org.hisp.dhis.webapi.json.domain.JsonErrorReport) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 7 with JsonErrorReport

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));
}
Also used : JsonWebMessage(org.hisp.dhis.webapi.json.domain.JsonWebMessage) JsonErrorReport(org.hisp.dhis.webapi.json.domain.JsonErrorReport) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 8 with JsonErrorReport

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));
}
Also used : User(org.hisp.dhis.user.User) JsonWebMessage(org.hisp.dhis.webapi.json.domain.JsonWebMessage) JsonErrorReport(org.hisp.dhis.webapi.json.domain.JsonErrorReport) JsonMetadataProposal(org.hisp.dhis.webapi.controller.json.JsonMetadataProposal) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 9 with JsonErrorReport

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));
}
Also used : JsonWebMessage(org.hisp.dhis.webapi.json.domain.JsonWebMessage) JsonErrorReport(org.hisp.dhis.webapi.json.domain.JsonErrorReport) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 10 with JsonErrorReport

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));
}
Also used : JsonWebMessage(org.hisp.dhis.webapi.json.domain.JsonWebMessage) JsonErrorReport(org.hisp.dhis.webapi.json.domain.JsonErrorReport) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Aggregations

JsonErrorReport (org.hisp.dhis.webapi.json.domain.JsonErrorReport)13 DhisControllerConvenienceTest (org.hisp.dhis.webapi.DhisControllerConvenienceTest)12 JsonWebMessage (org.hisp.dhis.webapi.json.domain.JsonWebMessage)12 Test (org.junit.jupiter.api.Test)12 JsonArray (org.hisp.dhis.jsontree.JsonArray)2 User (org.hisp.dhis.user.User)1 JsonMetadataProposal (org.hisp.dhis.webapi.controller.json.JsonMetadataProposal)1 JsonObjectReport (org.hisp.dhis.webapi.json.domain.JsonObjectReport)1