Java Code Examples for io.restassured.http.ContentType

The following examples show how to use io.restassured.http.ContentType. These examples are extracted from open source projects. 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 Project: camel-quarkus   Source File: MicroProfileHealthTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testRouteStoppedDownStatus() {
    try {
        RestAssured.get("/microprofile-health/route/healthyRoute/stop")
                .then()
                .statusCode(204);

        RestAssured.when().get("/health").then()
                .contentType(ContentType.JSON)
                .header("Content-Type", containsString("charset=UTF-8"))
                .body("status", is("DOWN"),
                        "checks.data.'route:healthyRoute'", containsInAnyOrder(null, null, "DOWN"));
    } finally {
        RestAssured.get("/microprofile-health/route/healthyRoute/start")
                .then()
                .statusCode(204);
    }
}
 
Example 2
Source Project: camel-quarkus   Source File: AmqpTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAmqpComponent() {
    String message = "Hello Camel Quarkus Amqp";

    RestAssured.given()
            .contentType(ContentType.TEXT)
            .body(message)
            .post("/amqp/amqp-test-queue")
            .then()
            .statusCode(201);

    RestAssured.given()
            .contentType(ContentType.TEXT)
            .get("/amqp/amqp-test-queue")
            .then()
            .statusCode(200)
            .body(is(message));
}
 
Example 3
Source Project: kogito-runtimes   Source File: DSCoercionTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWholeModel() {
    given()
           .contentType(ContentType.JSON)
       .when()
           .post("/DScoercion")
       .then()
           .statusCode(200)
           .body("n", is(47))
           .body("s", is("Hello, World"))
           .body("b", is(true))
           .body("d", is("2020-05-18")) // as JSON is not schema aware, here we assert the RAW string
           .body("t", is("12:34:56"))
           .body("dt", is("2020-05-18T12:34:56"))
           .body("ymd", is("P3Y"))
           .body("dtd", is("PT1H"));
}
 
Example 4
Source Project: camel-quarkus   Source File: JiraTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testJiraComponent() {
    String jiraUrl = System.getenv("JIRA_URL");
    if (jiraUrl == null) {
        jiraUrl = String.format("http://localhost:%s/jira",
                System.getProperty("quarkus.http.test-port", System.getProperty("quarkus.http.port")));
    }

    RestAssured
            .given()
            .contentType(ContentType.TEXT)
            .queryParam("jiraUrl", jiraUrl)
            .body("Demo issue body")
            .when()
            .post("/jira/post")
            .then()
            .statusCode(201)
            .body(matchesPattern("[A-Z]+-[0-9]+"));
}
 
Example 5
Source Project: camel-quarkus   Source File: FileTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void file() {
    // Create a new file
    String fileName = RestAssured.given()
            .contentType(ContentType.TEXT)
            .body(FILE_BODY)
            .post("/file/create/in")
            .then()
            .statusCode(201)
            .extract()
            .body()
            .asString();

    // Read the file
    RestAssured
            .get("/file/get/in/" + Paths.get(fileName).getFileName())
            .then()
            .statusCode(200)
            .body(equalTo(FILE_BODY));
}
 
Example 6
Source Project: kogito-runtimes   Source File: DSCoercionTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWholeModel() {
    given()
           .contentType(ContentType.JSON)
       .when()
           .post("/DScoercion")
       .then()
           .statusCode(200)
           .body("n", is(47))
           .body("s", is("Hello, World"))
           .body("b", is(true))
           .body("d", is("2020-05-18")) // as JSON is not schema aware, here we assert the RAW string
           .body("t", is("12:34:56"))
           .body("dt", is("2020-05-18T12:34:56"))
           .body("ymd", is("P3Y"))
           .body("dtd", is("PT1H"));
}
 
Example 7
Source Project: camel-quarkus   Source File: MicroProfileHealthTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testReadinessDownStatus() {
    try {
        RestAssured.get("/microprofile-health/checks/failing/true")
                .then()
                .statusCode(204);

        RestAssured.when().get("/health/ready").then()
                .contentType(ContentType.JSON)
                .header("Content-Type", containsString("charset=UTF-8"))
                .body("status", is("DOWN"),
                        "checks.status", containsInAnyOrder("UP", "DOWN"),
                        "checks.name", containsInAnyOrder("camel-readiness-checks", "camel-context-check"),
                        "checks.data.contextStatus", containsInAnyOrder(null, "Started"),
                        "checks.data.name", containsInAnyOrder(null, "quarkus-camel-example"),
                        "checks.data.test-readiness", containsInAnyOrder(null, "UP"));
    } finally {
        RestAssured.get("/microprofile-health/checks/failing/false")
                .then()
                .statusCode(204);
    }
}
 
