use of com.jayway.restassured.response.Headers in project newrelic-java-agent by newrelic.
the class SprayHttpRoutesTest method testSimpleRouteFutureCAT.
@Test
public void testSimpleRouteFutureCAT() throws UnsupportedEncodingException {
String idHeader = Obfuscator.obfuscateNameUsingKey("1xyz234#1xyz3333", "cafebabedeadbeef8675309babecafe1beefdead");
ValidatableResponse response = given().header(HeadersUtil.NEWRELIC_ID_HEADER, idHeader).baseUri("http://localhost:" + server.getPort()).when().get("/simple/route/future?query=value").then().body(containsString("Simple Route Future"));
Headers responseHeaders = response.extract().headers();
Assert.assertTrue(responseHeaders.hasHeaderWithName(HeadersUtil.NEWRELIC_APP_DATA_HEADER));
Introspector introspector = InstrumentationTestRunner.getIntrospector();
Assert.assertEquals(1, introspector.getFinishedTransactionCount(DEFAULT_TIMEOUT_MILLIS));
Assert.assertTrue(introspector.getTransactionNames().toString(), introspector.getTransactionNames().contains(getTransactionPrefix() + "/simple/route/future"));
}
use of com.jayway.restassured.response.Headers in project newrelic-java-agent by newrelic.
the class AkkaHttpRoutesTest method testSimpleRouteCAT.
@Test
public void testSimpleRouteCAT() throws UnsupportedEncodingException {
String idHeader = Obfuscator.obfuscateNameUsingKey("1xyz234#1xyz3333", "cafebabedeadbeef8675309babecafe1beefdead");
ValidatableResponse response = given().header(HeadersUtil.NEWRELIC_ID_HEADER, idHeader).baseUri("http://localhost:" + server.getPort()).when().get("/simple/route?query=value").then().body(containsString("Simple Route"));
Headers responseHeaders = response.extract().headers();
Assert.assertTrue(responseHeaders.hasHeaderWithName(HeadersUtil.NEWRELIC_APP_DATA_HEADER));
Introspector introspector = InstrumentationTestRunner.getIntrospector();
Assert.assertEquals(1, introspector.getFinishedTransactionCount(TIMEOUT));
Assert.assertTrue(introspector.getTransactionNames().toString(), introspector.getTransactionNames().contains(getTransactionPrefix() + "/simple/route"));
Collection<TransactionEvent> transactionEvents = introspector.getTransactionEvents(introspector.getTransactionNames().toArray()[0].toString());
assertResponseCodeOnTxEvents(transactionEvents, 1, "200");
}
use of com.jayway.restassured.response.Headers in project dataverse by IQSS.
the class DownloadFilesIT method downloadFilenameUtf8.
/**
* Download a file with a UTF-8 filename with a space.
*/
@Test
public void downloadFilenameUtf8() throws IOException {
Response createUser = UtilIT.createRandomUser();
createUser.prettyPrint();
createUser.then().assertThat().statusCode(OK.getStatusCode());
String username = UtilIT.getUsernameFromResponse(createUser);
String apiToken = UtilIT.getApiTokenFromResponse(createUser);
Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken);
createDataverseResponse.prettyPrint();
createDataverseResponse.then().assertThat().statusCode(CREATED.getStatusCode());
String dataverseAlias = UtilIT.getAliasFromResponse(createDataverseResponse);
Response createDataset = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, apiToken);
createDataset.prettyPrint();
createDataset.then().assertThat().statusCode(CREATED.getStatusCode());
Integer datasetId = UtilIT.getDatasetIdFromResponse(createDataset);
String datasetPid = UtilIT.getDatasetPersistentIdFromResponse(createDataset);
// Put a filename with an en-dash ("MY READ–ME.md") into a zip file.
StringBuilder sb = new StringBuilder();
sb.append("This is my README.");
Path pathtoTempDir = Paths.get(Files.createTempDirectory(null).toString());
String pathToZipFile = pathtoTempDir + File.separator + "test.zip";
File f = new File(pathToZipFile);
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(f));
ZipEntry e = new ZipEntry("MY READ–ME.md");
out.putNextEntry(e);
byte[] data = sb.toString().getBytes();
out.write(data, 0, data.length);
out.closeEntry();
out.close();
// We upload via SWORD (as a zip) because the native API gives this error:
// "Constraint violation found in FileMetadata. File Name cannot contain any
// of the following characters: / : * ? " < > | ; # . The invalid value is "READ?ME.md"."
// This error probably has something to do with the way REST Assured sends the filename
// to the native API. The en-dash is turned into question mark, which is disallowed.
Response uploadViaSword = UtilIT.uploadZipFileViaSword(datasetPid, pathToZipFile, apiToken);
uploadViaSword.prettyPrint();
uploadViaSword.then().assertThat().statusCode(CREATED.getStatusCode());
Response getDatasetJson = UtilIT.nativeGet(datasetId, apiToken);
getDatasetJson.then().assertThat().statusCode(OK.getStatusCode());
int fileId = JsonPath.from(getDatasetJson.getBody().asString()).getInt("data.latestVersion.files[0].dataFile.id");
// Download the file individually and assert READ–ME.md has an en-dash.
Response downloadFile = UtilIT.downloadFile(new Integer(fileId), apiToken);
downloadFile.then().assertThat().statusCode(OK.getStatusCode());
Headers headers = downloadFile.getHeaders();
// In "MY READ–ME.md" below the space is %20 and the en-dash ("–") is "%E2%80%93" (e2 80 93 in hex).
Assert.assertEquals("attachment; filename=\"MY%20READ%E2%80%93ME.md\"", headers.getValue("Content-disposition"));
Assert.assertEquals("text/markdown; name=\"MY%20READ%E2%80%93ME.md\";charset=UTF-8", headers.getValue("Content-Type"));
// Download all files as a zip and assert "MY READ–ME.md" has an en-dash.
Response downloadFiles = UtilIT.downloadFiles(datasetPid, apiToken);
downloadFiles.then().assertThat().statusCode(OK.getStatusCode());
HashSet<String> filenamesFound = gatherFilenames(downloadFiles.getBody().asInputStream());
// Note that a MANIFEST.TXT file is added.
// "MY READ–ME.md" (with an en-dash) is correctly extracted from the downloaded zip
HashSet<String> expectedFiles = new HashSet<>(Arrays.asList("MANIFEST.TXT", "MY READ–ME.md"));
Assert.assertEquals(expectedFiles, filenamesFound);
}
use of com.jayway.restassured.response.Headers in project newrelic-java-agent by newrelic.
the class AkkaHttpRoutesTest method testSimpleRouteFutureCAT.
@Test
public void testSimpleRouteFutureCAT() throws UnsupportedEncodingException {
String idHeader = Obfuscator.obfuscateNameUsingKey("1xyz234#1xyz3333", "cafebabedeadbeef8675309babecafe1beefdead");
ValidatableResponse response = given().header(HeadersUtil.NEWRELIC_ID_HEADER, idHeader).baseUri("http://localhost:" + server.getPort()).when().get("/simple/route/future?query=value").then().body(containsString("Simple Route Future"));
Headers responseHeaders = response.extract().headers();
Assert.assertTrue(responseHeaders.hasHeaderWithName(HeadersUtil.NEWRELIC_APP_DATA_HEADER));
Introspector introspector = InstrumentationTestRunner.getIntrospector();
Assert.assertEquals(1, introspector.getFinishedTransactionCount(TIMEOUT));
Assert.assertTrue(introspector.getTransactionNames().toString(), introspector.getTransactionNames().contains(getTransactionPrefix() + "/simple/route/future"));
Collection<TransactionEvent> transactionEvents = introspector.getTransactionEvents(introspector.getTransactionNames().toArray()[0].toString());
assertResponseCodeOnTxEvents(transactionEvents, 1, "200");
}
use of com.jayway.restassured.response.Headers in project quality-measure-and-cohort-service by Alvearie.
the class DefaultVT method testCohortEvaluationFalse.
@Test
public void testCohortEvaluationFalse() {
final String RESOURCE = getUrlBase() + "/{version}/cohort-evaluation";
Assume.assumeTrue(isServiceDarkFeatureEnabled(CohortEngineRestConstants.DARK_LAUNCHED_VALUE_SET_UPLOAD));
// Create the metadata part of the request
CohortEvaluation requestData = new CohortEvaluation();
requestData.setDataServerConfig(dataServerConfig);
requestData.setTerminologyServerConfig(dataServerConfig);
requestData.setDefineToRun("Male");
requestData.setEntrypoint("cql/basic/Test-1.0.0.cql");
requestData.setPatientIds(VALID_PATIENT_ID);
RequestSpecification request = buildBaseRequest(new Headers()).queryParam(CohortEngineRestHandler.VERSION, ServiceBuildConstants.DATE).multiPart(CohortEngineRestHandler.REQUEST_DATA_PART, requestData, "application/json").multiPart(CohortEngineRestHandler.CQL_DEFINITION, new File("src/test/resources/cql/zip/Test-1.0.0.zip"));
ValidatableResponse response = request.post(RESOURCE, getServiceVersion()).then();
ValidatableResponse vr = runSuccessValidation(response, ContentType.JSON, HttpStatus.SC_OK);
CohortResult actual = vr.extract().response().getBody().as(CohortResult.class);
CohortResult expected = new CohortResult(Collections.emptyList());
assertEquals(expected, actual);
}
Aggregations