Java Code Examples for com.jayway.restassured.response.Response#statusCode()

The following examples show how to use com.jayway.restassured.response.Response#statusCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InferenceVerticleHttpTest.java    From konduit-serving with Apache License 2.0 6 votes vote down vote up
@Test
public void testEmptyOrNullContentTypeHeader(TestContext testContext) {
    Data input = JData.singleton("key_null_or_empty_content_type_header", false);

    Response response = given().port(inferenceDeploymentResult.getActualPort())
            .contentType("")
            .accept(ContentType.BINARY)
            .body(input.asBytes())
            .post(PREDICT_ENDPOINT)
            .andReturn();

    if(response.statusCode() != 415) {
        testContext.assertEquals(500, response.statusCode());
        testContext.assertEquals(ContentType.JSON.toString(), response.contentType());
        testContext.assertEquals(MISSING_OR_EMPTY_CONTENT_TYPE_HEADER.name(), ErrorResponse.fromJson(response.asString()).getErrorCode().name());
    }
}
 
Example 2
Source File: InferenceVerticleHttpTest.java    From konduit-serving with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidContentTypeHeader(TestContext testContext) {
    Data input = JData.singleton("invalid_content_type_header", false);

    Response response = given().port(inferenceDeploymentResult.getActualPort())
            .contentType(ContentType.TEXT) // invalid
            .accept(ContentType.BINARY)
            .body(input.asBytes())
            .post(PREDICT_ENDPOINT)
            .andReturn();

    if(response.statusCode() != 415) {
        testContext.assertEquals(500, response.statusCode());
        testContext.assertEquals(ContentType.JSON.toString(), response.contentType());
        testContext.assertEquals(INVALID_CONTENT_TYPE_HEADER.name(), ErrorResponse.fromJson(response.asString()).getErrorCode().name());
    }
}
 
Example 3
Source File: InferenceVerticleHttpTest.java    From konduit-serving with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidAcceptHeader(TestContext testContext) {
    Data input = JData.singleton("invalid_accept_header", false);

    Response response = given().port(inferenceDeploymentResult.getActualPort())
            .contentType(ContentType.BINARY)
            .accept(ContentType.TEXT) // invalid
            .body(input.asBytes())
            .post(PREDICT_ENDPOINT)
            .andReturn();

    if(response.statusCode() != 406) {
        testContext.assertEquals(500, response.statusCode());
        testContext.assertEquals(ContentType.JSON.toString(), response.contentType());
        testContext.assertEquals(INVALID_ACCEPT_HEADER.name(), ErrorResponse.fromJson(response.asString()).getErrorCode().name());
    }
}
 
Example 4
Source File: DataSetAPITest.java    From data-prep with Apache License 2.0 6 votes vote down vote up
/**
 * DataSet deletion test case when the dataset is used by a preparation.
 */
@Test
public void testDataSetDeleteWhenUsedByPreparation() throws Exception {
    // given
    final String dataSetId = testClient.createDataset("dataset/dataset.csv", "testDataset");
    testClient.createPreparationFromDataset(dataSetId, "testPreparation", home.getId());

    // when/then
    final Response response = when().delete("/api/datasets/" + dataSetId);

    // then
    final int statusCode = response.statusCode();
    assertThat(statusCode, is(409));

    final String responseAsString = response.asString();
    final JsonPath json = from(responseAsString);
    assertThat(json.get("code"), is("TDP_API_DATASET_STILL_IN_USE"));
}
 
Example 5
Source File: KonduitServingLauncherWithoutProcessesTest.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
@Test
public void testRunCommand() throws InterruptedException, IOException, JoranException {
    int port = PortUtils.getAvailablePort();

    Thread runCommandThread = new Thread(() -> runCommand("run", "-c",
            InferenceConfiguration.builder()
                    .servingConfig(ServingConfig.builder()
                            .httpPort(port)
                            .uploadsDirectory(temporaryFolder.getRoot().getAbsolutePath())
                            .build())
                    .step(ImageLoadingStep.builder()
                            .inputName("default")
                            .outputName("default")
                            .build())
                    .build().toJsonObject().encode(),
            "-i", "1",
            "-s", "inference"));
    runCommandThread.start();
    backgroundThreads.add(runCommandThread);

    boolean isServerStarted = false;
    while(!runCommandThread.isInterrupted()) {
        Thread.sleep(2000);

        try {
            Response response = given().port(port).get("/config").andReturn();
            isServerStarted = response.statusCode() == 200;
        } catch (Exception exception) {
            log.info("Unable to connect to the server. Trying again...");
        }

        if(isServerStarted) {
            break;
        }
    }

    assertTrue(isServerStarted);

    LogUtils.setLoggingFromClassPath();
}
 
Example 6
Source File: AsynchronousTransformerTest.java    From p3-batchrefine with Apache License 2.0 5 votes vote down vote up
private Response doRequest(String input, String transform, String format,
                             MimeType contentType) throws Exception {
      String transformURI = fServers.transformURI(input + "-" + transform + ".json").toString();

      Response response = RestAssured.given()
              .queryParam("refinejson", transformURI)
              .header("Accept", contentType.toString() + ";q=1.0")
              .contentType("text/csv")
              .content(contentsAsBytes("inputs", input, "csv"))
              .when().post();

      Assert.assertEquals(HttpStatus.SC_ACCEPTED, response.getStatusCode());

      String location = response.getHeader("location");
      Assert.assertTrue(location != null);

/* Polls until ready. */
      long start = System.currentTimeMillis();
      do {
          response = RestAssured.given()
                  .header("Accept", "text/turtle")
                  .header("Content-Type", "text/turtle")
                  .when().get(location);

          if (System.currentTimeMillis() - start >= ASYNC_TIMEOUT) {
              Assert.fail("Asynchronous call timed out.");
          }

          Thread.sleep(100);

      } while (response.statusCode() == HttpStatus.SC_ACCEPTED);

      return response;
  }
 
Example 7
Source File: APIClientTest.java    From data-prep with Apache License 2.0 4 votes vote down vote up
public boolean deletePreparation(String preparationId) {
    Response response = delete("/api/preparations/{id}", preparationId);
    return response.statusCode() == HttpStatus.OK.value();
}