2727import java .util .ArrayList ;
2828import java .util .List ;
2929import java .util .Map ;
30+ import java .util .Set ;
3031
32+ import static java .util .stream .Collectors .toSet ;
33+ import static org .apache .commons .collections4 .CollectionUtils .isEqualCollection ;
34+ import static org .junit .Assert .assertEquals ;
35+ import static org .junit .Assert .assertTrue ;
36+ import static org .opensilex .sparql .deserializer .SPARQLDeserializers .getExpandedURI ;
3137import static org .opensilex .sparql .deserializer .SPARQLDeserializers .nodeURI ;
3238import static org .opensilex .sparql .service .SPARQLQueryHelper .makeVar ;
3339
@@ -136,10 +142,9 @@ public void testMixedMultiMonoValuedProperty() throws Exception {
136142 sparql .create (experimentNode , makeScientificObject (object1Uri , "object1" , TYPE_1_URI , Map .of (PROP_1_URI , List .of (device1Uri , device2Uri ))));
137143 sparql .create (experimentNode , makeScientificObject (object2Uri , "object2" , TYPE_2_URI , Map .of (PROP_1_URI , List .of (device1Uri ))));
138144
139- var initialModels = List .of (
140- makeScientificObject (object1Uri , "object1" , TYPE_1_URI , Map .of ()),
141- makeScientificObject (object2Uri , "object2" , TYPE_2_URI , Map .of ())
142- );
145+ var object1 = makeScientificObject (object1Uri , "object1" , TYPE_1_URI , Map .of ());
146+ var object2 = makeScientificObject (object2Uri , "object2" , TYPE_2_URI , Map .of ());
147+ var initialModels = List .of (object1 , object2 );
143148 var select = makeObjectSelect (experimentUri );
144149 var relationFetcher = new SPARQLRelationFetcher <>(
145150 sparql ,
@@ -148,5 +153,19 @@ public void testMixedMultiMonoValuedProperty() throws Exception {
148153 select ,
149154 initialModels );
150155 relationFetcher .updateModels ();
156+
157+ var rels1 = object1 .getRelations ();
158+ var relProperties1 = rels1 .stream ().map (rel -> getExpandedURI (rel .getProperty ().getURI ())).collect (toSet ());
159+ var relValues1 = rels1 .stream ().map (rel -> getExpandedURI (rel .getValue ())).collect (toSet ());
160+ var rels2 = object2 .getRelations ();
161+ var relProperties2 = rels2 .stream ().map (rel -> getExpandedURI (rel .getProperty ().getURI ())).collect (toSet ());
162+ var relValues2 = rels2 .stream ().map (rel -> getExpandedURI (rel .getValue ())).collect (toSet ());
163+
164+ assertEquals (2 , rels1 .size ());
165+ assertTrue (isEqualCollection (Set .of (PROP_1_URI .toString ()), relProperties1 ));
166+ assertTrue (isEqualCollection (Set .of (device1Uri .toString (), device2Uri .toString ()), relValues1 ));
167+ assertEquals (1 , rels2 .size ());
168+ assertTrue (isEqualCollection (Set .of (PROP_1_URI .toString ()), relProperties2 ));
169+ assertTrue (isEqualCollection (Set .of (device1Uri .toString ()), relValues2 ));
151170 }
152171}
0 commit comments