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());
}
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());
}
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());
}
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));
}
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());
}
Aggregations