Add (de)serialization tests to existing operation test classes

This commit is contained in:
Antonin Delpeuch 2018-08-12 11:52:18 +01:00
parent dbff74650d
commit 4013c0b8c5
2 changed files with 54 additions and 4 deletions

View File

@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.google.refine.operations.column;
package com.google.refine.tests.operations.column;
import java.io.IOException;
import java.net.InetAddress;
@ -47,19 +47,22 @@ import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.refine.expr.ExpressionUtils;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Cell;
import com.google.refine.model.ModelException;
import com.google.refine.model.Project;
import com.google.refine.model.Row;
import com.google.refine.operations.EngineDependentOperation;
import com.google.refine.operations.OnError;
import com.google.refine.operations.OperationRegistry;
import com.google.refine.operations.column.ColumnAdditionByFetchingURLsOperation;
import com.google.refine.process.Process;
import com.google.refine.process.ProcessManager;
import com.google.refine.tests.RefineTest;
import com.google.refine.tests.util.TestUtils;
public class UrlFetchingTests extends RefineTest {
public class ColumnAdditionByFetchingURLsOperationTests extends RefineTest {
static final String ENGINE_JSON_URLS = "{\"mode\":\"row-based\"}}";
@ -67,6 +70,7 @@ public class UrlFetchingTests extends RefineTest {
@BeforeTest
public void init() {
logger = LoggerFactory.getLogger(this.getClass());
OperationRegistry.registerOperation(getCoreModule(), "column-addition-by-fetching-urls", ColumnAdditionByFetchingURLsOperation.class);
}
// dependencies
@ -91,6 +95,26 @@ public class UrlFetchingTests extends RefineTest {
return state;
}
@Test
public void serializeColumnAdditionByFetchingURLsOperation() throws JSONException, Exception {
String json = "{\"op\":\"core/column-addition-by-fetching-urls\","
+ "\"description\":\"Create column employments at index 2 by fetching URLs based on column orcid using expression grel:\\\"https://pub.orcid.org/\\\"+value+\\\"/employments\\\"\","
+ "\"engineConfig\":{\"mode\":\"row-based\",\"facets\":[]},"
+ "\"newColumnName\":\"employments\","
+ "\"columnInsertIndex\":2,"
+ "\"baseColumnName\":\"orcid\","
+ "\"urlExpression\":\"grel:\\\"https://pub.orcid.org/\\\"+value+\\\"/employments\\\"\","
+ "\"onError\":\"set-to-blank\","
+ "\"delay\":500,"
+ "\"cacheResponses\":true,"
+ "\"httpHeadersJson\":["
+ " {\"name\":\"authorization\",\"value\":\"\"},"
+ " {\"name\":\"user-agent\",\"value\":\"OpenRefine 3.0 rc.1 [TRUNK]\"},"
+ " {\"name\":\"accept\",\"value\":\"application/json\"}"
+ "]}";
TestUtils.isSerializedTo(ColumnAdditionByFetchingURLsOperation.reconstruct(project, new JSONObject(json)), json);
}
/**
* Test for caching
*/

View File

@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.google.refine.tests.recon;
package com.google.refine.tests.operations.recon;
import static org.mockito.Mockito.mock;
@ -59,11 +59,13 @@ import com.google.refine.model.Row;
import com.google.refine.process.Process;
import com.google.refine.process.ProcessManager;
import com.google.refine.operations.EngineDependentOperation;
import com.google.refine.operations.OperationRegistry;
import com.google.refine.operations.recon.ExtendDataOperation;
import com.google.refine.tests.RefineTest;
import com.google.refine.tests.util.TestUtils;
public class DataExtensionTests extends RefineTest {
public class ExtendDataOperationTests extends RefineTest {
static final String ENGINE_JSON_URLS = "{\"mode\":\"row-based\"}}";
static final String RECON_SERVICE = "https://tools.wmflabs.org/openrefine-wikidata/en/api";
@ -84,6 +86,7 @@ public class DataExtensionTests extends RefineTest {
@BeforeMethod
public void SetUp() throws JSONException, IOException, ModelException {
OperationRegistry.registerOperation(getCoreModule(), "extend-reconciled-data", ExtendDataOperation.class);
project = createProjectWithColumns("DataExtensionTests", "country");
options = mock(Properties.class);
@ -106,6 +109,29 @@ public class DataExtensionTests extends RefineTest {
project.rows.add(row);
}
@Test
public void serializeExtendDataOperation() throws JSONException, Exception {
String json = "{\"op\":\"core/extend-reconciled-data\","
+ "\"description\":\"Extend data at index 3 based on column organization_name\","
+ "\"engineConfig\":{\"mode\":\"row-based\",\"facets\":["
+ " {\"selectNumeric\":true,\"expression\":\"cell.recon.best.score\",\"selectBlank\":false,\"selectNonNumeric\":true,\"selectError\":true,\"name\":\"organization_name: best candidate's score\",\"from\":13,\"to\":101,\"type\":\"range\",\"columnName\":\"organization_name\"},"
+ " {\"selectNonTime\":true,\"expression\":\"grel:toDate(value)\",\"selectBlank\":true,\"selectError\":true,\"selectTime\":true,\"name\":\"start_year\",\"from\":410242968000,\"to\":1262309184000,\"type\":\"timerange\",\"columnName\":\"start_year\"}"
+ "]},"
+ "\"columnInsertIndex\":3,"
+ "\"baseColumnName\":\"organization_name\","
+ "\"endpoint\":\"https://tools.wmflabs.org/openrefine-wikidata/en/api\","
+ "\"identifierSpace\":\"http://www.wikidata.org/entity/\","
+ "\"schemaSpace\":\"http://www.wikidata.org/prop/direct/\","
+ "\"extension\":{"
+ " \"properties\":["
+ " {\"name\":\"inception\",\"id\":\"P571\"},"
+ " {\"name\":\"headquarters location\",\"id\":\"P159\"},"
+ " {\"name\":\"coordinate location\",\"id\":\"P625\"}"
+ " ]"
+ "}}";
TestUtils.isSerializedTo(ExtendDataOperation.reconstruct(project, new JSONObject(json)), json);
}
@AfterMethod
public void TearDown() {
project = null;