Java Code Examples for io.restassured.RestAssured#reset()

The following examples show how to use io.restassured.RestAssured#reset() . 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: JaxRSTestCase.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
public void testJaxbConsumption() throws Exception {
    TestResource.XmlObject xmlObject = new TestResource.XmlObject();
    xmlObject.setValue("test");

    StringWriter writer = new StringWriter();
    JAXBContext context = JAXBContext.newInstance(TestResource.XmlObject.class);
    Marshaller m = context.createMarshaller();
    m.marshal(xmlObject, writer);

    try {
        // in the native image case, the right parser is not chosen, despite the content-type being correct
        RestAssured.defaultParser = Parser.XML;

        RestAssured.given().contentType("application/xml").body(writer.toString()).when().post("/test/consumeXml").then()
                .body(is("test"));
    } finally {
        RestAssured.reset();
    }
}
 
Example 2
Source File: TracingTest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
public void testCDI() {
    try {
        RestAssured.defaultParser = Parser.TEXT;
        RestAssured.when().get("/cdi")
                .then()
                .statusCode(200);
        Assertions.assertEquals(2, mockTracer.finishedSpans().size());
        Assertions.assertEquals("io.quarkus.smallrye.opentracing.deployment.Service.foo",
                mockTracer.finishedSpans().get(0).operationName());
        Assertions.assertEquals("GET:io.quarkus.smallrye.opentracing.deployment.TestResource.cdi",
                mockTracer.finishedSpans().get(1).operationName());
    } finally {
        RestAssured.reset();
    }
}
 
Example 3
Source File: TracingTest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
public void testMPRestClient() {
    try {
        RestAssured.defaultParser = Parser.TEXT;
        RestAssured.when().get("/restClient")
                .then()
                .statusCode(200);
        Assertions.assertEquals(3, mockTracer.finishedSpans().size());
        Assertions.assertEquals("GET:io.quarkus.smallrye.opentracing.deployment.TestResource.hello",
                mockTracer.finishedSpans().get(0).operationName());
        Assertions.assertEquals("GET", mockTracer.finishedSpans().get(1).operationName());
        Assertions.assertEquals("GET:io.quarkus.smallrye.opentracing.deployment.TestResource.restClient",
                mockTracer.finishedSpans().get(2).operationName());
    } finally {
        RestAssured.reset();
    }
}
 
Example 4
Source File: HealthCheckProducerDefaultScopeTest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
public void testHealth() {
    // the health check does not set a content type so we need to force the parser
    try {
        RestAssured.defaultParser = Parser.JSON;
        when().get("/health/ready").then()
                .body("status", is("UP"),
                        "checks.status", contains("UP", "UP"),
                        "checks.name", containsInAnyOrder("alpha1", "bravo1"));
        when().get("/health/ready").then()
                .body("status", is("UP"),
                        "checks.status", contains("UP", "UP"),
                        "checks.name", containsInAnyOrder("alpha1", "bravo2"));
    } finally {
        RestAssured.reset();
    }
}
 
Example 5
Source File: HealthCheckDefaultScopeTest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
public void testHealth() {
    // the health check does not set a content type so we need to force the parser
    try {
        RestAssured.defaultParser = Parser.JSON;
        when().get("/health/live").then()
                .body("status", is("UP"),
                        "checks.status", contains("UP"),
                        "checks.name", contains("noScope"));
        when().get("/health/live").then()
                .body("status", is("DOWN"),
                        "checks.status", contains("DOWN"),
                        "checks.name", contains("noScope"));
    } finally {
        RestAssured.reset();
    }
}
 
Example 6
Source File: HttpSourceTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    RestAssured.reset();
    addClasses(Receiver.class);
    addConfig(new HttpConnectorConfig("sink", "incoming", null));
    initialize();

    await()
            .catchUncaughtExceptions()
            .until(() -> {
                Response response = RestAssured.get("/health").andReturn();
                return response.statusCode() == 200;
            });
}
 
Example 7
Source File: JaxRSTestCase.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testJaxb() throws Exception {
    try {
        // in the native image case, the right parser is not chosen, despite the content-type being correct
        RestAssured.defaultParser = Parser.XML;

        RestAssured.when().get("/test/xml").then()
                .body("xmlObject.value.text()", is("A Value"));
    } finally {
        RestAssured.reset();
    }
}
 
Example 8
Source File: TracingTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleServerRequest() {
    try {
        RestAssured.defaultParser = Parser.TEXT;
        RestAssured.when().get("/hello")
                .then()
                .statusCode(200);
        Assertions.assertEquals(1, mockTracer.finishedSpans().size());
        Assertions.assertEquals("GET:io.quarkus.smallrye.opentracing.deployment.TestResource.hello",
                mockTracer.finishedSpans().get(0).operationName());
    } finally {
        RestAssured.reset();
    }
}
 
Example 9
Source File: TracingTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testContextPropagationInFaultTolerance() {
    try {
        RestAssured.defaultParser = Parser.TEXT;
        RestAssured.when().get("/faultTolerance")
                .then()
                .statusCode(200)
                .body(equalTo("fallback"));
        Awaitility.await().atMost(5, TimeUnit.SECONDS)
                .until(() -> mockTracer.finishedSpans().size() == 5);
        List<MockSpan> spans = mockTracer.finishedSpans();

        Assertions.assertEquals(5, spans.size());
        for (MockSpan mockSpan : spans) {
            Assertions.assertEquals(spans.get(0).context().traceId(), mockSpan.context().traceId());
        }

        // if timeout occurs, subsequent retries/fallback can be interleaved with the execution that timed out,
        // resulting in varying span order
        Assertions.assertEquals(3, countSpansWithOperationName(spans, "ft"));
        Assertions.assertEquals(1, countSpansWithOperationName(spans, "fallback"));
        Assertions.assertEquals(1, countSpansWithOperationName(spans,
                "GET:io.quarkus.smallrye.opentracing.deployment.TestResource.faultTolerance"));
    } finally {
        RestAssured.reset();
    }
}
 
