diff --git a/src/test/java/org/caosdb/server/grpc/CaosDBToGrpcConvertersTest.java b/src/test/java/org/caosdb/server/grpc/CaosDBToGrpcConvertersTest.java index 1a3489d86ae602679cff5b53d120aa32c9ed7d47..d46c187324b76e179ef8d562cd5a150ab7968a45 100644 --- a/src/test/java/org/caosdb/server/grpc/CaosDBToGrpcConvertersTest.java +++ b/src/test/java/org/caosdb/server/grpc/CaosDBToGrpcConvertersTest.java @@ -6,7 +6,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.TimeZone; import org.caosdb.api.entity.v1.Value.Builder; import org.caosdb.datetime.DateTimeFactory2; +import org.caosdb.server.datatype.CollectionValue; import org.caosdb.server.datatype.GenericValue; +import org.caosdb.server.datatype.ReferenceValue; import org.caosdb.server.datatype.Value; import org.caosdb.server.entity.EntityID; import org.caosdb.server.entity.FileProperties; @@ -119,4 +121,53 @@ public class CaosDBToGrpcConvertersTest { "scalar_value {\n" + " special_value: SPECIAL_VALUE_UNSPECIFIED\n" + "}\n", value.toString()); } + + @Test + public void testGetSelectedValueWithListOfReferenceValue() { + CollectionValue col = new CollectionValue(); + Property p = new Property(new RetrieveEntity()); + p.setName("Person"); + p.setDatatype("List<Person>"); + + Property fullName1 = new Property(new RetrieveEntity()); + fullName1.setName("full name"); + fullName1.setDatatype("TEXT"); + fullName1.setValue(new GenericValue("Harry Belafonte")); + + RetrieveEntity person1 = new RetrieveEntity(); + person1.addProperty(fullName1); + ReferenceValue val1 = new ReferenceValue(new EntityID(1234)); + val1.setEntity(person1, false); + col.add(val1); + + Property fullName2 = new Property(new RetrieveEntity()); + fullName2.setName("full name"); + fullName2.setDatatype("TEXT"); + fullName2.setValue(new GenericValue("Louis Prima")); + + RetrieveEntity person2 = new RetrieveEntity(); + person2.addProperty(fullName2); + ReferenceValue val2 = new ReferenceValue(new EntityID(1234)); + val2.setEntity(person2, false); + col.add(val2); + p.setValue(col); + + RetrieveEntity entity = new RetrieveEntity(); + entity.addProperty(p); + + CaosDBToGrpcConverters converters = new CaosDBToGrpcConverters(null); + Builder value = + converters.getSelectedValue( + new Selection("Person").setSubSelection(new Selection("full name")), entity); + assertEquals( + "list_values {\n" + + " values {\n" + + " string_value: \"Harry Belafonte\"\n" + + " }\n" + + " values {\n" + + " string_value: \"Louis Prima\"\n" + + " }\n" + + "}\n", + value.toString()); + } }