Search in sources :

Example 41 with JsonValue

use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.

the class EnumTypeTest method deserializationEnumTypeNoChoices.

@Test
public void deserializationEnumTypeNoChoices() {
    EnumType type = new EnumType(Cardinality.SINGLE, EnumType.Presentation.AUTOMATIC, Collections.<EnumItem>emptyList());
    JsonValue jsonObject = type.getParametersAsJson();
    EnumType reType = EnumType.TYPE_CLASS.deserializeType(jsonObject);
    assertThat(reType.getCardinality(), equalTo(Cardinality.SINGLE));
    assertThat(reType.getPresentation(), equalTo(EnumType.Presentation.AUTOMATIC));
    assertThat(reType.getValues(), hasSize(0));
}
Also used : JsonValue(org.activityinfo.json.JsonValue) Test(org.junit.Test)

Example 42 with JsonValue

use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.

the class CalculatedFieldTypeTest method emptySerialization.

@Test
public void emptySerialization() {
    FormField field = new FormField(ResourceId.generateId());
    field.setType(new CalculatedFieldType());
    JsonValue record = field.toJsonObject();
    System.out.println(record.toJson());
    FormField read = FormField.fromJson(record);
    assertThat(read.getType(), instanceOf(CalculatedFieldType.class));
    CalculatedFieldType readType = (CalculatedFieldType) read.getType();
    assertThat(readType.getExpression(), nullValue());
}
Also used : JsonValue(org.activityinfo.json.JsonValue) FormField(org.activityinfo.model.form.FormField) Test(org.junit.Test)

Example 43 with JsonValue

use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.

the class CalculatedFieldTypeTest method serialization.

@Test
public void serialization() {
    FormField field = new FormField(ResourceId.generateId());
    field.setType(new CalculatedFieldType("A+B"));
    JsonValue record = field.toJsonObject();
    System.out.println(record.toJson());
    FormField read = FormField.fromJson(record);
    assertThat(read.getType(), instanceOf(CalculatedFieldType.class));
    CalculatedFieldType readType = (CalculatedFieldType) read.getType();
    assertThat(readType.getExpression(), equalTo("A+B"));
}
Also used : JsonValue(org.activityinfo.json.JsonValue) FormField(org.activityinfo.model.form.FormField) Test(org.junit.Test)

Example 44 with JsonValue

use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.

the class QuantityTypeTest method parseResource.

private FormClass parseResource() throws IOException {
    URL resource = Resources.getResource(FormClass.class, "OldFormClass2.json");
    String json = Resources.toString(resource, Charsets.UTF_8);
    JsonValue element = Json.parse(json);
    return FormClass.fromJson(element);
}
Also used : JsonValue(org.activityinfo.json.JsonValue) URL(java.net.URL)

Example 45 with JsonValue

use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.

the class SubFormReferenceType method getParametersAsJson.

@Override
public JsonValue getParametersAsJson() {
    JsonValue object = createObject();
    object.put("formId", classId == null ? Json.createNull() : Json.create(classId.asString()));
    return object;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Aggregations

JsonValue (org.activityinfo.json.JsonValue)117 Test (org.junit.Test)24 ResourceId (org.activityinfo.model.resource.ResourceId)19 FormClass (org.activityinfo.model.form.FormClass)13 FormField (org.activityinfo.model.form.FormField)9 FieldValue (org.activityinfo.model.type.FieldValue)8 HashMap (java.util.HashMap)6 Map (java.util.Map)6 QuantityType (org.activityinfo.model.type.number.QuantityType)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Annotation (java.lang.annotation.Annotation)3 ArrayList (java.util.ArrayList)3 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)3 JaxRsJsonReader (org.activityinfo.server.endpoint.rest.JaxRsJsonReader)3 TypedRecordUpdate (org.activityinfo.store.spi.TypedRecordUpdate)3 EmbeddedEntity (com.google.appengine.api.datastore.EmbeddedEntity)2 URL (java.net.URL)2 JsonException (org.activityinfo.json.JsonException)2 JsonMappingException (org.activityinfo.json.JsonMappingException)2