Search in sources :

Example 11 with JsonWebMessage

use of org.hisp.dhis.webapi.json.domain.JsonWebMessage 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 12 with JsonWebMessage

use of org.hisp.dhis.webapi.json.domain.JsonWebMessage 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)

Example 13 with JsonWebMessage

use of org.hisp.dhis.webapi.json.domain.JsonWebMessage 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 14 with JsonWebMessage

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

the class ExpressionControllerTest method testGetExpressionDescription_InvalidExpression.

@Test
void testGetExpressionDescription_InvalidExpression() {
    JsonWebMessage response = GET("/expressions/description?expression=invalid").content().as(JsonWebMessage.class);
    assertWebMessage("OK", 200, "ERROR", "Expression is not well-formed", response);
    assertNull(response.getDescription());
}
Also used : JsonWebMessage(org.hisp.dhis.webapi.json.domain.JsonWebMessage) Test(org.junit.jupiter.api.Test) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest)

Example 15 with JsonWebMessage

use of org.hisp.dhis.webapi.json.domain.JsonWebMessage 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)

Aggregations

DhisControllerConvenienceTest (org.hisp.dhis.webapi.DhisControllerConvenienceTest)24 JsonWebMessage (org.hisp.dhis.webapi.json.domain.JsonWebMessage)24 Test (org.junit.jupiter.api.Test)24 JsonErrorReport (org.hisp.dhis.webapi.json.domain.JsonErrorReport)13 JsonTypeReport (org.hisp.dhis.webapi.json.domain.JsonTypeReport)3 JsonArray (org.hisp.dhis.jsontree.JsonArray)2 JsonImportSummary (org.hisp.dhis.webapi.json.domain.JsonImportSummary)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 GeoJsonObject (org.geojson.GeoJsonObject)1 Polygon (org.geojson.Polygon)1 ErrorCode (org.hisp.dhis.feedback.ErrorCode)1 JsonObject (org.hisp.dhis.jsontree.JsonObject)1 User (org.hisp.dhis.user.User)1 Body (org.hisp.dhis.webapi.WebClient.Body)1 ContentType (org.hisp.dhis.webapi.WebClient.ContentType)1 JsonMetadataProposal (org.hisp.dhis.webapi.controller.json.JsonMetadataProposal)1 JsonAttributeValue (org.hisp.dhis.webapi.json.domain.JsonAttributeValue)1 JsonIdentifiableObject (org.hisp.dhis.webapi.json.domain.JsonIdentifiableObject)1 JsonStats (org.hisp.dhis.webapi.json.domain.JsonStats)1