2222import org .apache .tinkerpop .gremlin .structure .T ;
2323import org .junit .jupiter .api .AfterEach ;
2424import org .junit .jupiter .api .BeforeEach ;
25- import org .junit .jupiter .api .Disabled ;
2625import org .junit .jupiter .api .Test ;
2726
2827import uk .gov .gchq .gaffer .cache .CacheServiceLoader ;
2928import uk .gov .gchq .gaffer .graph .Graph ;
3029import uk .gov .gchq .gaffer .tinkerpop .util .GafferPopFederatedTestUtil ;
3130
3231import java .util .AbstractMap .SimpleEntry ;
32+ import java .util .Arrays ;
3333import java .util .List ;
3434import java .util .Map ;
3535import java .util .stream .Collectors ;
@@ -76,6 +76,11 @@ public class GafferPopFederatedIT {
7676 new SimpleEntry <>(T .label , PERSON_GROUP ),
7777 new SimpleEntry <>(NAME_PROPERTY , "person2Name" ))
7878 .collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue ));
79+ public static final Map <Object , Object > EXPECTED_PERSON_3_VERTEX_MAP = Stream .of (
80+ new SimpleEntry <>(T .id , "p3" ),
81+ new SimpleEntry <>(T .label , PERSON_GROUP ),
82+ new SimpleEntry <>(NAME_PROPERTY , "person3Name" ))
83+ .collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue ));
7984
8085 @ BeforeEach
8186 public void setUp () throws Exception {
@@ -96,7 +101,7 @@ void shouldConstructFederatedGafferPopGraph() {
96101 // Then
97102 assertThat (variables ).contains (
98103 entry ("userId" , USER_ID ),
99- entry ("dataAuths" , new String []{AUTH_1 , AUTH_2 }));
104+ entry ("dataAuths" , new String [] {AUTH_1 , AUTH_2 }));
100105 }
101106
102107 @ Test
@@ -212,15 +217,13 @@ void shouldGroupVerticesByLabelAndProvideCount() {
212217 }
213218
214219 @ Test
215- @ Disabled ("This does not currently work with federation" )
216220 void shouldGetEdgesById () {
217221 // Given
218222 GraphTraversalSource g = gafferPopGraph .traversal ();
219223
220224 // When
221225 List <Edge > result = g .E ("[p1, s1]" , "[p3, s1]" ).toList ();
222226
223- // Then
224227 assertThat (result )
225228 .extracting (item -> item .id ().toString ())
226229 .containsExactly ("[p1, s1]" , "[p3, s1]" );
@@ -274,4 +277,111 @@ void shouldTraverseEdgesFromVertexAndReturnNames() {
274277 .containsExactly (EXPECTED_PERSON_2_VERTEX_MAP .get ("name" ),
275278 EXPECTED_SOFTWARE_1_VERTEX_MAP .get ("name" ));
276279 }
280+
281+ @ Test
282+ void shouldReturnVerticesByLabelFromSpecificGraph () {
283+ // Given
284+ GraphTraversalSource g = gafferPopGraph .traversal ();
285+ final List <String > graphOptions = Arrays .asList ("gaffer.federatedstore.operation.graphIds:graphA" );
286+
287+ // When
288+ List <Map <Object , Object >> result = g .with (GafferPopGraphVariables .OP_OPTIONS , graphOptions ).V ()
289+ .hasLabel (PERSON_GROUP )
290+ .elementMap ().toList ();
291+
292+ // Then
293+ assertThat (result )
294+ .containsExactlyInAnyOrder (EXPECTED_PERSON_1_VERTEX_MAP , EXPECTED_PERSON_2_VERTEX_MAP ,
295+ EXPECTED_PERSON_3_VERTEX_MAP );
296+ }
297+
298+ @ Test
299+ void shouldReturnFilteredVerticesFromSpecificGraph () {
300+ // Given
301+ GraphTraversalSource g = gafferPopGraph .traversal ();
302+ final List <String > graphOptions = Arrays .asList ("gaffer.federatedstore.operation.graphIds:graphA" );
303+
304+ // When
305+ List <Object > result = g .with (GafferPopGraphVariables .OP_OPTIONS , graphOptions ).V ()
306+ .outE (CREATED_EDGE_GROUP ).has (WEIGHT_PROPERTY , P .gt (0.2 ))
307+ .values (WEIGHT_PROPERTY )
308+ .toList ();
309+
310+ // Then
311+ assertThat (result )
312+ .containsExactly (0.4 );
313+ }
314+
315+ @ Test
316+ void shouldGroupVerticesByLabelAndProvideCountFromSpecificGraph () {
317+ // Given
318+ GraphTraversalSource g = gafferPopGraph .traversal ();
319+ final List <String > graphOptions = Arrays .asList ("gaffer.federatedstore.operation.graphIds:graphB" );
320+
321+ // When
322+ List <Map <Object , Long >> result = g .with (GafferPopGraphVariables .OP_OPTIONS , graphOptions ).V ().groupCount ()
323+ .by (T .label ).toList ();
324+
325+ assertThat (result )
326+ .first ()
327+ .hasFieldOrPropertyWithValue (PERSON_GROUP , 1L )
328+ .hasFieldOrPropertyWithValue (SOFTWARE_GROUP , 1L );
329+ }
330+
331+ @ Test
332+ void shouldGetEdgesByIdFromSpecificGraph () {
333+ // Given
334+ GraphTraversalSource g = gafferPopGraph .traversal ();
335+ final List <String > graphOptions = Arrays .asList ("gaffer.federatedstore.operation.graphIds:graphB" );
336+
337+ // When
338+ List <Edge > result = g .with (GafferPopGraphVariables .OP_OPTIONS , graphOptions ).E ("[p4, s2]" ).toList ();
339+
340+ assertThat (result )
341+ .extracting (item -> item .id ().toString ())
342+ .containsExactly ("[p4, s2]" );
343+
344+ assertThat (result )
345+ .extracting (item -> item .label ())
346+ .containsExactly (CREATED_EDGE_GROUP );
347+ }
348+
349+ @ Test
350+ void shouldGetOutgoingEdgesFromSpecificGraph () {
351+ // Given
352+ GraphTraversalSource g = gafferPopGraph .traversal ();
353+ final List <String > graphOptions = Arrays .asList ("gaffer.federatedstore.operation.graphIds:graphB" );
354+
355+ // When
356+ List <Edge > result = g .with (GafferPopGraphVariables .OP_OPTIONS , graphOptions ).V ("p4" ).outE ().toList ();
357+
358+ // Then
359+ assertThat (result )
360+ .extracting (item -> item .id ().toString ())
361+ .containsExactly ("[p4, s2]" );
362+
363+ assertThat (result )
364+ .extracting (item -> item .label ())
365+ .containsExactly (CREATED_EDGE_GROUP );
366+ }
367+
368+ @ Test
369+ void shouldGetIncomingEdgesFromSpecificGraph () {
370+ // Given
371+ GraphTraversalSource g = gafferPopGraph .traversal ();
372+ final List <String > graphOptions = Arrays .asList ("gaffer.federatedstore.operation.graphIds:graphA" );
373+
374+ // When
375+ List <Edge > result = g .with (GafferPopGraphVariables .OP_OPTIONS , graphOptions ).V (VERTEX_PERSON_1 ).outE ()
376+ .toList ();
377+
378+ // Then
379+ assertThat (result )
380+ .extracting (item -> item .id ().toString ())
381+ .containsExactlyInAnyOrder ("[p1, p2]" , "[p1, s1]" );
382+
383+ assertThat (result )
384+ .extracting (item -> item .label ())
385+ .containsExactlyInAnyOrder (CREATED_EDGE_GROUP , "knows" );
386+ }
277387}
0 commit comments