Resolved merge conflict

This commit is contained in:
Owen Stephens 2018-01-16 17:41:56 +00:00
parent 5acdb1429c
commit 4320ef8c10

View File

@ -42,6 +42,7 @@ import java.util.Properties;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.json.JSONArray;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterMethod;
@ -207,6 +208,7 @@ public class UrlFetchingTests extends RefineTest {
50, 50,
true, true,
null); null);
ProcessManager pm = project.getProcessManager(); ProcessManager pm = project.getProcessManager();
Process process = op.createProcess(project, options); Process process = op.createProcess(project, options);
process.startPerforming(pm); process.startPerforming(pm);
@ -225,4 +227,59 @@ public class UrlFetchingTests extends RefineTest {
Assert.assertTrue(ExpressionUtils.isError(project.rows.get(2).getCellValue(newCol))); Assert.assertTrue(ExpressionUtils.isError(project.rows.get(2).getCellValue(newCol)));
} }
@Test
public void testHttpHeaders() throws Exception {
Row row0 = new Row(2);
row0.setCell(0, new Cell("http://headers.jsontest.com", null));
/*
http://headers.jsontest.com is a service which returns the HTTP request headers
as JSON. For example:
{
"X-Cloud-Trace-Context": "579a1a2ee5c778dfc0810a3bf131ba4e/11053223648711966807",
"Authorization": "Basic",
"Host": "headers.jsontest.com",
"User-Agent": "OpenRefine",
"Accept": "*"
}
*/
project.rows.add(row0);
String userAgentValue = "OpenRefine";
String authorizationValue = "Basic";
String acceptValue = "*/*";
String jsonString = "[{\"name\": \"authorization\",\"value\": \""+authorizationValue+
"\"},{\"name\": \"user-agent\",\"value\": \""+userAgentValue+
"\"},{\"name\": \"accept\",\"value\": \""+acceptValue+"\"}]";
JSONArray httpHeadersJson = new JSONArray(jsonString);
EngineDependentOperation op = new ColumnAdditionByFetchingURLsOperation(engine_config,
"fruits",
"value",
OnError.StoreError,
"junk",
1,
50,
true,
httpHeadersJson);
ProcessManager pm = project.getProcessManager();
Process process = op.createProcess(project, options);
process.startPerforming(pm);
Assert.assertTrue(process.isRunning());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
Assert.fail("Test interrupted");
}
Assert.assertFalse(process.isRunning());
int newCol = project.columnModel.getColumnByName("junk").getCellIndex();
JSONObject headersUsed = new JSONObject(project.rows.get(0).getCellValue(newCol).toString());
// Inspect the results we got from remote service
Assert.assertEquals(headersUsed.getString("User-Agent"), userAgentValue);
Assert.assertEquals(headersUsed.getString("Authorization"), authorizationValue);
Assert.assertEquals(headersUsed.getString("Accept"), acceptValue);
}
} }