Author: ppitonak(a)redhat.com
Date: 2011-01-11 04:49:12 -0500 (Tue, 11 Jan 2011)
New Revision: 20939
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jMediaOutput/
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jMediaOutput/TestImage.java
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JMediaOutputBean.java
modules/tests/metamer/trunk/application/src/main/resources/org/richfaces/tests/metamer/bean/A4JMediaOutputBean.properties
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jMediaOutput/image.xhtml
Log:
https://issues.jboss.org/browse/RFPL-1046
* sample for a4j:mediaOutput rewritten
* added 31 tests for media output
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JMediaOutputBean.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JMediaOutputBean.java 2011-01-10
22:35:38 UTC (rev 20938)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JMediaOutputBean.java 2011-01-11
09:49:12 UTC (rev 20939)
@@ -1,6 +1,6 @@
/*******************************************************************************
* JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
+ * Copyright 2010-2011, Red Hat, Inc. and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -22,9 +22,7 @@
package org.richfaces.tests.metamer.bean;
import java.awt.Color;
-import java.awt.Font;
import java.awt.Graphics2D;
-import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
@@ -96,57 +94,24 @@
public void paint(OutputStream out, Object data) throws IOException {
if (data instanceof MediaData) {
MediaData paintData = (MediaData) data;
- BufferedImage img = new BufferedImage(paintData.width, paintData.height,
BufferedImage.TYPE_INT_RGB);
- Graphics2D g2d = img.createGraphics();
+ BufferedImage img = new BufferedImage(paintData.getWidth(),
paintData.getHeight(), BufferedImage.TYPE_INT_RGB);
+ Graphics2D graphics2D = img.createGraphics();
+ graphics2D.clearRect(0, 0, paintData.getWidth(), paintData.getHeight());
- g2d.setColor(Color.WHITE);
- g2d.fillRect(0, 0, paintData.width, paintData.height);
+ graphics2D.setColor(Color.YELLOW);
+ graphics2D.fillRect(0, 0, paintData.width / 2, paintData.height / 2);
- int testLenght = paintData.text.length();
- int fontSize = testLenght < 8 ? 40 : 40 - (testLenght - 8);
+ graphics2D.setColor(Color.RED);
+ graphics2D.fillRect(paintData.width / 2, 0, paintData.width / 2,
paintData.height / 2);
- if (fontSize < 12) {
- fontSize = 12;
- }
+ graphics2D.setColor(Color.BLUE);
+ graphics2D.fillRect(0, paintData.height / 2, paintData.width / 2,
paintData.height / 2);
- Font font = new Font("Serif", Font.HANGING_BASELINE, fontSize);
+ graphics2D.setColor(Color.GREEN);
+ graphics2D.fillRect(paintData.width / 2, paintData.height / 2,
paintData.width / 2, paintData.height / 2);
- g2d.setFont(font);
-
- int x = 10;
- int y = fontSize * 5 / 2;
-
- g2d.translate(x, y);
-
- Color color = new Color(paintData.color);
-
- g2d.setPaint(new Color(color.getRed(), color.getGreen(), color.getBlue(),
30));
-
- AffineTransform origTransform = g2d.getTransform();
-
- g2d.shear(-0.5 * paintData.scale, 0);
- g2d.scale(1, paintData.scale);
- g2d.drawString(paintData.text, 0, 0);
- g2d.setTransform(origTransform);
- g2d.setPaint(color);
- g2d.drawString(paintData.text, 0, 0);
- ImageIO.write(img, "jpeg", out);
+ ImageIO.write(img, "png", out);
}
-
-// if (data instanceof MediaData) {
-//
-// MediaData paintData = (MediaData) data;
-// BufferedImage img = new
BufferedImage(paintData.getWidth(),paintData.getHeight(),BufferedImage.TYPE_INT_RGB);
-// Graphics2D graphics2D = img.createGraphics();
-// graphics2D.clearRect(0,0,paintData.getWidth(),paintData.getHeight());
-// graphics2D.drawLine(5,5,paintData.getWidth()-5,paintData.getHeight()-5);
-// graphics2D.drawChars(new
String("RichFaces").toCharArray(),0,9,40,15);
-// graphics2D.drawChars(new
String("mediaOutput").toCharArray(),0,11,5,45);
-//
-// ImageIO.write(img,"jpeg",out);
-//
-// }
-
}
private void copy(InputStream in, OutputStream out) throws IOException {
Modified:
modules/tests/metamer/trunk/application/src/main/resources/org/richfaces/tests/metamer/bean/A4JMediaOutputBean.properties
===================================================================
---
modules/tests/metamer/trunk/application/src/main/resources/org/richfaces/tests/metamer/bean/A4JMediaOutputBean.properties 2011-01-10
22:35:38 UTC (rev 20938)
+++
modules/tests/metamer/trunk/application/src/main/resources/org/richfaces/tests/metamer/bean/A4JMediaOutputBean.properties 2011-01-11
09:49:12 UTC (rev 20939)
@@ -0,0 +1,3 @@
+attr.dir.lrt=ltr
+attr.dir.rtl=rtl
+attr.dir.null=
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jMediaOutput/image.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jMediaOutput/image.xhtml 2011-01-10
22:35:38 UTC (rev 20938)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jMediaOutput/image.xhtml 2011-01-11
09:49:12 UTC (rev 20939)
@@ -6,7 +6,7 @@
<!--
JBoss, Home of Professional Open Source
-Copyright 2010, Red Hat, Inc. and individual contributors
+Copyright 2010-2011, Red Hat, Inc. and individual contributors
by the @authors tag. See the copyright.txt in the distribution for a
full listing of individual contributors.
@@ -63,7 +63,7 @@
ismap="#{a4jMediaOutputBean.attributes['ismap'].value}"
lang="#{a4jMediaOutputBean.attributes['lang'].value}"
lastModified="#{a4jMediaOutputBean.attributes['lastModified'].value}"
- mimeType="image/jpeg"
+ mimeType="image/png"
onblur="#{a4jMediaOutputBean.attributes['onblur'].value}"
onclick="#{a4jMediaOutputBean.attributes['onclick'].value}"
ondblclick="#{a4jMediaOutputBean.attributes['ondblclick'].value}"
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jMediaOutput/TestImage.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jMediaOutput/TestImage.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jMediaOutput/TestImage.java 2011-01-11
09:49:12 UTC (rev 20939)
@@ -0,0 +1,270 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ *******************************************************************************/
+package org.richfaces.tests.metamer.ftest.a4jMediaOutput;
+
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.awt.Color;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.net.URL;
+
+import javax.imageio.ImageIO;
+
+import org.jboss.test.selenium.dom.Event;
+import org.jboss.test.selenium.locator.Attribute;
+import org.jboss.test.selenium.locator.AttributeLocator;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.testng.annotations.Test;
+
+/**
+ * Test case for page /faces/components/a4jMediaOutput/image.xhtml
+ *
+ * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
+ * @version $Revision$
+ */
+public class TestImage extends AbstractMetamerTest {
+
+ private JQueryLocator image = pjq("img[id$=mediaOutput]");
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/a4jMediaOutput/image.xhtml");
+ }
+
+ @Test
+ public void testImage() {
+ AttributeLocator imageURLAttr = image.getAttribute(Attribute.SRC);
+ URL imageURL = buildUrl(contextRoot, selenium.getAttribute(imageURLAttr));
+
+ BufferedImage bufferedImage = null;
+
+ try {
+ bufferedImage = ImageIO.read(imageURL);
+ } catch (IOException ex) {
+ fail("Could not download image from URL " + imageURL.getPath());
+ }
+
+ assertEquals(bufferedImage.getHeight(), 120, "Height of the image");
+ assertEquals(bufferedImage.getWidth(), 300, "Width of the image");
+
+ for (int x = 0; x < 150; x++) {
+ for (int y = 0; y < 60; y++) {
+ assertEquals(bufferedImage.getRGB(x, y), Color.YELLOW.getRGB(),
"Top-left quadrant should be yellow [" + x + ", " + y +
"].");
+ }
+ }
+
+ for (int x = 151; x < 300; x++) {
+ for (int y = 0; y < 60; y++) {
+ assertEquals(bufferedImage.getRGB(x, y), Color.RED.getRGB(),
"Top-right quadrant should be red [" + x + ", " + y +
"].");
+ }
+ }
+
+ for (int x = 0; x < 150; x++) {
+ for (int y = 61; y < 120; y++) {
+ assertEquals(bufferedImage.getRGB(x, y), Color.BLUE.getRGB(),
"Bottom-left quadrant should be blue [" + x + ", " + y +
"].");
+ }
+ }
+
+ for (int x = 151; x < 300; x++) {
+ for (int y = 61; y < 120; y++) {
+ assertEquals(bufferedImage.getRGB(x, y), Color.GREEN.getRGB(),
"Bottom-right quadrant should be yellow [" + x + ", " + y +
"].");
+ }
+ }
+ }
+
+ @Test
+ public void testAccesskey() {
+ testHtmlAttribute("accesskey", "r");
+ }
+
+ @Test
+ public void testAlign() {
+ testHtmlAttribute("align", "left");
+ }
+
+ @Test
+ public void testBorder() {
+ testHtmlAttribute("border", "3");
+ }
+
+ @Test
+ public void testCharset() {
+ testHtmlAttribute("charset", "utf-8");
+ }
+
+ @Test
+ public void testCoords() {
+ testHtmlAttribute("coords", "circle: 150, 60, 60");
+ }
+
+ @Test
+ public void testDir() {
+ testDir(image);
+ }
+
+ @Test
+ public void testHreflang() {
+ testHtmlAttribute("hreflang", "sk");
+ }
+
+ @Test
+ public void testIsmap() {
+ AttributeLocator<?> attr = image.getAttribute(new
Attribute("ismap"));
+ assertFalse(selenium.isAttributePresent(attr), "Attribute ismap should not
be present.");
+
+
selenium.click(pjq("input[type=radio][name$=ismapInput][value=true]"));
+ selenium.waitForPageToLoad();
+
+ assertTrue(selenium.isAttributePresent(attr), "Attribute ismap should be
present.");
+ assertEquals(selenium.getAttribute(attr), "ismap", "Attribute
dir");
+ }
+
+ @Test
+ public void testOnblur() {
+ testFireEvent(Event.BLUR, image);
+ }
+
+ @Test
+ public void testOnclick() {
+ testFireEvent(Event.CLICK, image);
+ }
+
+ @Test
+ public void testOndblclick() {
+ testFireEvent(Event.DBLCLICK, image);
+ }
+
+ @Test
+ public void testOnfocus() {
+ testFireEvent(Event.FOCUS, image);
+ }
+
+ @Test
+ public void testOnkeydown() {
+ testFireEvent(Event.KEYDOWN, image);
+ }
+
+ @Test
+ public void testOnkeypress() {
+ testFireEvent(Event.KEYPRESS, image);
+ }
+
+ @Test
+ public void testOnkeyup() {
+ testFireEvent(Event.KEYUP, image);
+ }
+
+ @Test
+ public void testOnmousedown() {
+ testFireEvent(Event.MOUSEDOWN, image);
+ }
+
+ @Test
+ public void testOnmousemove() {
+ testFireEvent(Event.MOUSEMOVE, image);
+ }
+
+ @Test
+ public void testOnmouseout() {
+ testFireEvent(Event.MOUSEOUT, image);
+ }
+
+ @Test
+ public void testOnmouseover() {
+ testFireEvent(Event.MOUSEOVER, image);
+ }
+
+ @Test
+ public void testOnmouseup() {
+ testFireEvent(Event.MOUSEUP, image);
+ }
+
+ @Test
+ public void testRel() {
+ testHtmlAttribute("rel", "metamer");
+ }
+
+ @Test
+ public void testRendered() {
+ JQueryLocator input =
pjq("input[type=radio][name$=renderedInput][value=false]");
+ selenium.click(input);
+ selenium.waitForPageToLoad();
+
+ assertFalse(selenium.isElementPresent(image), "Image should not be rendered
when rendered=false.");
+ }
+
+ @Test
+ public void testRev() {
+ testHtmlAttribute("rev", "metamer");
+ }
+
+ @Test
+ public void testShape() {
+ testHtmlAttribute("shape", "default");
+ }
+
+ @Test
+ public void testStyle() {
+ testStyle(image, "style");
+ }
+
+ @Test
+ public void testStyleClass() {
+ testStyleClass(image, "styleClass");
+ }
+
+ @Test
+ public void testTabindex() {
+ testHtmlAttribute("tabindex", "50");
+ }
+
+ @Test
+ public void testTarget() {
+ testHtmlAttribute("target", "_blank");
+ }
+
+ @Test
+ public void testTitle() {
+ testTitle(image);
+ }
+
+ @Test
+ public void testUsemap() {
+ testHtmlAttribute("usemap", "metamer");
+ }
+
+ private void testHtmlAttribute(String attribute, String value) {
+ AttributeLocator<?> attr = image.getAttribute(new Attribute(attribute));
+ assertFalse(selenium.isAttributePresent(attr), "Attribute " + attribute
+ " should not be present.");
+
+ selenium.type(pjq("input[id$=" + attribute + "Input]"),
value);
+ selenium.waitForPageToLoad();
+
+ assertTrue(selenium.getAttribute(attr).contains(value), "Attribute " +
attribute + " should contain \"" + value + "\".");
+ }
+}
Property changes on:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jMediaOutput/TestImage.java
___________________________________________________________________
Name: svn:keywords
+ Revision