Skip to content

Commit b2bca5e

Browse files
Gh-3120: Improved testing of matchedVertex (#3131)
Co-authored-by: GCHQDeveloper314 <94527357+GCHQDeveloper314@users.noreply.github.com>
1 parent ffd66d7 commit b2bca5e

File tree

11 files changed

+111
-77
lines changed

11 files changed

+111
-77
lines changed

core/data/src/test/java/uk/gov/gchq/gaffer/data/util/ElementUtil.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 Crown Copyright
2+
* Copyright 2016-2024 Crown Copyright
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,4 +43,21 @@ public static void assertElementEquals(final Iterable<? extends ElementId> expec
4343
assertThat(resultCache).containsExactlyInAnyOrderElementsOf(expectedCache);
4444
}
4545
}
46+
47+
public static void assertElementEqualsIncludingMatchedVertex(final Iterable<? extends ElementId> expected, final Iterable<? extends ElementId> result) {
48+
assertElementEqualsIncludingMatchedVertex(expected, result, false);
49+
}
50+
51+
@SuppressWarnings("unchecked")
52+
public static void assertElementEqualsIncludingMatchedVertex(final Iterable<? extends ElementId> expected, final Iterable<? extends ElementId> result, final boolean ignoreDuplicates) {
53+
if (ignoreDuplicates) {
54+
assertThat((Iterable<ElementId>) result)
55+
.usingRecursiveFieldByFieldElementComparator()
56+
.hasSameElementsAs((Iterable<ElementId>) expected);
57+
} else {
58+
assertThat((Iterable<ElementId>) result)
59+
.usingRecursiveFieldByFieldElementComparator()
60+
.containsExactlyInAnyOrderElementsOf((Iterable<ElementId>) expected);
61+
}
62+
}
4663
}

core/store/src/test/java/uk/gov/gchq/gaffer/store/operation/handler/function/FilterHandlerTest.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2021 Crown Copyright
2+
* Copyright 2017-2024 Crown Copyright
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package uk.gov.gchq.gaffer.store.operation.handler.function;
1718

1819
import com.google.common.collect.Lists;
@@ -707,7 +708,7 @@ public void shouldFilterBasedOnMatchedVertex() throws OperationException {
707708
final Iterable<? extends Element> results = handler.doOperation(filter, context, store);
708709

709710
// Then
710-
ElementUtil.assertElementEquals(
711+
ElementUtil.assertElementEqualsIncludingMatchedVertex(
711712
Arrays.asList(new Edge.Builder()
712713
.group(TestGroups.EDGE)
713714
.source("srcVal1")
@@ -718,7 +719,7 @@ public void shouldFilterBasedOnMatchedVertex() throws OperationException {
718719
.group(TestGroups.EDGE)
719720
.source("srcVal3")
720721
.dest("destVal3")
721-
.matchedVertex(EdgeId.MatchedVertex.SOURCE)
722+
.matchedVertex(EdgeId.MatchedVertex.DESTINATION)
722723
.build()),
723724
results);
724725
}
@@ -774,7 +775,7 @@ public void shouldFilterBasedOnAdjacentMatchedVertex() throws OperationException
774775
final Iterable<? extends Element> results = handler.doOperation(filter, context, store);
775776

776777
// Then
777-
ElementUtil.assertElementEquals(
778+
ElementUtil.assertElementEqualsIncludingMatchedVertex(
778779
Arrays.asList(new Edge.Builder()
779780
.group(TestGroups.EDGE)
780781
.source("srcVal1")
@@ -785,7 +786,7 @@ public void shouldFilterBasedOnAdjacentMatchedVertex() throws OperationException
785786
.group(TestGroups.EDGE)
786787
.source("srcVal3")
787788
.dest("destVal3")
788-
.matchedVertex(EdgeId.MatchedVertex.SOURCE)
789+
.matchedVertex(EdgeId.MatchedVertex.DESTINATION)
789790
.build()),
790791
results);
791792
}

core/store/src/test/java/uk/gov/gchq/gaffer/store/operation/handler/function/TransformHandlerTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2021 Crown Copyright
2+
* Copyright 2017-2024 Crown Copyright
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package uk.gov.gchq.gaffer.store.operation.handler.function;
1718

1819
import com.google.common.collect.Lists;
@@ -470,7 +471,7 @@ public void shouldSelectMatchedVertexForTransform() throws OperationException {
470471
.matchedVertex(EdgeId.MatchedVertex.SOURCE)
471472
.property(TestPropertyNames.PROP_3, "srcVal")
472473
.build();
473-
ElementUtil.assertElementEquals(Collections.singletonList(expectedEdge), results);
474+
ElementUtil.assertElementEqualsIncludingMatchedVertex(Collections.singletonList(expectedEdge), results);
474475
}
475476

476477
@Test
@@ -505,6 +506,6 @@ public void shouldSelectAdjacentMatchedVertexForTransform() throws OperationExce
505506
.matchedVertex(EdgeId.MatchedVertex.SOURCE)
506507
.property(TestPropertyNames.PROP_3, "destVal")
507508
.build();
508-
ElementUtil.assertElementEquals(Collections.singletonList(expectedEdge), results);
509+
ElementUtil.assertElementEqualsIncludingMatchedVertex(Collections.singletonList(expectedEdge), results);
509510
}
510511
}

