io.restassured.http.ContentType Java Examples

The following examples show how to use io.restassured.http.ContentType. 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: MessageRecordTest.java    From camel-quarkus with 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 #2
Source File: MicroProfileHealthTest.java    From camel-quarkus with 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 #3
Source File: JaegerIntegrationTest.java    From opentelemetry-java with 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 #4
Source File: AmqpTest.java    From camel-quarkus with 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 #5
Source File: MongoDbTest.java    From camel-quarkus with 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 #6
Source File: XmlTest.java    From camel-quarkus with 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 #7
Source File: DSCoercionTest.java    From kogito-runtimes with 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 #8
Source File: JiraTest.java    From camel-quarkus with 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 #9
Source File: FileTest.java    From camel-quarkus with 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 #10
Source File: VertxTest.java    From camel-quarkus with 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 #11
Source File: DSCoercionTest.java    From kogito-runtimes with 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 #12
Source File: BoxTest.java    From camel-quarkus with 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 #13
Source File: NewUnitTest.java    From kogito-runtimes with 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 #14
Source File: JsonComponentsTest.java    From camel-quarkus with 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 #15
Source File: MicroProfileHealthTest.java    From camel-quarkus with 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 #16
Source File: BeanTest.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testRoutes() {
    RestAssured.given().contentType(ContentType.TEXT).body("nuts@bolts").post("/bean/process-order").then()
            .body(equalTo("{success=true, lines=[(id=1,item=nuts), (id=2,item=bolts)]}"));

    /* Ensure that the RoutesBuilder.configure() was not called multiple times on CamelRoute */
    RestAssured.when()
            .get("/bean/camel-configure-counter")
            .then()
            .statusCode(200)
            .body(equalTo("1"));
}
 
Example #17
Source File: CamelJdbcTest.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Test
void testExecuteStatement() {
    RestAssured.given()
            .contentType(ContentType.TEXT).body("select id from camels order by id desc")
            .post("/test/execute")
            .then().body(is("[{ID=3}, {ID=2}, {ID=1}]"));
}
 
Example #18
Source File: SoapTest.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testMarshal() {
    final String msg = UUID.randomUUID().toString().replace("-", "");
    String resp = RestAssured.given()
            .contentType(ContentType.TEXT).body(msg).post("/soap/marshal/1.1") //
            .then().statusCode(201)
            .extract().body().asString();
    assertThat(resp).contains("<ns3:getCustomersByName>");
    assertThat(resp).contains("<name>" + msg + "</name>");
    assertThat(resp).contains("<ns2:Envelope xmlns:ns2=\"http://schemas.xmlsoap.org/soap/envelope/\"");
}
 
Example #19
Source File: JaxbTest.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testMarshallLasttName() {
    String name = RestAssured.given().contentType(ContentType.TEXT)
            .body("Bar")
            .post("/jaxb/marshal-lastname")
            .then().statusCode(201).extract().asString();
    assertThat(name).contains("<lastName>Bar</lastName>");
}
 
Example #20
Source File: ObservabilityTest.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void metrics() {
    // Verify a expected Camel metric is available
    given()
            .when().accept(ContentType.JSON)
            .get("/metrics/application")
            .then()
            .statusCode(200)
            .body(
                    "'camel.context.status;camelContext=camel-quarkus-observability'", is(3));
}
 
Example #21
Source File: JsonPathBeanTest.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void getFullNameWihtoutMiddleNameShouldSucceed() {
    personRequest.getPerson().setMiddleName(null);

    String fullName = RestAssured.given() //
            .contentType(ContentType.JSON).body(personRequest).get("/jsonpath/getFullName").then().statusCode(200).extract()
            .asString();
    assertEquals("Christophe Fontane", fullName);
}
 
Example #22
Source File: GreetingsTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testHelloEndpoint() {
    given()
        .contentType(ContentType.JSON)
        .accept(ContentType.JSON)
        .body("{}")
    .when()
        .post("/greetings")
    .then()
        .statusCode(200)
        .body("id", notNullValue());    
}
 
