From 0bcd9cff8d5fbe3404c0610b32579ea611eaacf1 Mon Sep 17 00:00:00 2001 From: sitara-a Date: Mon, 28 Oct 2024 12:17:38 -0500 Subject: [PATCH 1/3] Fixing two flaky tests in AuthorisationsTest and ViewTest --- .../elementvisibilityutil/AuthorisationsTest.java | 5 +++-- .../gaffer/data/elementdefinition/view/ViewTest.java | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/core/common-util/src/test/java/uk/gov/gchq/gaffer/commonutil/elementvisibilityutil/AuthorisationsTest.java b/core/common-util/src/test/java/uk/gov/gchq/gaffer/commonutil/elementvisibilityutil/AuthorisationsTest.java index 7fc9fefd53e..3edc071e6a9 100644 --- a/core/common-util/src/test/java/uk/gov/gchq/gaffer/commonutil/elementvisibilityutil/AuthorisationsTest.java +++ b/core/common-util/src/test/java/uk/gov/gchq/gaffer/commonutil/elementvisibilityutil/AuthorisationsTest.java @@ -113,7 +113,8 @@ void testUnmodifiableList() { @Test void testToString() { final Authorisations a = new Authorisations("a", "abcdefg", "hijklmno"); - - assertThat(a).hasToString("a,hijklmno,abcdefg"); + assertThat(a.toString()).contains("a"); + assertThat(a.toString()).contains("abcdefg"); + assertThat(a.toString()).contains("hijklmno"); } } diff --git a/core/data/src/test/java/uk/gov/gchq/gaffer/data/elementdefinition/view/ViewTest.java b/core/data/src/test/java/uk/gov/gchq/gaffer/data/elementdefinition/view/ViewTest.java index db63733bf74..d74fbd323e2 100644 --- a/core/data/src/test/java/uk/gov/gchq/gaffer/data/elementdefinition/view/ViewTest.java +++ b/core/data/src/test/java/uk/gov/gchq/gaffer/data/elementdefinition/view/ViewTest.java @@ -16,6 +16,8 @@ package uk.gov.gchq.gaffer.data.elementdefinition.view; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; import uk.gov.gchq.gaffer.JSONSerialisationTest; @@ -30,6 +32,7 @@ import uk.gov.gchq.koryphe.impl.function.Identity; import uk.gov.gchq.koryphe.impl.predicate.Exists; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -384,7 +387,7 @@ public void shouldCreateViewWithGlobalDefinitions() { } @Test - public void shouldCreateAnIdenticalObjectWhenCloned() { + public void shouldCreateAnIdenticalObjectWhenCloned() throws IOException { // Given final ViewElementDefinition edgeDef1 = new ViewElementDefinition(); final ViewElementDefinition edgeDef2 = new ViewElementDefinition(); @@ -408,8 +411,11 @@ public void shouldCreateAnIdenticalObjectWhenCloned() { final byte[] viewJson = view.toCompactJson(); final byte[] cloneJson = clone.toCompactJson(); + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode treeView = objectMapper.readTree(viewJson); + JsonNode treeClone = objectMapper.readTree(cloneJson); // Check that JSON representations of the objects are equal - assertThat(cloneJson).containsExactly(viewJson); + assertThat(treeClone).isEqualTo(treeView); final View viewFromJson = new View.Builder().json(viewJson).build(); final View cloneFromJson = new View.Builder().json(cloneJson).build(); From f76f138c99d6971d2c7ec0d9435ca9d5d61863b0 Mon Sep 17 00:00:00 2001 From: sitara-a Date: Tue, 29 Oct 2024 12:13:49 -0500 Subject: [PATCH 2/3] Fixing two flaky tests in AuthorisationsTest and ViewTest --- .../gov/gchq/gaffer/data/elementdefinition/view/ViewTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/data/src/test/java/uk/gov/gchq/gaffer/data/elementdefinition/view/ViewTest.java b/core/data/src/test/java/uk/gov/gchq/gaffer/data/elementdefinition/view/ViewTest.java index d74fbd323e2..b21ccd18244 100644 --- a/core/data/src/test/java/uk/gov/gchq/gaffer/data/elementdefinition/view/ViewTest.java +++ b/core/data/src/test/java/uk/gov/gchq/gaffer/data/elementdefinition/view/ViewTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 Crown Copyright + * Copyright 2016-2024 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 055c0a87d4e14ca211fbbc82a98cd1fd714952fa Mon Sep 17 00:00:00 2001 From: sitara-a Date: Sun, 17 Nov 2024 19:29:50 -0600 Subject: [PATCH 3/3] Fixed Flaky Test in ViewUtilTest --- .../data/elementdefinition/view/ViewUtilTest.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/data/src/test/java/uk/gov/gchq/gaffer/data/elementdefinition/view/ViewUtilTest.java b/core/data/src/test/java/uk/gov/gchq/gaffer/data/elementdefinition/view/ViewUtilTest.java index 8bed1b0f3e6..6affeeffb27 100644 --- a/core/data/src/test/java/uk/gov/gchq/gaffer/data/elementdefinition/view/ViewUtilTest.java +++ b/core/data/src/test/java/uk/gov/gchq/gaffer/data/elementdefinition/view/ViewUtilTest.java @@ -16,6 +16,8 @@ package uk.gov.gchq.gaffer.data.elementdefinition.view; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; import uk.gov.gchq.gaffer.commonutil.JsonAssert; @@ -29,6 +31,7 @@ import uk.gov.gchq.gaffer.function.ExampleTransformFunction; import uk.gov.gchq.koryphe.impl.predicate.Exists; +import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -36,7 +39,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; @@ -497,7 +499,7 @@ public void shouldCreateViewWithGlobalDefinitions() { } @Test - public void shouldCreateAnIdenticalObjectWhenCloned() { + public void shouldCreateAnIdenticalObjectWhenCloned() throws IOException{ // Given final ViewElementDefinition edgeDef1 = new ViewElementDefinition(); final ViewElementDefinition edgeDef2 = new ViewElementDefinition(); @@ -521,8 +523,13 @@ public void shouldCreateAnIdenticalObjectWhenCloned() { final byte[] viewJson = view.toCompactJson(); final byte[] cloneJson = clone.toCompactJson(); + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode treeView = objectMapper.readTree(viewJson); + JsonNode treeClone = objectMapper.readTree(cloneJson); + // Check that JSON representations of the objects are equal - assertArrayEquals(viewJson, cloneJson); + assertThat(treeView).isEqualTo(treeClone); + final View viewFromJson = new View.Builder().json(viewJson).build(); final View cloneFromJson = new View.Builder().json(cloneJson).build();