Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing three flaky tests in AuthorisationsTest and ViewTest #3327

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,14 +31,14 @@
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;
import java.util.Set;

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;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down