Example 8
Source Project: camel-quarkus   Source File: MessageRecordTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void jsonToMessageShouldSucceed() {
    MessageOrder order = new MessageOrder();
    order.setAccount("BE.CHM.001");
    order.setHeader(new Header());
    order.getHeader().setBeginString("BEGIN");
    order.getHeader().setBodyLength(20);
    order.setSecurities(new ArrayList<>());
    order.getSecurities().add(new Security());
    order.getSecurities().get(0).setIdSource("4");
    order.setText("camel - quarkus - bindy test");
    order.setTrailer(new Trailer());
    order.getTrailer().setCheckSum(220);

    String messageOrder = RestAssured.given() //
            .contentType(ContentType.JSON).body(order).get("/bindy/jsonToMessage").then().statusCode(200).extract()
            .asString();
    assertEquals(MESSAGE_ORDER, messageOrder);
}
 
Example 9
Source Project: camel-quarkus   Source File: JsonComponentsTest.java    License: Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@MethodSource("listJsonDataFormatsToBeTested")
public void testRoutes(String jsonComponent) {
    RestAssured.given().contentType(ContentType.TEXT)
            .queryParam("json-component", jsonComponent)
            .body("[{\"dummy_string\": \"value1\"}, {\"dummy_string\": \"value2\"}]")
            .post("/dataformats-json/in");
    RestAssured.given()
            .queryParam("json-component", jsonComponent)
            .post("/dataformats-json/out")
            .then()
            .body(equalTo("{\"dummy_string\":\"value1\"}"));
    RestAssured.given()
            .queryParam("json-component", jsonComponent)
            .post("/dataformats-json/out")
            .then()
            .body(equalTo("{\"dummy_string\":\"value2\"}"));
}
 
Example 10
Source Project: kogito-runtimes   Source File: NewUnitTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testServletChange() throws InterruptedException {

    String personsPayload = "{\"persons\":[{\"name\":\"Mario\",\"age\":45,\"adult\":false},{\"name\":\"Sofia\",\"age\":17,\"adult\":false}]}";

    test.addResourceFile(DRL_RESOURCE_FILE, DRL_SOURCE);

    List<String> names = given()
            .baseUri("http://localhost:" + HTTP_TEST_PORT)
            .contentType(ContentType.JSON)
            .accept(ContentType.JSON)
            .body(personsPayload).when()
            .post("/find-adult-names")
            .then()
            .statusCode(200)
            .extract().
                    as(List.class);

    assertEquals(1, names.size());
    assertTrue(names.contains( "Mario" ));
}
 
Example 11
Source Project: camel-quarkus   Source File: BoxTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testUploadDownloadDeleteFile() {
    String fileName = "CamelQuarkusTestFile_Upload.txt";
    String content = "This is the CamelQuarkusTestFile.";

    // upload
    final String fileId = RestAssured.given() //
            .contentType(ContentType.TEXT).body(content).post("/box/uploadFile/0/" + fileName) //
            .then().statusCode(201).extract().body().asString();

    // download
    final String fileContent = RestAssured.given() //
            .contentType(ContentType.TEXT).body(fileId).get("/box/downloadFile") //
            .then().statusCode(201).extract().body().asString();

    Assertions.assertEquals(content, fileContent, "File contents do not match!");

    // delete
    RestAssured.given() //
            .contentType(ContentType.TEXT).body(fileId).post("/box/deleteFile") //
            .then().statusCode(201);
}
 
Example 12
Source Project: camel-quarkus   Source File: VertxTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testVertxComponent() {
    // Verify that the Vertx instance set up by the Quarkus extension
    // is the one used in the Camel component
    RestAssured.given()
            .get("/vertx/verify/instance")
            .then()
            .statusCode(200)
            .body(is("true"));

    String message = "Camel Quarkus Vert.x";
    RestAssured.given()
            .contentType(ContentType.TEXT)
            .body(message)
            .post("/vertx/post")
            .then()
            .statusCode(201)
            .body(is("Hello " + message));
}
 
