use of com.nixmash.blog.jsoup.base.JsoupImage in project nixmash-blog by mintster.
the class JsoupTests method parseImages.
@Test
public void parseImages() {
// # of images in content area one less than full testdto.html page
assertEquals(testDTO.getTestImagesInContentArea().size(), 2);
assertEquals(testDTO.getTestImagesInPage().size(), 3);
// attributes of first image in List<JsoupImage>
JsoupImage img = testDTO.getTestImagesInContentArea().get(0);
assertEquals("http://example.com/one.png", img.getSrc());
assertEquals("one", img.getAlt());
assertTrue(img.getHeight().equals(40));
// empty image height-width attributes are null
assertTrue(testDTO.getTestImagesInContentArea().get(1).getHeight() == null);
// retrieving image with class=myimage
assertEquals(testDTO.getTestImage().getSrc(), "http://example.com/two.png");
}
use of com.nixmash.blog.jsoup.base.JsoupImage in project nixmash-blog by mintster.
the class JsoupUI method getImages.
private List<JsoupImage> getImages(Document doc) {
List<JsoupImage> images = new ArrayList<>();
Elements elements;
elements = doc.select("[src]");
for (Element media : elements) {
if (media.tagName().equals("img")) {
JsoupImage img = new JsoupImage();
img.setSrc(media.attr("abs:src"));
img.setAlt(trim(media.attr("alt"), 60));
img.setHeight(attrIntToNull(media.attr("height")));
img.setWidth(attrIntToNull(media.attr("width")));
images.add(img);
}
}
return images;
}
use of com.nixmash.blog.jsoup.base.JsoupImage in project nixmash-blog by mintster.
the class JsoupPostMetaTests method firstContentImageExtracted.
@Test
public void firstContentImageExtracted() throws IOException {
// First Src URL in /html/testPostBody.html = http://nixmash.com/x/blog/2017/dd0120a.png
List<JsoupImage> images = jsoupPostDTOWithImages.getImagesInContent();
assertNotNull(images);
assertTrue(jsoupPostDTOWithImages.hasImages());
JsoupImage img = jsoupPostDTOWithImages.getImagesInContent().get(0);
assertThat(img.getSrc()).isEqualTo("http://nixmash.com/x/blog/2017/dd0120a.png");
}
Aggregations