Example usage for org.jsoup.nodes FormElement getElementById

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

Introduction

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

Prototype

public Element getElementById(String id) 

Source Link

Document

Find an element by ID, including or under this element.

Usage

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

@Test
public void htmlMinimalTest() throws Exception {

    final String SERVICE_RESPONSE_BODY = "BODY";

    optionsResponse.set(/* w  ww.j av  a 2 s.co  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);
}