Search in sources :

Example 6 with JsonWebMessage

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

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

the class AbstractCrudControllerTest method testSetSharing_InvalidPublicAccess.

@Test
void testSetSharing_InvalidPublicAccess() {
    String userId = getCurrentUser().getUid();
    // first create an object which can be shared
    String programId = assertStatus(HttpStatus.CREATED, POST("/programs/", "{'name':'test', 'shortName':'test', 'programType':'WITHOUT_REGISTRATION'}"));
    String sharing = "{'owner':'" + userId + "', 'public':'illegal', 'external': true }";
    JsonWebMessage message = PUT("/programs/" + programId + "/sharing", sharing).content(HttpStatus.CONFLICT).as(JsonWebMessage.class);
    assertWebMessage("Conflict", 409, "ERROR", "One more more errors occurred, please see full details in import report.", message);
    JsonTypeReport response = message.get("response", JsonTypeReport.class);
    assertEquals(1, response.getObjectReports().size());
    assertEquals(ErrorCode.E3015, response.getObjectReports().get(0).getErrorReports().get(0).getErrorCode());
}
Also used : JsonWebMessage(org.hisp.dhis.webapi.json.domain.JsonWebMessage) JsonTypeReport(org.hisp.dhis.webapi.json.domain.JsonTypeReport) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 8 with JsonWebMessage

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

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

the class DataValueSetControllerTest method testGetDataValueSetJson.

@Test
void testGetDataValueSetJson() {
    String ouId = assertStatus(HttpStatus.CREATED, POST("/organisationUnits/", "{'name':'My Unit', 'shortName':'OU1', 'openingDate': '2020-01-01', 'code':'OU1'}"));
    JsonWebMessage response = GET("/dataValueSets/?inputOrgUnitIdScheme=code&idScheme=name&orgUnit={ou}", "OU1").content(HttpStatus.CONFLICT).as(JsonWebMessage.class);
    assertEquals(String.format("User is not allowed to view org unit: `%s`", ouId), response.getMessage());
}
Also used : JsonWebMessage(org.hisp.dhis.webapi.json.domain.JsonWebMessage) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 10 with JsonWebMessage

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

the class ExpressionControllerTest method testGetExpressionDescription.

@Test
void testGetExpressionDescription() {
    JsonWebMessage response = GET("/expressions/description?expression=0").content().as(JsonWebMessage.class);
    assertWebMessage("OK", 200, "OK", "Valid", response);
    assertEquals("0", response.getDescription());
}
Also used : JsonWebMessage(org.hisp.dhis.webapi.json.domain.JsonWebMessage) Test(org.junit.jupiter.api.Test) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest)

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