Search in sources :

Example 96 with Document

use of org.jsoup.nodes.Document in project gocd by gocd.

the class BuildDetailPageVelocityTemplateTest method shouldEscapeBuildCauseOnVelocityTemplate.

@Test
public void shouldEscapeBuildCauseOnVelocityTemplate() throws Exception {
    Document actualDoc = Jsoup.parse(getBuildDetailVelocityView(createJobDetailModel()).render());
    assertThat(actualDoc.select("#build-detail-summary").last().html(), containsString("modified by Ernest Hemingway <oldman@sea.com>"));
}
Also used : Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 97 with Document

use of org.jsoup.nodes.Document in project gocd by gocd.

the class HeaderTemplateTest method should_NOT_HaveHeaderWhenLocalizerIs_NULL_InContext.

@Test
public void should_NOT_HaveHeaderWhenLocalizerIs_NULL_InContext() throws Exception {
    HashMap<String, Object> data = new HashMap<>();
    data.put("l", null);
    TestVelocityView view = new TestVelocityView(TEMPLATE_PATH, data);
    Document actualOutput = Jsoup.parse(view.render());
    assertThat(actualOutput.select("#header .application_nav").isEmpty(), is(true));
}
Also used : HashMap(java.util.HashMap) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 98 with Document

use of org.jsoup.nodes.Document in project gocd by gocd.

the class HeaderTemplateTest method shouldHaveNavigationElementsWhenLocalizerIsPresentInContext.

@Test
public void shouldHaveNavigationElementsWhenLocalizerIsPresentInContext() throws Exception {
    HashMap<String, Object> data = new HashMap<>();
    data.put("l", mock(Localizer.class));
    TestVelocityView view = new TestVelocityView(TEMPLATE_PATH, data);
    Document actualOutput = Jsoup.parse(view.render());
    assertThat(actualOutput.select("#header .application_nav").isEmpty(), is(false));
}
Also used : HashMap(java.util.HashMap) Localizer(com.thoughtworks.go.i18n.Localizer) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 99 with Document

use of org.jsoup.nodes.Document in project gocd by gocd.

the class NotificationTemplateTest method shouldHTMLEscapeMatchers.

@Test
public void shouldHTMLEscapeMatchers() throws Exception {
    HashMap<String, Object> data = new HashMap<>();
    User user = new User("name", "display-name", new String[] { "<script>this && that</script>", "matcher2" }, "email1@host.com", true);
    user.populateModel(data);
    data.put("pipelines", "[]");
    data.put("l", null);
    Document actualDoc = Jsoup.parse(new TestVelocityView(TEMPLATE_PATH, data).render());
    assertMatchers(actualDoc, "<script>this && that</script>,matcher2", "&lt;script&gt;this &amp;&amp; that&lt;/script&gt;,", "matcher2");
}
Also used : User(com.thoughtworks.go.domain.User) HashMap(java.util.HashMap) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 100 with Document

use of org.jsoup.nodes.Document in project jstructure by JonStargaryen.

the class OrientationsOfProteinsInMembranesAnnotator method getDocument.

Document getDocument(String url) throws IOException {
    logger.info("fetching OPM annotation from {}", url);
    Document document = Jsoup.connect(url).get();
    // not the results directly but rather the page forwarding to representative entries
    if (document.text().contains("Representative structure(s) of this protein: ")) {
        String href = document.getElementById("body").getElementsByTag("a").first().attr("href");
        logger.info("moving to representative structure at {}", href);
        return getDocument(BASE_URL + href);
    }
    return document;
}
Also used : Document(org.jsoup.nodes.Document)

Aggregations

Document (org.jsoup.nodes.Document)391 Test (org.junit.Test)194 Element (org.jsoup.nodes.Element)153 IOException (java.io.IOException)100 File (java.io.File)81 Elements (org.jsoup.select.Elements)70 ElementHandlerImpl (org.asqatasun.ruleimplementation.ElementHandlerImpl)51 Connection (org.jsoup.Connection)37 ArrayList (java.util.ArrayList)36 URL (java.net.URL)24 HashMap (java.util.HashMap)16 InputStream (java.io.InputStream)13 List (java.util.List)9 MalformedURLException (java.net.MalformedURLException)8 Matcher (java.util.regex.Matcher)7 Logger (org.slf4j.Logger)7 Pattern (java.util.regex.Pattern)6 HttpGet (org.apache.http.client.methods.HttpGet)6 Jsoup (org.jsoup.Jsoup)6 LoggerFactory (org.slf4j.LoggerFactory)6