001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-setup/org/opencms/setup/comptest/CmsSetupTestSimapi.java,v $
003: * Date : $Date: 2008-02-27 12:05:32 $
004: * Version: $Revision: 1.2 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.setup.comptest;
033:
034: import com.alkacon.simapi.RenderSettings;
035: import com.alkacon.simapi.Simapi;
036: import com.alkacon.simapi.filter.ImageMath;
037: import com.alkacon.simapi.filter.RotateFilter;
038:
039: import org.opencms.setup.CmsSetupBean;
040:
041: import java.awt.image.BufferedImage;
042: import java.io.File;
043: import java.util.Arrays;
044: import java.util.Iterator;
045:
046: import javax.imageio.ImageIO;
047:
048: /**
049: * Tests the image processing capabilities.<p>
050: *
051: * @author Michael Moossen
052: *
053: * @version $Revision: 1.2 $
054: *
055: * @since 6.1.8
056: */
057: public class CmsSetupTestSimapi implements I_CmsSetupTest {
058:
059: /** The test name. */
060: public static final String TEST_NAME = "Image Processing";
061:
062: /**
063: * @see org.opencms.setup.comptest.I_CmsSetupTest#getName()
064: */
065: public String getName() {
066:
067: return TEST_NAME;
068: }
069:
070: /**
071: * @see org.opencms.setup.comptest.I_CmsSetupTest#execute(org.opencms.setup.CmsSetupBean)
072: */
073: public CmsSetupTestResult execute(CmsSetupBean setupBean) {
074:
075: CmsSetupTestResult testResult = new CmsSetupTestResult(this );
076: boolean ok = true;
077: Throwable ex = null;
078: try {
079: RenderSettings settings = new RenderSettings(
080: Simapi.RENDER_QUALITY);
081: settings.setCompressionQuality(0.85f);
082: Simapi simapi = new Simapi(settings);
083:
084: ImageIO.scanForPlugins();
085: Iterator pngReaders = ImageIO
086: .getImageReadersByFormatName(Simapi.TYPE_PNG);
087: if (!pngReaders.hasNext()) {
088: throw (new Exception(
089: "No Java ImageIO readers for the PNG format are available."));
090: }
091: Iterator pngWriters = ImageIO
092: .getImageWritersByFormatName(Simapi.TYPE_PNG);
093: if (!pngWriters.hasNext()) {
094: throw (new Exception(
095: "No Java ImageIO writers for the PNG format are available."));
096: }
097:
098: String basePath = setupBean.getWebAppRfsPath();
099: if (!basePath.endsWith(File.separator)) {
100: basePath += File.separator;
101: }
102: basePath += "setup" + File.separator + "resources"
103: + File.separator;
104:
105: BufferedImage img1 = Simapi.read(basePath + "test1.png");
106: BufferedImage img3 = simapi.applyFilter(img1,
107: new RotateFilter(ImageMath.PI));
108: simapi.write(img3, basePath + "test3.png", Simapi.TYPE_PNG);
109: BufferedImage img2 = Simapi.read(basePath + "test2.png");
110:
111: ok = Arrays.equals(simapi.getBytes(img2, Simapi.TYPE_PNG),
112: simapi.getBytes(img3, Simapi.TYPE_PNG));
113: } catch (Throwable e) {
114: ok = false;
115: ex = e;
116: }
117:
118: if (ok) {
119: testResult.setResult(RESULT_PASSED);
120: testResult.setGreen();
121: } else {
122: testResult.setYellow();
123: if (ex != null) {
124: testResult.setResult(RESULT_FAILED);
125: testResult.setHelp(ex.toString());
126: testResult
127: .setInfo("<p><code>-Djava.awt.headless=true</code> JVM parameter or X-Server may be missing.<br>"
128: + "<b>You can continue the setup, but image processing will be disabled.</b></p>");
129: } else {
130: testResult.setResult(RESULT_WARNING);
131: testResult
132: .setHelp("Image processing works but result does not exactly match.");
133: StringBuffer info = new StringBuffer();
134: info
135: .append("<p>Please check the following images for visible differences:</p>");
136: info.append("<table width='100%'>");
137: info
138: .append("<tr><th>Expected</th><th>Result</th></tr>");
139: info
140: .append("<tr><td align='center' width='50%'><img src='resources/test2.png'></td>");
141: info
142: .append("<td align='center' width='50%'><img src='resources/test3.png'></td></table>");
143: info
144: .append("<p><b>You can continue the setup, but image processing may not always work as expected.</b></p>");
145: testResult.setInfo(info.toString());
146: }
147: }
148: return testResult;
149: }
150: }
|