Example 13
Source Project: camel-quarkus   Source File: XmlTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void xpathLanguage() {
    // Tests a simple xpath driven content based router
    RestAssured.given()
            .contentType(ContentType.XML)
            .body("<orders><order><id>1</id><country>UK</country><total>2.54</total></order></orders>")
            .post("/xml/xpath")
            .then()
            .statusCode(200)
            .body(is("Country UK"));

    RestAssured.given()
            .contentType(ContentType.XML)
            .body("<orders><order><id>1</id><country>FR</country><total>9.99</total></order></orders>")
            .post("/xml/xpath")
            .then()
            .statusCode(200)
            .body(is("Invalid country code"));
}
 
Example 14
Source Project: opentelemetry-java   Source File: JaegerIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
private static boolean assertJaegerHaveTrace() {
  try {
    String url =
        String.format(
            "%s/api/traces?service=%s",
            String.format(JAEGER_URL + ":%d", jaegerContainer.getMappedPort(QUERY_PORT)),
            SERVICE_NAME);
    Response response =
        given()
            .headers("Content-Type", ContentType.JSON, "Accept", ContentType.JSON)
            .when()
            .get(url)
            .then()
            .contentType(ContentType.JSON)
            .extract()
            .response();
    Map<String, String> path = response.jsonPath().getMap("data[0]");
    return path.get("traceID") != null;
  } catch (Exception e) {
    return false;
  }
}
 
Example 15
Source Project: camel-quarkus   Source File: MongoDbTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMongoDbComponent() {
    // Write to collection
    RestAssured.given()
            .contentType(ContentType.JSON)
            .body("{message:\"Hello Camel Quarkus Mongo DB\"}")
            .post("/mongodb/collection/camelTest")
            .then()
            .statusCode(201);

    // Retrieve from collection
    JsonPath jsonPath = RestAssured.get("/mongodb/collection/camelTest")
            .then()
            .contentType(ContentType.JSON)
            .statusCode(200)
            .extract()
            .body()
            .jsonPath();

    List<Map<String, String>> documents = jsonPath.get();
    assertEquals(1, documents.size());

    Map<String, String> document = documents.get(0);
    assertEquals("Hello Camel Quarkus Mongo DB", document.get("message"));
}
 
Example 16
Source Project: kogito-runtimes   Source File: DSCoercionTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDSt() {
    LocalTime DSt = given().contentType(ContentType.JSON)
                           .when()
                           .post("/DScoercion/DSt")
                           .getBody().as(LocalTime.class);
    assertThat(DSt, is(LocalTime.of(12, 34, 56)));
}
 
Example 17
Source Project: apicurio-registry   Source File: ArtifactsResourceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testYamlContentType() throws Exception {
    String artifactId = "testYamlContentType";
    ArtifactType artifactType = ArtifactType.OPENAPI;
    String artifactContent = resourceToString("openapi-empty.yaml");

    // Create OpenAPI artifact (from YAML)
    given()
        .config(RestAssuredConfig.config().encoderConfig(EncoderConfig.encoderConfig().encodeContentTypeAs(CT_YAML, ContentType.TEXT)))
        .when()
            .contentType(CT_YAML)
            .header("X-Registry-ArtifactId", artifactId)
            .header("X-Registry-ArtifactType", artifactType.name())
            .body(artifactContent)
            .post("/artifacts")
        .then()
            .statusCode(200)
            .body("id", equalTo(artifactId))
            .body("name", equalTo("Empty API"))
            .body("description", equalTo("An example API design using OpenAPI."))
            .body("type", equalTo(artifactType.name()));
    
    this.waitForArtifact(artifactId);

    // Get the artifact content (should be JSON)
    given()
        .when()
            .pathParam("artifactId", "testYamlContentType")
            .get("/artifacts/{artifactId}")
        .then()
            .statusCode(200)
            .header("Content-Type", Matchers.containsString(CT_JSON))
            .body("openapi", equalTo("3.0.2"))
            .body("info.title", equalTo("Empty API"));
}
 
Example 18
Source Project: camel-quarkus   Source File: OpenApiTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void invokeApiDocumentEndpoint() {
    RestAssured.given()
            .get("/openapi.json")
            .then()
            .contentType(ContentType.JSON)
            .statusCode(200)
            .body(
                    "paths.'/fruits/list'", hasKey("get"),
                    "paths.'/fruits/list'.get.operationId", is("list"));
}
 