core/store/src/test/java/uk/gov/gchq/gaffer/store/util/AggregatorUtilTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2021 Crown Copyright
2+
* Copyright 2017-2024 Crown Copyright
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -55,6 +55,8 @@
5555
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
5656
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
5757
import static uk.gov.gchq.gaffer.data.util.ElementUtil.assertElementEquals;
58+
import static uk.gov.gchq.gaffer.data.util.ElementUtil.assertElementEqualsIncludingMatchedVertex;
59+
5860

5961
public class AggregatorUtilTest {
6062
@Test
@@ -1007,7 +1009,7 @@ public void shouldQueryAggregateDirectedEdgesIncludingMatchedVertexGroupBy() {
10071009
final Iterable<Element> aggregatedElementsIncludingMatchedVertex = AggregatorUtil.queryAggregate(elements, schema, view, true);
10081010

10091011
// then
1010-
assertElementEquals(expectedIncludingMatchedVertex, aggregatedElementsIncludingMatchedVertex);
1012+
assertElementEqualsIncludingMatchedVertex(expectedIncludingMatchedVertex, aggregatedElementsIncludingMatchedVertex);
10111013
}
10121014

10131015
@Test

integration-test/src/test/java/uk/gov/gchq/gaffer/integration/impl/GeneratorsIT.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 Crown Copyright
2+
* Copyright 2016-2024 Crown Copyright
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -88,7 +88,7 @@ public void shouldConvertFromDomainObjects() throws OperationException {
8888
.first(new GenerateElements.Builder<DomainObject>()
8989
.generator(new BasicElementGenerator())
9090
.input(new EntityDomainObject(NEW_VERTEX, "1", null),
91-
new EdgeDomainObject(NEW_SOURCE, NEW_DEST, false, 1, 1L))
91+
new EdgeDomainObject(NEW_SOURCE, NEW_DEST, true, 1, 1L))
9292
.build())
9393
.then(new AddElements())
9494
.build();
@@ -98,22 +98,22 @@ public void shouldConvertFromDomainObjects() throws OperationException {
9898

9999
// Then - check they were added correctly
100100
final List<Element> results = Lists.newArrayList(graph.execute(new GetElements.Builder()
101-
.input(new EntitySeed(NEW_VERTEX), new EdgeSeed(NEW_SOURCE, NEW_DEST, false))
101+
.input(new EntitySeed(NEW_VERTEX), new EdgeSeed(NEW_SOURCE, NEW_DEST, true))
102102
.build(), getUser()));
103103

104104
final Edge expectedEdge = new Edge.Builder()
105105
.group(TestGroups.EDGE)
106106
.source(NEW_SOURCE)
107107
.dest(NEW_DEST)
108-
.directed(false)
109-
.matchedVertex(EdgeId.MatchedVertex.DESTINATION)
108+
.directed(true)
109+
.matchedVertex(EdgeId.MatchedVertex.SOURCE)
110110
.build();
111111
expectedEdge.putProperty(TestPropertyNames.INT, 1);
112112
expectedEdge.putProperty(TestPropertyNames.COUNT, 1L);
113113

114114
final Entity expectedEntity = new Entity(TestGroups.ENTITY, NEW_VERTEX);
115115
expectedEntity.putProperty(TestPropertyNames.SET, CollectionUtil.treeSet("1"));
116116

117-
ElementUtil.assertElementEquals(Arrays.asList(expectedEntity, expectedEdge), results);
117+
ElementUtil.assertElementEqualsIncludingMatchedVertex(Arrays.asList(expectedEntity, expectedEdge), results);
118118
}
119119
}

