Search in sources :

Example 1 with Document

use of org.apache.sling.hapi.client.Document in project sling by apache.

the class FormTest method testForm.

@Test
public void testForm() throws ClientException, URISyntaxException {
    MicrodataHtmlClient client = new MicrodataHtmlClient(httpServer.getURI().toString());
    Document doc = client.enter(GET_URL);
    Items items = doc.items();
    Assert.assertThat(items.length(), equalTo(1));
    Items form = doc.form("test");
    Assert.assertThat(form.length(), equalTo(2));
    List<NameValuePair> data = new ArrayList<NameValuePair>();
    data.add(new BasicNameValuePair("f1", "val1"));
    // url encode enctype
    Document doc2 = form.at(0).submit(data);
    Assert.assertThat(doc2.items().length(), equalTo(1));
    // the multipart enctype
    Document doc3 = form.at(1).submit(data);
    Assert.assertThat(doc3.items().length(), equalTo(1));
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) Items(org.apache.sling.hapi.client.Items) MicrodataHtmlClient(org.apache.sling.hapi.client.impl.microdata.MicrodataHtmlClient) Document(org.apache.sling.hapi.client.Document) Test(org.junit.Test)

Example 2 with Document

use of org.apache.sling.hapi.client.Document in project sling by apache.

the class GetPostTest method testRedirect.

@Test
public void testRedirect() throws ClientException, URISyntaxException, UnsupportedEncodingException {
    MicrodataHtmlClient client = new MicrodataHtmlClient(httpServer.getURI().toString());
    Document doc = client.post(REDIRECT_URL, new StringEntity("test"));
    Assert.assertThat("POST request failed to redirect", doc.toString(), containsString(OK_RESPONSE));
}
Also used : StringEntity(org.apache.http.entity.StringEntity) MicrodataHtmlClient(org.apache.sling.hapi.client.impl.microdata.MicrodataHtmlClient) Document(org.apache.sling.hapi.client.Document) Test(org.junit.Test)

Example 3 with Document

use of org.apache.sling.hapi.client.Document in project sling by apache.

the class GetPostTest method testValidAuthGet.

@Test
public void testValidAuthGet() throws ClientException, URISyntaxException {
    MicrodataHtmlClient client = new MicrodataHtmlClient(httpServer.getURI().toString(), USER, PASSWORD);
    Document doc = client.get(GET_AUTH_URL);
    Assert.assertThat("GET request failed with basic auth", doc.toString(), containsString(OK_RESPONSE));
}
Also used : MicrodataHtmlClient(org.apache.sling.hapi.client.impl.microdata.MicrodataHtmlClient) Document(org.apache.sling.hapi.client.Document) Test(org.junit.Test)

Example 4 with Document

use of org.apache.sling.hapi.client.Document in project sling by apache.

the class ItemsTest method testItemsLinks.

@Test
public void testItemsLinks() throws ClientException, URISyntaxException {
    MicrodataHtmlClient client = new MicrodataHtmlClient(httpServer.getURI().toString());
    Document doc = client.enter(GET_LINKS_URL);
    Items items = doc.items();
    Assert.assertThat(items.length(), equalTo(1));
    Assert.assertThat(items.prop("name").text(), equalTo("Avatar"));
    Assert.assertThat(items.prop("genre").text(), equalTo("Science fiction"));
    Assert.assertThat(items.prop("rank").number(), equalTo(2));
    Assert.assertThat(items.prop("director").prop("name").text(), equalTo("James Cameron"));
    Assert.assertThat(items.prop("director").prop("birthDate").text(), equalTo("August 16, 1954"));
    Assert.assertThat(doc.link("test").length(), equalTo(2));
    Assert.assertThat(doc.items().link("test").length(), equalTo(1));
    Assert.assertThat(doc.items().prop("director").link("test").length(), equalTo(1));
    Items otherMovies = doc.link("test").follow().items();
    Assert.assertThat(otherMovies.length(), equalTo(2));
}
Also used : Items(org.apache.sling.hapi.client.Items) MicrodataHtmlClient(org.apache.sling.hapi.client.impl.microdata.MicrodataHtmlClient) Document(org.apache.sling.hapi.client.Document) Test(org.junit.Test)

Example 5 with Document

use of org.apache.sling.hapi.client.Document in project sling by apache.

the class ItemsTest method testItems.

@Test
public void testItems() throws ClientException, URISyntaxException {
    MicrodataHtmlClient client = new MicrodataHtmlClient(httpServer.getURI().toString());
    Document doc = client.enter(GET_URL);
    Items items = doc.items();
    Assert.assertThat(items.length(), equalTo(2));
    for (int i = 0; i < 2; i++) {
        Assert.assertThat(items.at(i).prop("name").text(), equalTo("Avatar" + i));
        Assert.assertThat(items.at(i).prop("genre").text(), equalTo("Science fiction" + i));
        Assert.assertThat(items.at(i).prop("rank").number(), equalTo(i));
        Assert.assertThat(items.at(i).prop("director").prop("name").text(), equalTo("James Cameron" + i));
        Assert.assertThat(items.at(i).prop("director").prop("birthDate").text(), equalTo("August 16, 1954 - " + i));
    }
}
Also used : Items(org.apache.sling.hapi.client.Items) MicrodataHtmlClient(org.apache.sling.hapi.client.impl.microdata.MicrodataHtmlClient) Document(org.apache.sling.hapi.client.Document) Test(org.junit.Test)

Aggregations

Document (org.apache.sling.hapi.client.Document)6 MicrodataHtmlClient (org.apache.sling.hapi.client.impl.microdata.MicrodataHtmlClient)6 Test (org.junit.Test)6 Items (org.apache.sling.hapi.client.Items)3 ArrayList (java.util.ArrayList)1 NameValuePair (org.apache.http.NameValuePair)1 StringEntity (org.apache.http.entity.StringEntity)1 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)1 StringContains (org.hamcrest.core.StringContains)1