Example 19
Source Project: camel-quarkus   Source File: ValidatorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void validXML() {

    RestAssured.given()
            .contentType(ContentType.XML)
            .body("<message><firstName>MyFirstname</firstName><lastName>MyLastname</lastName></message>")
            .post("/validator/xml")
            .then()
            .statusCode(200);

}
 
Example 20
Source Project: camel-quarkus   Source File: ValidatorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void invalidXML() {

    RestAssured.given()
            .contentType(ContentType.XML)
            .body("<message><firstName>MyFirstname</firstName></message>")
            .post("/validator/xml")
            .then()
            .statusCode(500);

}
 
Example 21
Source Project: kogito-runtimes   Source File: DSCoercionTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDSb() {
    Boolean DSb = given().contentType(ContentType.JSON)
                        .when()
                         .post("/DScoercion/DSb")
                        .getBody().as(Boolean.class);
    assertThat(DSb, is(true));
}
 
Example 22
Source Project: camel-quarkus   Source File: TelegramTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void postText() {
    final String uuid = UUID.randomUUID().toString().replace("-", "");
    final String msg = String.format("A message from camel-quarkus-telegram %s", uuid);

    /* Send a message */
    RestAssured.given()
            .contentType(ContentType.TEXT)
            .body(msg)
            .post("/telegram/messages")
            .then()
            .statusCode(201);

}
 
Example 23
Source Project: camel-quarkus   Source File: BeanTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void method() {
    RestAssured.given()
            .contentType(ContentType.TEXT)
            .body("Kermit")
            .post("/bean/method")
            .then()
            .body(equalTo("Hello Kermit from the MyBean"));
}
 
Example 24
Source Project: camel-quarkus   Source File: JoltTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void sampleShouldSucceed() throws IOException {
    File requestBody = new File("src/test/resources/sample-input.json");
    String expectedResponseBody = IoUtils.readFile(Paths.get("src/test/resources/sample-output.json"));

    given().body(requestBody).contentType(ContentType.JSON).put("/jolt/sample").then().statusCode(200)
            .body(is(expectedResponseBody));
}
 
Example 25
Source Project: camel-quarkus   Source File: JoltTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void functionShouldSucceed() throws IOException {
    File requestBody = new File("src/test/resources/function-input.json");
    String expectedResponseBody = IoUtils.readFile(Paths.get("src/test/resources/function-output.json"));

    given().body(requestBody).contentType(ContentType.JSON).put("/jolt/function").then().statusCode(200)
            .body(is(expectedResponseBody));
}
 
Example 26
Source Project: camel-quarkus   Source File: SedaTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSeda() {
    RestAssured.given()
            .contentType(ContentType.TEXT).body("Hello World").post("/seda/post")
            .then().statusCode(201);

    RestAssured.get("/seda/get").then().body(equalTo("Hello World")).statusCode(200);
}
 
Example 27
Source Project: kogito-runtimes   Source File: DSCoercionTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDSdtd() {
    Duration DSdtd = given().contentType(ContentType.JSON)
                            .when()
                            .post("/DScoercion/DSdtd")
                            .getBody().as(Duration.class);
    assertThat(DSdtd, is(Duration.parse("PT1H")));
}
 
Example 28
Source Project: camel-quarkus   Source File: RestOpenapiTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testInvokeApiEndpoint() {
    RestAssured.given()
            .queryParam("port", RestAssured.port)
            .get("/rest-openapi/fruits/list")
            .then()
            .contentType(ContentType.JSON)
            .statusCode(200)
            .body("description", containsInAnyOrder("Winter fruit", "Tropical fruit"), "name",
                    containsInAnyOrder("Apple", "Pineapple"));
}
 
Example 29
Source Project: kogito-runtimes   Source File: DSCoercionTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDSymd() {
    Period DSymd = given().contentType(ContentType.JSON)
                          .when()
                          .post("/DScoercion/DSymd")
                          .getBody().as(Period.class);
    assertThat(DSymd, is(Period.parse("P3Y")));
}
 
Example 30
Source Project: kogito-runtimes   Source File: ElementAtIndexTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testHeaderPopulated() {
    given().body(" { \"a list\" : [\"a\", \"b\", \"c\"], \"an index\" : 47 }")
           .contentType(ContentType.JSON)
           .when()
           .post("/ElementAtIndex")
           .then()
           .statusCode(200)
           .header("X-Kogito-decision-messages", notNullValue()) // a warning
           .body("'element at index'", nullValue());
}