public void testGettersAndSetters() { Image image = new Image(); image.setAttachmentId(ATTACHMENT_ID); image.setCaption(CAPTION); image.setUrl(URL); image.setWidth(WIDTH); image.setHeight(HEIGHT); assertEquals(ATTACHMENT_ID, image.getAttachmentId()); assertEquals(CAPTION, image.getCaption()); assertEquals(URL, image.getUrl()); assertEquals(WIDTH, image.getWidth()); assertEquals(HEIGHT, image.getHeight()); }
public void testAttachmentConstructor() { Image image = new Image(ATTACHMENT_ID, CAPTION); assertEquals(ElementType.IMAGE, image.getType()); assertEquals(ATTACHMENT_ID, image.getAttachmentId()); assertEquals(CAPTION, image.getCaption()); assertNull(image.getUrl()); }
/** * Constructs a Wave image given an attachment id and a caption. * * @param attachmentId the attachment id of the wave image. * @param caption the caption for the image. */ public Image(String attachmentId, String caption) { this(); setAttachmentId(attachmentId); setCaption(caption); }
/** * Constructs an external image given a url, image dimensions, and a caption. * * @param url the url for the external image. * @param width the width of the image. * @param height the height of the image. * @param caption the caption for the image. */ public Image(String url, int width, int height, String caption) { this(); setUrl(url); setWidth(width); setHeight(height); setCaption(caption); }
@Override public BlipContent call(BlipContent source) { Image matchedImage = (Image) source; return new Image(matchedImage.getUrl() + "?query=foo", matchedImage.getWidth(), matchedImage.getHeight(), matchedImage.getCaption()); } });
public void testImageConstructor() { Image image = new Image(URL, WIDTH, HEIGHT, CAPTION); assertEquals(ElementType.IMAGE, image.getType()); assertNull(image.getAttachmentId()); assertEquals(CAPTION, image.getCaption()); assertEquals(URL, image.getUrl()); assertEquals(WIDTH, image.getWidth()); assertEquals(HEIGHT, image.getHeight()); }
blip.append(new Image(url, 100, 100, "Cool pix.")); assertEquals(2, blip.getElements().size()); List<BlipContent> result = blip.all(ElementType.IMAGE, Image.restrictByUrl(url)).values(); assertEquals(1, result.size()); blip.first("chars").replace(new Image(url, 200, 200, "Yet another cool pix.")); assertEquals(3, blip.getElements().size()); assertTrue(blip.getContent().startsWith("\n hello")); element = blip.at(1).value().asElement(); assertTrue(element instanceof Image); assertEquals("Yet another cool pix.", ((Image) element).getCaption()); blip.append(new Image(url, 100, 100, "Cool pix.")); blip.append(" some piece of text."); assertEquals("\n some piece of text.", blip.getContent()); assertEquals(url, ((Image) blip.first(ElementType.IMAGE).value()).getUrl()); blip.first(ElementType.IMAGE).insertAfter(new BlipContentFunction() { @Override blip.append(new Image(url, 100, 100, "Cool pix.")); blip.append(" some piece of text."); assertEquals("\n some piece of text.", blip.getContent()); assertEquals(url, ((Image) blip.first(ElementType.IMAGE).value()).getUrl()); blip.first(ElementType.IMAGE).replace(new BlipContentFunction() { @Override public BlipContent call(BlipContent source) { Image matchedImage = (Image) source; return new Image(matchedImage.getUrl() + "?query=foo", matchedImage.getWidth(),
public void testGetHeight() { Image image = new Image(); image.setHeight(HEIGHT); assertEquals(HEIGHT, image.getHeight()); image = new Image(); try { image.getHeight(); fail("Should have failed with IllegalStateException. Calling getHeight() is not allowed if " + "the image doesn't have a height."); } catch (IllegalStateException e) { // Expected. } } }
public void testGetWidth() { Image image = new Image(); image.setWidth(WIDTH); assertEquals(WIDTH, image.getWidth()); image = new Image(); try { image.getWidth(); fail("Should have failed with IllegalStateException. Calling getWidth() is not allowed if " + "the image doesn't have a width."); } catch (IllegalStateException e) { // Expected. } }
result = new Gadget(properties); } else if (type == ElementType.IMAGE) { result = new Image(properties); } else if (type == ElementType.ATTACHMENT) { byte[] data = null;
public void testUpdateElement() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); String url = "http://www.test.com/image.png"; blip.append(new Image(url, 100, 100, "Cool pix.")); assertEquals(2, blip.getElements().size()); // Update the image by appending a query param to the URL. blip.first(ElementType.IMAGE).updateElement(new MapFunction() { @Override public Map<String, String> call(BlipContent source) { Image matchedImage = (Image) source; Map<String, String> properties = new HashMap<String, String>(); properties.put("url", matchedImage.getUrl() + "?version=newversion"); return properties; } }); Image image = (Image) blip.first(ElementType.IMAGE).value(); assertEquals(url + "?version=newversion", image.getUrl()); }
public void testImageConstructor() { Image image = new Image(URL, WIDTH, HEIGHT, CAPTION); assertEquals(ElementType.IMAGE, image.getType()); assertNull(image.getAttachmentId()); assertEquals(CAPTION, image.getCaption()); assertEquals(URL, image.getUrl()); assertEquals(WIDTH, image.getWidth()); assertEquals(HEIGHT, image.getHeight()); }
@Override public Element fromXml(Document doc, E element, Wavelet wavelet) { Image image = new Image(); if (doc.getAttribute(element, "src") != null) { image.setUrl(doc.getAttribute(element, "src")); } if (doc.getAttribute(element, "alt") != null) { image.setCaption(doc.getAttribute(element, "alt")); } if (doc.getAttribute(element, "width") != null) { image.setWidth(Integer.parseInt(doc.getAttribute(element, "width"))); } if (doc.getAttribute(element, "height") != null) { image.setHeight(Integer.parseInt(doc.getAttribute(element, "height"))); } return image; } });
@Override public BlipContent call(BlipContent source) { Image matchedImage = (Image) source; return new Image(matchedImage.getUrl() + "?query=foo", matchedImage.getWidth(), matchedImage.getHeight(), matchedImage.getCaption()); } });
blip.append(new Image(url, 100, 100, "Cool pix.")); assertEquals(2, blip.getElements().size()); List<BlipContent> result = blip.all(ElementType.IMAGE, Image.restrictByUrl(url)).values(); assertEquals(1, result.size()); blip.first("chars").replace(new Image(url, 200, 200, "Yet another cool pix.")); assertEquals(3, blip.getElements().size()); assertTrue(blip.getContent().startsWith("\n hello")); element = blip.at(1).value().asElement(); assertTrue(element instanceof Image); assertEquals("Yet another cool pix.", ((Image) element).getCaption()); blip.append(new Image(url, 100, 100, "Cool pix.")); blip.append(" some piece of text."); assertEquals("\n some piece of text.", blip.getContent()); assertEquals(url, ((Image) blip.first(ElementType.IMAGE).value()).getUrl()); blip.first(ElementType.IMAGE).insertAfter(new BlipContentFunction() { @Override blip.append(new Image(url, 100, 100, "Cool pix.")); blip.append(" some piece of text."); assertEquals("\n some piece of text.", blip.getContent()); assertEquals(url, ((Image) blip.first(ElementType.IMAGE).value()).getUrl()); blip.first(ElementType.IMAGE).replace(new BlipContentFunction() { @Override public BlipContent call(BlipContent source) { Image matchedImage = (Image) source; return new Image(matchedImage.getUrl() + "?query=foo", matchedImage.getWidth(),
public void testGetHeight() { Image image = new Image(); image.setHeight(HEIGHT); assertEquals(HEIGHT, image.getHeight()); image = new Image(); try { image.getHeight(); fail("Should have failed with IllegalStateException. Calling getHeight() is not allowed if " + "the image doesn't have a height."); } catch (IllegalStateException e) { // Expected. } } }
public void testGetWidth() { Image image = new Image(); image.setWidth(WIDTH); assertEquals(WIDTH, image.getWidth()); image = new Image(); try { image.getWidth(); fail("Should have failed with IllegalStateException. Calling getWidth() is not allowed if " + "the image doesn't have a width."); } catch (IllegalStateException e) { // Expected. } }
public void testElementIterator() { Element element1 = new Gadget("http://www.google.com/gadget.xml"); Element element2 = new Image("attachment1", "the coolest photo"); Element element3 = new Gadget("http://www.google.com/foo.xml"); Element element4 = new Gadget("http://www.google.com/gadget.xml");
public void testUpdateElement() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); String url = "http://www.test.com/image.png"; blip.append(new Image(url, 100, 100, "Cool pix.")); assertEquals(2, blip.getElements().size()); // Update the image by appending a query param to the URL. blip.first(ElementType.IMAGE).updateElement(new MapFunction() { @Override public Map<String, String> call(BlipContent source) { Image matchedImage = (Image) source; Map<String, String> properties = new HashMap<String, String>(); properties.put("url", matchedImage.getUrl() + "?version=newversion"); return properties; } }); Image image = (Image) blip.first(ElementType.IMAGE).value(); assertEquals(url + "?version=newversion", image.getUrl()); }
public void testGettersAndSetters() { Image image = new Image(); image.setAttachmentId(ATTACHMENT_ID); image.setCaption(CAPTION); image.setUrl(URL); image.setWidth(WIDTH); image.setHeight(HEIGHT); assertEquals(ATTACHMENT_ID, image.getAttachmentId()); assertEquals(CAPTION, image.getCaption()); assertEquals(URL, image.getUrl()); assertEquals(WIDTH, image.getWidth()); assertEquals(HEIGHT, image.getHeight()); }