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