Example #23
Source File: MicroProfileHealthTest.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testLivenessUpStatus() {
    RestAssured.when().get("/health/live").then()
            .contentType(ContentType.JSON)
            .header("Content-Type", containsString("charset=UTF-8"))
            .body("status", is("UP"),
                    "checks.status", containsInAnyOrder("UP"),
                    "checks.name", containsInAnyOrder("camel-liveness-checks"),
                    "checks.data.test", containsInAnyOrder("UP"),
                    "checks.data.test-liveness", containsInAnyOrder("UP"));
}
 
Example #24
Source File: PdfTest.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Order(2)
@Test
public void appendTextShouldReturnAnUpdatedPdfDocument() throws IOException {
    byte[] bytes = RestAssured.given().contentType(ContentType.TEXT).body("another line that should be appended")
            .put("/pdf/appendText").then().statusCode(200).extract().asByteArray();

    PDDocument doc = PDDocument.load(bytes);
    PDFTextStripper pdfTextStripper = new PDFTextStripper();
    String text = pdfTextStripper.getText(doc);
    assertEquals(2, doc.getNumberOfPages());
    assertTrue(text.contains("content to be included in the created pdf document"));
    assertTrue(text.contains("another line that should be appended"));
    doc.close();
}
 
Example #25
Source File: SoapTest.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void round() {
    final String msg = UUID.randomUUID().toString().replace("-", "");
    String resp = RestAssured.given()
            .contentType(ContentType.TEXT).body(msg).post("/soap/round") //
            .then().statusCode(201)
            .extract().body().asString();
    assertThat(resp).isEqualTo(msg);
}
 
Example #26
Source File: JsonPathSetBodyTest.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void getBookPrice() {
    String bookPrice = RestAssured.given() //
            .contentType(ContentType.JSON).body(storeRequest).get("/jsonpath/getBookPrice").then().statusCode(200).extract()
            .asString();
    assertEquals("6.0", bookPrice);
}
 
Example #27
Source File: FixedLengthRecordTest.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void jsonToFixedLengthShouldSucceed() {
    FixedLengthOrder order = new FixedLengthOrder();
    order.setName("Bob");
    order.setCountry("Spa");

    String fixedLengthOrder = RestAssured.given() //
            .contentType(ContentType.JSON).body(order).get("/bindy/jsonToFixedLength").then().statusCode(200).extract()
            .asString();

    assertEquals(FIXED_LENGTH_ORDER, fixedLengthOrder);
}
 
Example #28
Source File: GoogleComponentsTest.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testGoogleMailComponent() {
    String message = "Hello Camel Quarkus Google Mail";

    // Create
    String messageId = RestAssured.given()
            .contentType(ContentType.TEXT)
            .body(message)
            .post("/google-mail/create")
            .then()
            .statusCode(201)
            .extract()
            .body()
            .asString();

    // Read
    RestAssured.given()
            .queryParam("messageId", messageId)
            .get("/google-mail/read")
            .then()
            .statusCode(200)
            .body(is(message));

    // Delete
    RestAssured.given()
            .queryParam("messageId", messageId)
            .delete("/google-mail/delete")
            .then()
            .statusCode(204);

    RestAssured.given()
            .queryParam("messageId", messageId)
            .get("/google-mail/read")
            .then()
            .statusCode(404);
}
 
Example #29
Source File: CsvTest.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void csv2json() {
    RestAssured.given() //
            .contentType(ContentType.TEXT)
            .accept(ContentType.JSON)
            .body("Melwah,Camelus Dromedarius\r\nAl Hamra,Camelus Dromedarius\r\n")
            .post("/csv/csv-to-json")
            .then()
            .statusCode(200)
            .body(is("[[\"Melwah\",\"Camelus Dromedarius\"],[\"Al Hamra\",\"Camelus Dromedarius\"]]"));
}
 
Example #30
Source File: DSCoercionTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testDSd() {
    LocalDate DSd = given().contentType(ContentType.JSON)
                           .when()
                           .post("/DScoercion/DSd")
                           .getBody().as(LocalDate.class);
    assertThat(DSd, is(LocalDate.of(2020, 5, 18)));
}