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

The following examples show how to use io.restassured.RestAssured#defaultParser() . 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: RabbitMQReindexingWithEventDeadLettersTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@BeforeEach
void setUp(GuiceJamesServer jamesServer) throws Exception {
    jamesServer.getProbe(DataProbeImpl.class)
        .fluent()
        .addDomain(DOMAIN)
        .addUser(ALICE.asString(), ALICE_PASSWORD);

    Port jmapPort = jamesServer.getProbe(JmapGuiceProbe.class).getJmapPort();
    RestAssured.requestSpecification = jmapRequestSpecBuilder
        .setPort(jmapPort.getValue())
        .build();
    RestAssured.defaultParser = Parser.JSON;

    webAdminApi = WebAdminUtils.spec(jamesServer.getProbe(WebAdminGuiceProbe.class).getWebAdminPort());

    aliceAccessToken = authenticateJamesUser(LocalHostURIBuilder.baseUri(jmapPort), ALICE, ALICE_PASSWORD);

    dockerElasticSearch.getDockerES().pause();
    Thread.sleep(Duration.TEN_SECONDS.getValueInMS()); // Docker pause is asynchronous and we found no way to poll for it
}
 
Example 2
Source File: SpamAssassinContract.java    From james-project with Apache License 2.0 6 votes vote down vote up
@BeforeEach
default void setup(GuiceJamesServer jamesServer) throws Throwable {
    RestAssured.requestSpecification = new RequestSpecBuilder()
            .setContentType(ContentType.JSON)
            .setAccept(ContentType.JSON)
            .setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(StandardCharsets.UTF_8)))
            .setPort(jamesServer.getProbe(JmapGuiceProbe.class).getJmapPort().getValue())
            .build();
    RestAssured.defaultParser = Parser.JSON;

    jamesServer.getProbe(DataProbeImpl.class)
        .fluent()
        .addDomain(BOBS_DOMAIN)
        .addDomain(RECIPIENTS_DOMAIN)
        .addUser(BOB, BOB_PASSWORD)
        .addUser(ALICE, ALICE_PASSWORD)
        .addUser(PAUL, PAUL_PASSWORD);
}
 
Example 3
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 4
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 5
Source File: QuotaMailingTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Throwable {
    jmapServer = createJmapServer();
    jmapServer.start();
    MailboxProbe mailboxProbe = jmapServer.getProbe(MailboxProbeImpl.class);
    DataProbe dataProbe = jmapServer.getProbe(DataProbeImpl.class);
    quotaProbe = jmapServer.getProbe(QuotaProbesImpl.class);

    RestAssured.requestSpecification = jmapRequestSpecBuilder
        .setPort(jmapServer.getProbe(JmapGuiceProbe.class).getJmapPort().getValue())
        .build();
    RestAssured.defaultParser = Parser.JSON;

    dataProbe.addDomain(DOMAIN);
    dataProbe.addUser(HOMER.asString(), PASSWORD);
    dataProbe.addUser(BART.asString(), BOB_PASSWORD);
    mailboxProbe.createMailbox("#private", HOMER.asString(), DefaultMailboxes.INBOX);
    homerAccessToken = authenticateJamesUser(baseUri(jmapServer), HOMER, PASSWORD);
    bartAccessToken = authenticateJamesUser(baseUri(jmapServer), BART, BOB_PASSWORD);
}
 
Example 6
Source File: SendMDNMethodTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@BeforeEach
void setup(GuiceJamesServer jmapServer) throws Throwable {
    this.jmapServer = jmapServer;
    MailboxProbe mailboxProbe = jmapServer.getProbe(MailboxProbeImpl.class);
    DataProbe dataProbe = jmapServer.getProbe(DataProbeImpl.class);

    RestAssured.requestSpecification = jmapRequestSpecBuilder
            .setPort(jmapServer.getProbe(JmapGuiceProbe.class).getJmapPort().getValue())
            .build();
    RestAssured.defaultParser = Parser.JSON;

    dataProbe.addDomain(DOMAIN);
    dataProbe.addUser(HOMER.asString(), PASSWORD);
    dataProbe.addUser(BART.asString(), BOB_PASSWORD);
    mailboxProbe.createMailbox("#private", HOMER.asString(), DefaultMailboxes.INBOX);
    homerAccessToken = authenticateJamesUser(baseUri(jmapServer), HOMER, PASSWORD);
    bartAccessToken = authenticateJamesUser(baseUri(jmapServer), BART, BOB_PASSWORD);
}
 