Example 10
Source File: TracingTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testJPA() {
    try {
        RestAssured.defaultParser = Parser.JSON;
        RestAssured.when().get("/jpa")
                .then()
                .statusCode(200)
                .body("", hasSize(3))
                .body("name[0]", equalTo("Apple"))
                .body("name[1]", equalTo("Banana"))
                .body("name[2]", equalTo("Cherry"));
        List<MockSpan> spans = mockTracer.finishedSpans();

        Assertions.assertEquals(3, spans.size());
        for (MockSpan mockSpan : spans) {
            Assertions.assertEquals(spans.get(0).context().traceId(), mockSpan.context().traceId());
        }
        MockSpan firstSpan = mockTracer.finishedSpans().get(0);
        Assertions.assertEquals("Query", firstSpan.operationName());
        Assertions.assertTrue(firstSpan.tags().containsKey("db.statement"));
        Assertions.assertTrue(firstSpan.tags().get("db.statement").toString().contains("known_fruits"));
        Assertions.assertEquals("io.quarkus.smallrye.opentracing.deployment.Service.getFruits",
                mockTracer.finishedSpans().get(1).operationName());
        Assertions.assertEquals("GET:io.quarkus.smallrye.opentracing.deployment.TestResource.jpa",
                mockTracer.finishedSpans().get(2).operationName());
    } finally {
        RestAssured.reset();
    }
}
 
Example 11
Source File: HealthUnitTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testHealth() {
    // the health check does not set a content type so we need to force the parser
    try {
        RestAssured.defaultParser = Parser.JSON;
        RestAssured.when().get("/health/live").then()
                .body("status", is("UP"),
                        "checks.status", contains("UP"),
                        "checks.name", contains("basic"));
    } finally {
        RestAssured.reset();
    }
}
 
Example 12
Source File: RestResourceTestBase.java    From rest-example with Apache License 2.0 5 votes vote down vote up
/**
 * Sets up RestAssured test framework before tests.
 */
@BeforeTest
public void setUpRestAssured() {
    RestAssured.reset();
    RestAssured.port = ENDPOINT_PORT;
    RestAssured.basePath = "";
}
 
Example 13
Source File: IntegrationTests.java    From spring-microservice-sample with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void setup() {
    RestAssured.reset();
    RestAssured.port = this.port;
    this.comments.deleteAllInBatch();
    this.posts.deleteAllInBatch();

    Post post = posts.save(
        Post.builder()
            .title(test_title)
            .content(test_content)
            .build()
    );
    log.debug("saved post:" + post);
    this.slug = post.getSlug();

    log.debug("print all posts:");
    posts.findAll().forEach(System.out::println);

    Comment comment = this.comments.save(
        Comment.builder()
            .content(test_comment)
            .post(new Slug(this.slug))
            .build()
    );
    log.debug("saved comment:" + comment);
}
 
Example 14
Source File: AbstractApiMethod.java    From carina with Apache License 2.0 4 votes vote down vote up
public void setMethodPath(String methodPath) {
    RestAssured.reset();
    this.methodPath = methodPath;
}
 
Example 15
Source File: SslServerWithP12Test.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@AfterAll
public static void restoreRestAssured() {
    RestAssured.reset();
}
 
Example 16
Source File: SslServerWithJksTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@AfterAll
public static void restoreRestAssured() {
    RestAssured.reset();
}
 
Example 17
Source File: SslServerWithPemTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@AfterAll
public static void restoreRestAssured() {
    RestAssured.reset();
}
 
Example 18
Source File: DisableHttpPortTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@AfterAll
public static void restoreRestAssured() {
    RestAssured.reset();
}
 
Example 19
Source File: HealthTestCase.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Test
public void testHealthCheck() {
    try {
        RestAssured.when().get("/health/live").then()
                .contentType(ContentType.JSON)
                .header("Content-Type", containsString("charset=UTF-8"))
                .body("status", is("UP"),
                        "checks.status", containsInAnyOrder("UP", "UP"),
                        "checks.name", containsInAnyOrder("basic", "basic-with-builder"));

        RestAssured.when().get("/health/ready").then()
                .contentType(ContentType.JSON)
                .header("Content-Type", containsString("charset=UTF-8"))
                .body("status", is("UP"),
                        "checks.status", containsInAnyOrder("UP"),
                        "checks.name", containsInAnyOrder("Database connections health check"));

        RestAssured.when().get("/health/group/group1").then()
                .contentType(ContentType.JSON)
                .header("Content-Type", containsString("charset=UTF-8"))
                .body("status", is("UP"),
                        "checks.status", containsInAnyOrder("UP", "UP"),
                        "checks.name", containsInAnyOrder("single", "combined"));

        RestAssured.when().get("/health/group/group2").then()
                .contentType(ContentType.JSON)
                .header("Content-Type", containsString("charset=UTF-8"))
                .body("status", is("UP"),
                        "checks.status", containsInAnyOrder("UP"),
                        "checks.name", containsInAnyOrder("combined"));

        RestAssured.when().get("/health/group").then()
                .contentType(ContentType.JSON)
                .header("Content-Type", containsString("charset=UTF-8"))
                .body("status", is("UP"),
                        "checks.status", containsInAnyOrder("UP", "UP"),
                        "checks.name", containsInAnyOrder("single", "combined"));
    } finally {
        RestAssured.reset();
    }
}