diff --git a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/MissionModelTests.java b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/MissionModelTests.java index 6cd63203ae..04633a5643 100644 --- a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/MissionModelTests.java +++ b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/MissionModelTests.java @@ -12,6 +12,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; +import javax.json.Json; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -72,8 +73,8 @@ private ArrayList expectedResourceTypesBanananation(){ resourceTypes.add(new ResourceType("/flag/conflicted", VALUE_SCHEMA_BOOLEAN)); resourceTypes.add(new ResourceType( "/fruit", - new ValueSchemaStruct(Map.of("rate", VALUE_SCHEMA_REAL, "initial", VALUE_SCHEMA_REAL)))); - resourceTypes.add(new ResourceType("/peel", VALUE_SCHEMA_REAL)); + new ValueSchemaMeta(Map.of("unit", Json.createValue("bananas")), new ValueSchemaStruct(Map.of("rate", VALUE_SCHEMA_REAL, "initial", VALUE_SCHEMA_REAL))))); + resourceTypes.add(new ResourceType("/peel", new ValueSchemaMeta(Map.of("unit", Json.createValue("kg")), VALUE_SCHEMA_REAL))); resourceTypes.add(new ResourceType("/plant", VALUE_SCHEMA_INT)); resourceTypes.add(new ResourceType("/producer", VALUE_SCHEMA_STRING)); return resourceTypes; @@ -91,7 +92,7 @@ private ArrayList expectedActivityTypesBanananation() { "glutenFree", new Parameter(2, VALUE_SCHEMA_BOOLEAN), "temperature", new Parameter(0, VALUE_SCHEMA_REAL)))); activityTypes.add(new ActivityType("BananaNap", Map.of())); - activityTypes.add(new ActivityType("BiteBanana", Map.of("biteSize", new Parameter(0, VALUE_SCHEMA_REAL)))); + activityTypes.add(new ActivityType("BiteBanana", Map.of("biteSize", new Parameter(0, new ValueSchemaMeta(Map.of("unit", Json.createValue("m"), "label", Json.createObjectBuilder().add("value", Json.createValue("Specifies the size of bite to take")).build()), VALUE_SCHEMA_REAL))))); activityTypes.add(new ActivityType("ChangeProducer", Map.of("producer", new Parameter(0, VALUE_SCHEMA_STRING)))); activityTypes.add(new ActivityType("child", Map.of("counter", new Parameter(0, VALUE_SCHEMA_INT)))); activityTypes.add(new ActivityType("ControllableDurationActivity", Map.of("duration", new Parameter(0, VALUE_SCHEMA_DURATION)))); @@ -247,8 +248,8 @@ private ArrayList expectedActivityTypesBanananation() { entry("byteArray", new Parameter(19,new ValueSchemaSeries(VALUE_SCHEMA_INT))), entry("charArray", new Parameter(23, new ValueSchemaSeries(VALUE_SCHEMA_STRING))), entry("doubleMap", new Parameter(43,new ValueSchemaSeries(new ValueSchemaStruct(Map.of( - "key", VALUE_SCHEMA_REAL, - "value", VALUE_SCHEMA_REAL))))), + "key", new ValueSchemaMeta(Map.of("unit", Json.createValue("m")), VALUE_SCHEMA_REAL), + "value", new ValueSchemaMeta(Map.of("unit", Json.createValue("m")), VALUE_SCHEMA_REAL)))))), entry("floatList", new Parameter(35, new ValueSchemaSeries(VALUE_SCHEMA_REAL))), entry("longArray", new Parameter(22, new ValueSchemaSeries(VALUE_SCHEMA_INT))), entry("obnoxious", new Parameter(57, new ValueSchemaSeries(new ValueSchemaSeries(new ValueSchemaStruct(Map.of( @@ -265,7 +266,7 @@ private ArrayList expectedActivityTypesBanananation() { "value", VALUE_SCHEMA_BOOLEAN))))), entry("boxedFloat", new Parameter(9, VALUE_SCHEMA_REAL)), entry("boxedShort", new Parameter(11, VALUE_SCHEMA_INT)), - entry("doubleList", new Parameter(34, new ValueSchemaSeries(VALUE_SCHEMA_REAL))), + entry("doubleList", new Parameter(34, new ValueSchemaSeries(new ValueSchemaMeta(Map.of("unit", Json.createValue("m")), VALUE_SCHEMA_REAL)))), entry("floatArray", new Parameter(18, new ValueSchemaSeries(VALUE_SCHEMA_REAL))), entry("shortArray", new Parameter(20, new ValueSchemaSeries(VALUE_SCHEMA_INT))), entry("stringList", new Parameter(42, new ValueSchemaSeries(VALUE_SCHEMA_STRING))), diff --git a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/types/ValueSchema.java b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/types/ValueSchema.java index 5edd3c4589..7b3a468131 100644 --- a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/types/ValueSchema.java +++ b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/types/ValueSchema.java @@ -2,6 +2,8 @@ import javax.json.Json; import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; +import javax.json.JsonValue; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -16,28 +18,34 @@ public sealed interface ValueSchema { ValueSchemaString VALUE_SCHEMA_STRING = new ValueSchemaString(); static ValueSchema fromJSON(JsonObject json) { - switch (json.getString("type")) { - case "boolean" -> {return VALUE_SCHEMA_BOOLEAN;} - case "duration" -> {return VALUE_SCHEMA_DURATION;} - case "int" -> {return VALUE_SCHEMA_INT;} - case "path" -> {return VALUE_SCHEMA_PATH;} - case "real" -> {return VALUE_SCHEMA_REAL;} - case "series" -> {return new ValueSchemaSeries(ValueSchema.fromJSON(json.getJsonObject("items")));} - case "string" -> {return VALUE_SCHEMA_STRING;} + final var result = switch (json.getString("type")) { + case "boolean" -> VALUE_SCHEMA_BOOLEAN; + case "duration" -> VALUE_SCHEMA_DURATION; + case "int" -> VALUE_SCHEMA_INT; + case "path" -> VALUE_SCHEMA_PATH; + case "real" -> VALUE_SCHEMA_REAL; + case "series" -> new ValueSchemaSeries(ValueSchema.fromJSON(json.getJsonObject("items"))); + case "string" -> VALUE_SCHEMA_STRING; case "struct" -> { final var items = new HashMap(); final var itemsJson = json.getJsonObject("items"); for(final var item : itemsJson.keySet()){ items.put(item, ValueSchema.fromJSON(itemsJson.getJsonObject(item))); } - return new ValueSchemaStruct(items); + yield new ValueSchemaStruct(items); } case "variant" -> { final var variants = json.getJsonArray("variants") .getValuesAs((JsonObject v) -> new Variant(v.getString("key"), v.getString("label"))); - return new ValueSchemaVariant(variants); + yield new ValueSchemaVariant(variants); } default -> throw new IllegalArgumentException("Cannot determine ValueSchema from JSON"); + }; + if (json.containsKey("metadata")) { + final var metadata = new HashMap<>(json.getJsonObject("metadata")); + return new ValueSchemaMeta(metadata, result); + } else { + return result; } } @@ -132,6 +140,16 @@ public JsonObject toJson() { .build(); } } + + record ValueSchemaMeta(Map metadata, ValueSchema target) implements ValueSchema { + @Override + public JsonObject toJson() { + final var builder = Json.createObjectBuilder(target.toJson()); + metadata.forEach(builder::add); + return builder.build(); + } + } + record Variant(String key, String label) { public JsonObject toJson() { return Json.createObjectBuilder().add("key", key).add("label", label).build();