Example 7
Source File: SetMessagesMethodReRoutingTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Throwable {
    jmapServer = createJmapServer();
    jmapServer.start();
    mailboxProbe = jmapServer.getProbe(MailboxProbeImpl.class);
    dataProbe = jmapServer.getProbe(DataProbeImpl.class);

    RestAssured.requestSpecification = new RequestSpecBuilder()
            .setContentType(ContentType.JSON)
            .setAccept(ContentType.JSON)
            .setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(StandardCharsets.UTF_8)))
            .setPort(jmapServer.getProbe(JmapGuiceProbe.class).getJmapPort().getValue())
            .build();
    RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
    RestAssured.defaultParser = Parser.JSON;

    dataProbe.addDomain(DESTINATION_DOMAIN);
    dataProbe.addDomain(ALIAS_DOMAIN);
    dataProbe.addUser(RECEIVER_AT_DESTINATION_DOMAIN, PASSWORD);
    dataProbe.addUser(SENDER_AT_DESTINATION_DOMAIN, PASSWORD);
    receiverAtDestinationDomainToken = authenticateJamesUser(baseUri(jmapServer), Username.of(RECEIVER_AT_DESTINATION_DOMAIN), PASSWORD);
    senderAtDestinationDomainToken = authenticateJamesUser(baseUri(jmapServer), Username.of(SENDER_AT_DESTINATION_DOMAIN), PASSWORD);
}
 
Example 8
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 9
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 10
Source File: PersonResourceTest.java    From quarkus-quickstarts with Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void initAll() {
    RestAssured.defaultParser = Parser.JSON;
    RestAssured.config
            .logConfig((logConfig().enableLoggingOfRequestAndResponseIfValidationFails()))
            .objectMapperConfig(new ObjectMapperConfig().jackson2ObjectMapperFactory((type, s) -> new ObjectMapper()
                    .registerModule(new Jdk8Module())
                    .registerModule(new JavaTimeModule())
                    .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)));
}
 
Example 11
Source File: DeletedMessageVaultIntegrationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setup(GuiceJamesServer jmapServer) throws Throwable {
    MailboxProbe mailboxProbe = jmapServer.getProbe(MailboxProbeImpl.class);
    DataProbe dataProbe = jmapServer.getProbe(DataProbeImpl.class);

    Port jmapPort = jmapServer.getProbe(JmapGuiceProbe.class).getJmapPort();
    RestAssured.requestSpecification = jmapRequestSpecBuilder
        .setPort(jmapPort.getValue())
        .build();
    RestAssured.defaultParser = Parser.JSON;

    dataProbe.addDomain(DOMAIN);
    dataProbe.addUser(HOMER, PASSWORD);
    dataProbe.addUser(BART, BOB_PASSWORD);
    dataProbe.addUser(JACK, PASSWORD);
    mailboxProbe.createMailbox("#private", HOMER, DefaultMailboxes.INBOX);
    otherMailboxId = mailboxProbe.createMailbox("#private", HOMER, MAILBOX_NAME);
    homerAccessToken = authenticateJamesUser(baseUri(jmapPort), Username.of(HOMER), PASSWORD);
    bartAccessToken = authenticateJamesUser(baseUri(jmapPort), Username.of(BART), BOB_PASSWORD);
    jackAccessToken = authenticateJamesUser(baseUri(jmapPort), Username.of(JACK), PASSWORD);

    testIMAPClient = new TestIMAPClient();

    webAdminApi = WebAdminUtils.spec(jmapServer.getProbe(WebAdminGuiceProbe.class).getWebAdminPort())
        .config(WebAdminUtils.defaultConfig()
            .paramConfig(new ParamConfig(REPLACE, REPLACE, REPLACE)));

}
 
Example 12
Source File: ConfigurationExtension.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void beforeAll( ExtensionContext context )
{
    RestAssured.baseURI = TestConfiguration.get().baseUrl();
    RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
    RestAssured.defaultParser = Parser.JSON;
    RestAssured.requestSpecification = defaultRequestSpecification();
}
 
Example 13
Source File: AppTestBase.java    From microprofile-open-api with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void configureRestAssured() throws MalformedURLException {
    // set base URI and port number to use for all requests
    serverUrl = System.getProperty("test.url");
    String protocol = DEFAULT_PROTOCOL;
    String host = DEFAULT_HOST;
    int port = DEFAULT_PORT;

    if (serverUrl != null) {
        URL url = new URL(serverUrl);
        protocol = url.getProtocol();
        host = url.getHost();
        port = (url.getPort() == -1) ? DEFAULT_PORT : url.getPort();
    }

    RestAssured.baseURI = protocol + "://" + host;
    RestAssured.port = port;

    username = System.getProperty("test.user");
    password = System.getProperty("test.pwd");

    if (username != null && password != null) {
        RestAssured.authentication = RestAssured.basic(username, password);
        RestAssured.useRelaxedHTTPSValidation();
    }
    RestAssured.defaultParser = Parser.JSON;

    if (StringUtils.isBlank(serverUrl)) {
        serverUrl = DEFAULT_PROTOCOL + "://" + DEFAULT_HOST + ":" + DEFAULT_PORT;
    }
}
 
Example 14
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 15
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 16
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 17
Source File: RabbitMQJamesServerReprocessingTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setUp(GuiceJamesServer server) {
    RestAssured.defaultParser = Parser.JSON;
    webAdminApi = WebAdminUtils.spec(server.getProbe(WebAdminGuiceProbe.class).getWebAdminPort())
        .config(WebAdminUtils.defaultConfig()
            .paramConfig(new ParamConfig(REPLACE, REPLACE, REPLACE)));
}
 
Example 18
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 19
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 20
Source File: CassandraBulkOperationTest.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
    RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
    RestAssured.defaultParser = Parser.JSON;
}