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));
}
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));
}
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));
}
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));
}
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));
}
}
Aggregations