integration-test/src/test/java/uk/gov/gchq/gaffer/integration/impl/GetElementsIT.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 Crown Copyright
2+
* Copyright 2016-2024 Crown Copyright
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -193,7 +193,7 @@ public void shouldGetAllEdgesWhenFlagSet() throws Exception {
193193
final Iterable<? extends Element> resultsIncludingAllEdges = graph.execute(opIncludingAllEdges, user);
194194

195195
// Then
196-
ElementUtil.assertElementEquals(Arrays.asList(
196+
ElementUtil.assertElementEqualsIncludingMatchedVertex(Arrays.asList(
197197
new Edge.Builder()
198198
.group(TestGroups.EDGE)
199199
.source(SOURCE_1)
@@ -238,7 +238,7 @@ public void shouldGetAllEntitiesWhenFlagSet() throws OperationException {
238238
final Iterable<? extends Element> resultsExcludingAllEntities = graph.execute(opExcludingAllEntities, user);
239239

240240
// Then
241-
ElementUtil.assertElementEquals(Arrays.asList(
241+
ElementUtil.assertElementEqualsIncludingMatchedVertex(Arrays.asList(
242242
new Edge.Builder()
243243
.group(TestGroups.EDGE)
244244
.source(SOURCE_1)
@@ -297,7 +297,7 @@ public void shouldGetElementsWithMatchedVertex() throws Exception {
297297
final Iterable<? extends Element> results = graph.execute(op, user);
298298

299299
// Then
300-
ElementUtil.assertElementEquals(Arrays.asList(
300+
ElementUtil.assertElementEqualsIncludingMatchedVertex(Arrays.asList(
301301
new Edge.Builder()
302302
.group(TestGroups.EDGE)
303303
.source(SOURCE_DIR_1)
@@ -350,7 +350,7 @@ public void shouldGetElementsWithMatchedVertexFilter() throws Exception {
350350
final Iterable<? extends Element> results = graph.execute(op, user);
351351

352352
// Then
353-
ElementUtil.assertElementEquals(Arrays.asList(
353+
ElementUtil.assertElementEqualsIncludingMatchedVertex(Arrays.asList(
354354
new Edge.Builder()
355355
.group(TestGroups.EDGE)
356356
.source(SOURCE_DIR_1)
@@ -652,8 +652,13 @@ private void shouldGetElements(final Collection<Element> expectedElements,
652652
final Iterable<? extends Element> resultsElement = graph.execute(opElement, user);
653653

654654
// Then
655-
ElementUtil.assertElementEquals(expectedElements, resultsSeed, true);
656-
ElementUtil.assertElementEquals(expectedElements, resultsElement, true);
655+
if (includeEdges && inOutType == IncludeIncomingOutgoingType.INCOMING) {
656+
ElementUtil.assertElementEquals(expectedElements, resultsSeed, true);
657+
ElementUtil.assertElementEquals(expectedElements, resultsElement, true);
658+
} else {
659+
ElementUtil.assertElementEqualsIncludingMatchedVertex(expectedElements, resultsSeed, true);
660+
ElementUtil.assertElementEqualsIncludingMatchedVertex(expectedElements, resultsElement, true);
661+
}
657662
}
658663

659664
private static Collection<Element> getElements(final Collection<ElementId> seeds, final Boolean direction) {

integration-test/src/test/java/uk/gov/gchq/gaffer/integration/impl/SchemaMigrationIT.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2023 Crown Copyright
2+
* Copyright 2018-2024 Crown Copyright
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -517,7 +517,7 @@ public void shouldCorrectlyApplyPostAggFiltering() throws OperationException {
517517
new User());
518518

519519
// Then
520-
ElementUtil.assertElementEquals(
520+
ElementUtil.assertElementEqualsIncludingMatchedVertex(
521521
Arrays.asList(
522522
EDGE_OLD_AGGREGATION_ALT_COUNT_MIGRATED_TO_NEW
523523
),
@@ -557,7 +557,7 @@ public void shouldApplyPostOpAggregation() throws OperationException {
557557
new User());
558558

559559
// Then
560-
ElementUtil.assertElementEquals(
560+
ElementUtil.assertElementEqualsIncludingMatchedVertex(
561561
Arrays.asList(
562562
EDGE_NEW_POST_OP_AGGREGATION_AGGREGATED
563563
),

store-implementation/accumulo-store/src/main/java/uk/gov/gchq/gaffer/accumulostore/retriever/impl/AccumuloElementsRetriever.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 Crown Copyright
2+
* Copyright 2016-2024 Crown Copyright
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@
1818

1919
import uk.gov.gchq.gaffer.accumulostore.AccumuloStore;
2020
import uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException;
21-
import uk.gov.gchq.gaffer.data.element.id.EdgeId;
21+
import uk.gov.gchq.gaffer.data.element.id.EntityId;
2222
import uk.gov.gchq.gaffer.operation.impl.get.GetElements;
2323
import uk.gov.gchq.gaffer.store.StoreException;
2424
import uk.gov.gchq.gaffer.user.User;
@@ -31,8 +31,8 @@ public AccumuloElementsRetriever(final AccumuloStore store,
3131
final User user)
3232
throws IteratorSettingException, StoreException {
3333
super(store, operation, user,
34-
// includeMatchedVertex if input only contains EntityIds
35-
StreamSupport.stream(operation.getInput().spliterator(), false).noneMatch(input -> EdgeId.class.isInstance(input)),
34+
// includeMatchedVertex if any input are EntityIds
35+
StreamSupport.stream(operation.getInput().spliterator(), false).anyMatch(EntityId.class::isInstance),
3636
store.getKeyPackage().getIteratorFactory().getElementPreAggregationFilterIteratorSetting(operation.getView(), store),
3737
store.getKeyPackage().getIteratorFactory().getElementPostAggregationFilterIteratorSetting(operation.getView(), store),
3838
store.getKeyPackage().getIteratorFactory().getEdgeEntityDirectionFilterIteratorSetting(operation),

store-implementation/accumulo-store/src/test/java/uk/gov/gchq/gaffer/accumulostore/key/AbstractAccumuloElementConverterTest.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 Crown Copyright
2+
* Copyright 2016-2024 Crown Copyright
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package uk.gov.gchq.gaffer.accumulostore.key;
1718

1819
import org.apache.accumulo.core.data.Key;
@@ -479,7 +480,7 @@ public void shouldThrowExceptionWhenGetPropertiesFromTimestampWhenGroupIsNotFoun
479480

480481
@Test
481482
public void shouldSerialiseAndDeserialisePropertiesWhenAllAreEmpty() {
482-
// Given
483+
// Given
483484
final Schema schema = new Schema.Builder()
484485
.entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder()
485486
.vertex("string")
@@ -503,7 +504,7 @@ public void shouldSerialiseAndDeserialisePropertiesWhenAllAreEmpty() {
503504
.property(TestPropertyNames.PROP_2, new FreqMap())
504505
.build();
505506

506-
// When 1
507+
// When 1
507508
final Value value = converter.getValueFromProperties(TestGroups.ENTITY, entity.getProperties());
508509

509510
// Then 1
@@ -519,7 +520,7 @@ public void shouldSerialiseAndDeserialisePropertiesWhenAllAreEmpty() {
519520

520521
@Test
521522
public void shouldDeserialiseEntityId() {
522-
// Given
523+
// Given
523524
final EntityId expectedElementId = new EntitySeed("vertex1");
524525
final Entity entity = new Entity.Builder()
525526
.vertex("vertex1")
@@ -538,7 +539,7 @@ public void shouldDeserialiseEntityId() {
538539

539540
@Test
540541
public void shouldDeserialiseEdgeId() {
541-
// Given
542+
// Given
542543
final EdgeId expectedElementId = new EdgeSeed("source1", "dest1", true);
543544
final Edge edge = new Edge.Builder()
544545
.source("source1")
@@ -559,7 +560,7 @@ public void shouldDeserialiseEdgeId() {
559560

560561
@Test
561562
public void shouldDeserialiseEdgeIdWithQueriedDestVertex() {
562-
// Given
563+
// Given
563564
final EdgeId expectedElementId = new EdgeSeed("vertex1", "vertex2", true, EdgeId.MatchedVertex.DESTINATION);
564565
final Edge edge = new Edge.Builder()
565566
.source("vertex1")
@@ -581,7 +582,7 @@ public void shouldDeserialiseEdgeIdWithQueriedDestVertex() {
581582

582583
@Test
583584
public void shouldDeserialiseEdgeIdWithQueriedSourceVertex() {
584-
// Given
585+
// Given
585586
final EdgeId expectedElementId = new EdgeSeed("source1", "dest1", true);
586587
final Edge edge = new Edge.Builder()
587588
.source("source1")

store-implementation/accumulo-store/src/test/java/uk/gov/gchq/gaffer/accumulostore/key/core/AbstractCoreKeyAccumuloElementConverterTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2020 Crown Copyright
2+
* Copyright 2017-2024 Crown Copyright
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package uk.gov.gchq.gaffer.accumulostore.key.core;
1718

1819
import com.google.common.primitives.Bytes;
@@ -69,7 +70,7 @@ public void shouldReturnOverriddenSerialiseNull() throws Exception {
6970

7071
@Test
7172
public void shouldDeserialiseSourceDestinationValuesCorrectWayRound() {
72-
// Given
73+
// Given
7374
final Edge edge = new Edge.Builder()
7475
.source("1")
7576
.dest("2")
@@ -109,7 +110,7 @@ public void shouldDeserialiseSourceDestinationValuesIncorrectWayRound() {
109110

110111
@Test
111112
public void shouldDeserialiseSourceDestinationValuesUndirected() {
112-
// Given
113+
// Given
113114
final Edge edge = new Edge.Builder()
114115
.source("1")
115116
.dest("2")

0 commit comments

Comments
 (0)