Search in sources :

Example 1 with JsonErrorReport

use of org.hisp.dhis.webapi.json.domain.JsonErrorReport in project dhis2-core by dhis2.

the class WebClientUtils method assertError.

/**
 * Assumes the {@link org.hisp.dhis.webapi.json.domain.JsonError} has a
 * {@link org.hisp.dhis.webapi.json.domain.JsonTypeReport} containing a
 * single {@link org.hisp.dhis.webapi.json.domain.JsonErrorReport} with the
 * expected properties.
 *
 * @param expectedCode The code the single error is expected to have
 * @param expectedMessage The message the single error is expected to have
 * @param actual the actual error from the {@link HttpResponse}
 */
public static void assertError(ErrorCode expectedCode, String expectedMessage, JsonError actual) {
    JsonList<JsonObjectReport> reports = actual.getTypeReport().getObjectReports();
    assertEquals(1, reports.size());
    JsonList<JsonErrorReport> errors = reports.get(0).getErrorReports();
    assertEquals(1, errors.size());
    JsonErrorReport error = errors.get(0);
    assertEquals(expectedCode, error.getErrorCode());
    assertEquals(expectedMessage, error.getMessage());
}
Also used : JsonObjectReport(org.hisp.dhis.webapi.json.domain.JsonObjectReport) JsonErrorReport(org.hisp.dhis.webapi.json.domain.JsonErrorReport)

Example 2 with JsonErrorReport

use of org.hisp.dhis.webapi.json.domain.JsonErrorReport in project dhis2-core by dhis2.

the class AbstractCrudControllerTest method replaceTranslationsForNotTranslatableObject.

@Test
void replaceTranslationsForNotTranslatableObject() {
    String id = getCurrentUser().getUid();
    JsonArray translations = GET("/users/{id}/translations", id).content().getArray("translations");
    assertTrue(translations.isEmpty());
    JsonWebMessage message = assertWebMessage("Conflict", 409, "WARNING", "One more more errors occurred, please see full details in import report.", PUT("/users/" + id + "/translations", "{'translations': [{'locale':'sv', 'property':'name', 'value':'namn'}]}").content(HttpStatus.CONFLICT));
    JsonErrorReport error = message.find(JsonErrorReport.class, report -> report.getErrorCode() == ErrorCode.E1107);
    assertEquals("Object type `User` is not translatable.", error.getMessage());
}
Also used : JsonArray(org.hisp.dhis.jsontree.JsonArray) 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 3 with JsonErrorReport

use of org.hisp.dhis.webapi.json.domain.JsonErrorReport in project dhis2-core by dhis2.

the class AbstractCrudControllerTest method replaceTranslations_MissingProperty.

@Test
void replaceTranslations_MissingProperty() {
    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': [{'locale':'en', 'value':'namn 1'}]}").content(HttpStatus.CONFLICT));
    JsonErrorReport error = message.find(JsonErrorReport.class, report -> report.getErrorCode() == ErrorCode.E4000);
    assertEquals("Missing required property `property`.", 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 4 with JsonErrorReport

use of org.hisp.dhis.webapi.json.domain.JsonErrorReport in project dhis2-core by dhis2.

the class AbstractCrudControllerTest method replaceTranslationsWithDuplicateLocales.

@Test
public void replaceTranslationsWithDuplicateLocales() {
    String id = assertStatus(HttpStatus.CREATED, POST("/dataSets/", "{'name':'My data set', 'periodType':'Monthly'}"));
    JsonArray translations = GET("/dataSets/{id}/translations", id).content().getArray("translations");
    assertTrue(translations.isEmpty());
    JsonWebMessage message = assertWebMessage("Conflict", 409, "WARNING", "One more more errors occurred, please see full details in import report.", PUT("/dataSets/" + id + "/translations", "{'translations': [{'locale':'sv', 'property':'name', 'value':'namn 1'},{'locale':'sv', 'property':'name', 'value':'namn2'}]}").content(HttpStatus.CONFLICT));
    JsonErrorReport error = message.find(JsonErrorReport.class, report -> report.getErrorCode() == ErrorCode.E1106);
    assertEquals("There are duplicate translation record for property `name` and locale `sv`", error.getMessage());
    assertEquals("name", error.getErrorProperties().get(0));
}
Also used : JsonArray(org.hisp.dhis.jsontree.JsonArray) 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 5 with JsonErrorReport

use of org.hisp.dhis.webapi.json.domain.JsonErrorReport in project dhis2-core by dhis2.

the class AbstractCrudControllerTest method replaceTranslations_MissingValue.

@Test
void replaceTranslations_MissingValue() {
    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': [{'locale':'en', 'property':'name'}]}").content(HttpStatus.CONFLICT));
    JsonErrorReport error = message.find(JsonErrorReport.class, report -> report.getErrorCode() == ErrorCode.E4000);
    assertEquals("Missing required property `value`.", 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)

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