Skip to content

Commit

Permalink
Fixed flaky tests in ListFacetTests (OpenRefine#6180)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThugJudy committed Nov 25, 2023
1 parent a68ba3b commit f329963
Showing 1 changed file with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@
package com.google.refine.browsing.facets;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.testng.annotations.Test;

import com.google.refine.RefineTest;
Expand Down Expand Up @@ -69,8 +74,8 @@ public class ListFacetTests extends RefineTest {
+ "\"columnName\":\"Column A\","
+ "\"invert\":false,"
+ "\"choices\":["
+ " {\"v\":{\"v\":\"foobar\",\"l\":\"foobar\"},\"c\":1,\"s\":true},"
+ " {\"v\":{\"v\":\"barbar\",\"l\":\"barbar\"},\"c\":1,\"s\":false}"
+ " {\"v\":{\"v\":\"barbar\",\"l\":\"barbar\"},\"c\":1,\"s\":false},"
+ " {\"v\":{\"v\":\"foobar\",\"l\":\"foobar\"},\"c\":1,\"s\":true}"
+ "]}";

private static String selectedEmptyChoiceFacet = "{"
Expand All @@ -79,9 +84,9 @@ public class ListFacetTests extends RefineTest {
+ "\"columnName\":\"Column A\","
+ "\"invert\":false,"
+ "\"choices\":["
+ " {\"v\":{\"v\":\"ebar\",\"l\":\"ebar\"},\"c\":1,\"s\":false},"
+ " {\"v\":{\"v\":\"cbar\",\"l\":\"cbar\"},\"c\":1,\"s\":false},"
+ " {\"v\":{\"v\":\"abar\",\"l\":\"abar\"},\"c\":1,\"s\":false},"
+ " {\"v\":{\"v\":\"cbar\",\"l\":\"cbar\"},\"c\":1,\"s\":false},"
+ " {\"v\":{\"v\":\"ebar\",\"l\":\"ebar\"},\"c\":1,\"s\":false},"
+ " {\"v\":{\"v\":\"foobar\",\"l\":\"true\"},\"c\":0,\"s\":true}"
+ "]}";

Expand All @@ -103,7 +108,14 @@ public void serializeListFacet() throws JsonParseException, JsonMappingException
Facet facet = facetConfig.apply(project);
facet.computeChoices(project, engine.getAllFilteredRows());

TestUtils.isSerializedTo(facet, jsonFacet);
ObjectNode actual = ParsingUtilities.mapper.valueToTree(facet);
List<JsonNode> choicesList = new ArrayList<>();

actual.findValues("choices").get(0).forEach(choicesList::add);
choicesList.sort(Comparator.comparing(JsonNode::toString));
actual.replace("choices", ParsingUtilities.mapper.createArrayNode().addAll(choicesList));

TestUtils.assertEqualsAsJson(actual.toString(), jsonFacet);
}

@Test
Expand All @@ -128,6 +140,14 @@ public void testSelectedEmptyChoice() throws IOException {
ListFacetConfig facetConfig = ParsingUtilities.mapper.readValue(jsonConfig, ListFacetConfig.class);
Facet facet = facetConfig.apply(project);
facet.computeChoices(project, engine.getAllFilteredRows());
TestUtils.isSerializedTo(facet, selectedEmptyChoiceFacet);

ObjectNode actual = ParsingUtilities.mapper.valueToTree(facet);
List<JsonNode> choicesList = new ArrayList<>();

actual.findValues("choices").get(0).forEach(choicesList::add);
choicesList.sort(Comparator.comparing(n -> n.get("v").toString()));
actual.replace("choices", ParsingUtilities.mapper.createArrayNode().addAll(choicesList));

TestUtils.assertEqualsAsJson(actual.toString(), selectedEmptyChoiceFacet);
}
}

0 comments on commit f329963

Please sign in to comment.