Jackson deserialization for ListFacetConfig

This commit is contained in:
Antonin Delpeuch 2018-10-21 19:26:12 +01:00
parent 121dd76fa1
commit 39498233fb
2 changed files with 17 additions and 6 deletions

View File

@ -118,6 +118,13 @@ public class ListFacet implements Facet {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@JsonProperty("selection")
public void setSelection(List<DecoratedValueWrapper> wrapped) {
selection = wrapped.stream()
.map(e -> e.value)
.collect(Collectors.toList());
}
@Override @Override
public void initializeFromJSON(JSONObject o) { public void initializeFromJSON(JSONObject o) {
name = o.getString("name"); name = o.getString("name");

View File

@ -1,14 +1,20 @@
package com.google.refine.tests.browsing.facets; package com.google.refine.tests.browsing.facets;
import java.io.IOException;
import org.json.JSONObject; import org.json.JSONObject;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.google.refine.browsing.Engine; import com.google.refine.browsing.Engine;
import com.google.refine.browsing.facets.Facet; import com.google.refine.browsing.facets.Facet;
import com.google.refine.browsing.facets.ListFacet.ListFacetConfig; import com.google.refine.browsing.facets.ListFacet.ListFacetConfig;
import com.google.refine.model.Project; import com.google.refine.model.Project;
import com.google.refine.tests.RefineTest; import com.google.refine.tests.RefineTest;
import com.google.refine.tests.util.TestUtils; import com.google.refine.tests.util.TestUtils;
import com.google.refine.util.ParsingUtilities;
public class ListFacetTests extends RefineTest { public class ListFacetTests extends RefineTest {
@ -66,14 +72,13 @@ public class ListFacetTests extends RefineTest {
} }
@Test @Test
public void serializeListFacet() { public void serializeListFacet() throws JsonParseException, JsonMappingException, IOException {
Project project = createCSVProject("Column A\n" + Project project = createCSVProject("Column A\n" +
"foo\n" + "foo\n" +
"bar\n"); "bar\n");
Engine engine = new Engine(project); Engine engine = new Engine(project);
ListFacetConfig facetConfig = new ListFacetConfig(); ListFacetConfig facetConfig = ParsingUtilities.mapper.readValue(jsonConfig, ListFacetConfig.class);
facetConfig.initializeFromJSON(new JSONObject(jsonConfig));
Facet facet = facetConfig.apply(project); Facet facet = facetConfig.apply(project);
facet.computeChoices(project, engine.getAllFilteredRows()); facet.computeChoices(project, engine.getAllFilteredRows());
@ -82,13 +87,12 @@ public class ListFacetTests extends RefineTest {
} }
@Test @Test
public void serializeListFacetWithError() { public void serializeListFacetWithError() throws JsonParseException, JsonMappingException, IOException {
Project project = createCSVProject("other column\n" + Project project = createCSVProject("other column\n" +
"foo\n" + "foo\n" +
"bar\n"); "bar\n");
ListFacetConfig facetConfig = new ListFacetConfig(); ListFacetConfig facetConfig = ParsingUtilities.mapper.readValue(jsonConfig, ListFacetConfig.class);
facetConfig.initializeFromJSON(new JSONObject(jsonConfig));
Facet facet = facetConfig.apply(project); Facet facet = facetConfig.apply(project);
TestUtils.isSerializedTo(facet, jsonFacetError); TestUtils.isSerializedTo(facet, jsonFacetError);
} }