Search in sources :

Example 6 with Headers

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"));
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) Headers(com.jayway.restassured.response.Headers) Introspector(com.newrelic.agent.introspec.Introspector) Matchers.containsString(org.hamcrest.Matchers.containsString) Java13IncompatibleTest(com.newrelic.test.marker.Java13IncompatibleTest) Java16IncompatibleTest(com.newrelic.test.marker.Java16IncompatibleTest) Java17IncompatibleTest(com.newrelic.test.marker.Java17IncompatibleTest) Java14IncompatibleTest(com.newrelic.test.marker.Java14IncompatibleTest) Test(org.junit.Test) Java11IncompatibleTest(com.newrelic.test.marker.Java11IncompatibleTest) Java15IncompatibleTest(com.newrelic.test.marker.Java15IncompatibleTest) Java12IncompatibleTest(com.newrelic.test.marker.Java12IncompatibleTest)

Example 7 with Headers

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");
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) TransactionEvent(com.newrelic.agent.introspec.TransactionEvent) Headers(com.jayway.restassured.response.Headers) Introspector(com.newrelic.agent.introspec.Introspector) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 8 with Headers

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);
}
Also used : Path(java.nio.file.Path) JsonPath(com.jayway.restassured.path.json.JsonPath) Headers(com.jayway.restassured.response.Headers) ZipEntry(java.util.zip.ZipEntry) Response(com.jayway.restassured.response.Response) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with Headers

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");
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) TransactionEvent(com.newrelic.agent.introspec.TransactionEvent) Headers(com.jayway.restassured.response.Headers) Introspector(com.newrelic.agent.introspec.Introspector) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 10 with Headers

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);
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) CohortEvaluation(com.ibm.cohort.engine.api.service.model.CohortEvaluation) Headers(com.jayway.restassured.response.Headers) CohortResult(com.ibm.cohort.engine.api.service.model.CohortResult) RequestSpecification(com.jayway.restassured.specification.RequestSpecification) File(java.io.File) Test(org.junit.Test)

Aggregations

Headers (com.jayway.restassured.response.Headers)15 Test (org.junit.Test)15 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)14 RequestSpecification (com.jayway.restassured.specification.RequestSpecification)10 File (java.io.File)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 CohortEvaluation (com.ibm.cohort.engine.api.service.model.CohortEvaluation)4 Introspector (com.newrelic.agent.introspec.Introspector)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 FhirContext (ca.uhn.fhir.context.FhirContext)3 IParser (ca.uhn.fhir.parser.IParser)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 DateParameter (com.ibm.cohort.cql.evaluation.parameters.DateParameter)3 IntervalParameter (com.ibm.cohort.cql.evaluation.parameters.IntervalParameter)3 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)3 PatientListMeasureEvaluation (com.ibm.cohort.engine.api.service.model.PatientListMeasureEvaluation)3 MeasureContext (com.ibm.cohort.engine.measure.MeasureContext)3 MeasureEvidenceOptions (com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3