Search in sources :

Example 1 with ObjectType

use of org.hisp.dhis.attribute.Attribute.ObjectType in project dhis2-core by dhis2.

the class AttributeControllerTest method testObjectTypes.

/**
 * Tests that each type only sets the property the type relates to
 */
@Test
void testObjectTypes() {
    for (ObjectType testedType : ObjectType.values()) {
        String propertyName = testedType.getPropertyName();
        String uid = assertStatus(HttpStatus.CREATED, POST("/attributes", "{" + "'name':'" + testedType + "', " + "'valueType':'INTEGER', " + "'" + propertyName + "':true}"));
        JsonObject attr = GET("/attributes/{uid}", uid).content();
        for (ObjectType otherType : ObjectType.values()) {
            assertEquals(testedType == otherType, attr.getBoolean(otherType.getPropertyName()).booleanValue());
        }
    }
}
Also used : ObjectType(org.hisp.dhis.attribute.Attribute.ObjectType) JsonObject(org.hisp.dhis.jsontree.JsonObject) Test(org.junit.jupiter.api.Test) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest)

Example 2 with ObjectType

use of org.hisp.dhis.attribute.Attribute.ObjectType in project dhis2-core by dhis2.

the class SchemaBasedControllerTest method testCanHaveAttributes.

private void testCanHaveAttributes(JsonSchema schema, String uid) {
    ObjectType type = ObjectType.valueOf(schema.getKlass());
    if (type == null || type == ObjectType.MAP) {
        return;
    }
    System.out.println(schema.getRelativeApiEndpoint());
    String attrId = assertStatus(HttpStatus.CREATED, POST("/attributes", "{'name':'" + type + "', 'valueType':'INTEGER','" + type.getPropertyName() + "':true}"));
    String endpoint = schema.getRelativeApiEndpoint();
    JsonObject object = GET(endpoint + "/" + uid).content();
    assertStatus(HttpStatus.OK, PUT(endpoint + "/" + uid + "?mergeMode=REPLACE", Body(object.getObject("attributeValues").node().replaceWith("[{\"value\":42, \"attribute\":{\"id\":\"" + attrId + "\"}}]").getDeclaration()), ContentType(MediaType.APPLICATION_JSON)));
    assertEquals("42", GET(endpoint + "/" + uid).content().as(JsonIdentifiableObject.class).getAttributeValues().get(0).getValue());
}
Also used : ObjectType(org.hisp.dhis.attribute.Attribute.ObjectType) JsonObject(org.hisp.dhis.jsontree.JsonObject)

Aggregations

ObjectType (org.hisp.dhis.attribute.Attribute.ObjectType)2 JsonObject (org.hisp.dhis.jsontree.JsonObject)2 DhisControllerConvenienceTest (org.hisp.dhis.webapi.DhisControllerConvenienceTest)1 Test (org.junit.jupiter.api.Test)1