001: /*
002: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003: * Copyright (C) 2002-2005 NextApp, Inc.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package nextapp.echo2.app.test.componentxml;
031:
032: import java.io.InputStream;
033:
034: import nextapp.echo2.app.Button;
035: import nextapp.echo2.app.Extent;
036: import nextapp.echo2.app.ResourceImageReference;
037: import nextapp.echo2.app.Style;
038: import nextapp.echo2.app.StyleSheet;
039: import nextapp.echo2.app.componentxml.StyleSheetLoader;
040: import junit.framework.TestCase;
041:
042: /**
043: * Unit test(s) for <code>nextapp.echo2.app.componentxml.propertypeer.FontPeer</code>.
044: */
045: public class ImageReferencePeerTest extends TestCase {
046:
047: private StyleSheet styleSheet;
048:
049: /**
050: * @see junit.framework.TestCase#setUp()
051: */
052: public void setUp() throws Exception {
053: InputStream in = ImageReferencePeerTest.class
054: .getResourceAsStream("ImageReferencePeerTest.stylesheet");
055: styleSheet = StyleSheetLoader.load(in,
056: StyleSheetLoaderTest.class.getClassLoader());
057: in.close();
058: }
059:
060: public void testResourceImageReferenceInline() {
061: Style alphaStyle = styleSheet.getStyle(Button.class, "alpha");
062: assertTrue(alphaStyle.getProperty(Button.PROPERTY_ICON) instanceof ResourceImageReference);
063: ResourceImageReference icon = (ResourceImageReference) alphaStyle
064: .getProperty(Button.PROPERTY_ICON);
065: assertEquals("nextapp.echo2/test/componentxml/Alpha.png", icon
066: .getResource());
067: }
068:
069: public void testResourceImageReferencePlain() {
070: Style bravoStyle = styleSheet.getStyle(Button.class, "bravo");
071: assertTrue(bravoStyle.getProperty(Button.PROPERTY_ICON) instanceof ResourceImageReference);
072: ResourceImageReference icon = (ResourceImageReference) bravoStyle
073: .getProperty(Button.PROPERTY_ICON);
074: assertEquals("nextapp.echo2/test/componentxml/Bravo.png", icon
075: .getResource());
076: }
077:
078: public void testResourceImageReferenceDimensioned() {
079: Style charlieStyle = styleSheet.getStyle(Button.class,
080: "charlie");
081: assertTrue(charlieStyle.getProperty(Button.PROPERTY_ICON) instanceof ResourceImageReference);
082: ResourceImageReference icon = (ResourceImageReference) charlieStyle
083: .getProperty(Button.PROPERTY_ICON);
084: assertEquals("nextapp.echo2/test/componentxml/Charlie.png",
085: icon.getResource());
086: assertEquals(new Extent(20), icon.getWidth());
087: assertEquals(new Extent(30), icon.getHeight());
088: }
089:
090: public void testResourceImageReferenceContentTypeHalfDimensioned() {
091: Style deltaStyle = styleSheet.getStyle(Button.class, "delta");
092: assertTrue(deltaStyle.getProperty(Button.PROPERTY_ICON) instanceof ResourceImageReference);
093: ResourceImageReference icon = (ResourceImageReference) deltaStyle
094: .getProperty(Button.PROPERTY_ICON);
095: assertEquals("nextapp.echo2/test/componentxml/Delta.whoknows",
096: icon.getResource());
097: assertEquals("image/gif", icon.getContentType());
098: assertEquals(new Extent(30), icon.getWidth());
099: assertNull(icon.getHeight());
100: }
101: }
|