Example usage for org.jsoup.nodes FormElement submit

List of usage examples for org.jsoup.nodes FormElement submit

Introduction

In this page you can find the example usage for org.jsoup.nodes FormElement submit.

Prototype

public Connection submit() 

Source Link

Document

Prepare to submit this form.

Usage

From source file:org.fcrepo.apix.integration.LoaderIT.java

@Test
public void htmlMinimalTest() throws Exception {

    final String SERVICE_RESPONSE_BODY = "BODY";

    optionsResponse.set(//from w  ww.jav a 2 s.  c o  m
            IOUtils.toString(testResource("objects/options_LoaderIT_minimal.ttl").representation(), "utf8"));
    serviceResponse.set(SERVICE_RESPONSE_BODY);

    final Document html = attempt(60,
            () -> Jsoup.connect(LOADER_URI).method(Method.GET).timeout(1000).execute().parse());
    final FormElement form = ((FormElement) html.getElementById("uriForm"));
    form.getElementById("uri").val(serviceEndpoint);

    final Response response = form.submit().ignoreHttpErrors(true).followRedirects(false).execute();
    update();

    assertEquals("OPTIONS", requestToService.getHeader(Exchange.HTTP_METHOD));
    assertEquals(303, response.statusCode());
    assertNotNull(response.header("Location"));

    // Verify that extension works!

    // Get the intercept/proxy URI for a fedora container
    final URI container = routing.of(REQUEST_URI).interceptUriFor(objectContainer);

    // Deposit an object into the container
    final URI deposited = client.post(container).slug("LoaderIT_htmlMinimalTest")
            .body(IOUtils.toInputStream("<> a <test:LoaderIT#minimal> .", "utf8"), "text/turtle").perform()
            .getLocation();

    // Get the service discovery document
    final URI discoveryDoc = client.options(deposited).perform().getLinkHeaders("service").get(0);

    // Invoke the "minimal" service, and verify that the response body is as expected
    final String body = attempt(10,
            () -> IOUtils.toString(
                    client.get(serviceEndpoints(discoveryDoc).get(SERVICE_MINIMAL)).perform().getBody(),
                    "utf8"));
    assertEquals(SERVICE_RESPONSE_BODY, body);
}