1 29 30 package nextapp.echo2.app.test.componentxml; 31 32 import java.io.InputStream ; 33 34 import nextapp.echo2.app.FillImage; 35 import nextapp.echo2.app.Extent; 36 import nextapp.echo2.app.ImageReference; 37 import nextapp.echo2.app.ResourceImageReference; 38 import nextapp.echo2.app.Style; 39 import nextapp.echo2.app.StyleSheet; 40 import nextapp.echo2.app.componentxml.StyleSheetLoader; 41 import nextapp.echo2.app.text.TextComponent; 42 import junit.framework.TestCase; 43 44 47 public class FillImagePeerTest extends TestCase { 48 49 private StyleSheet styleSheet; 50 51 54 public void setUp() 55 throws Exception { 56 InputStream in = FillImagePeerTest.class.getResourceAsStream("FillImagePeerTest.stylesheet"); 57 styleSheet = StyleSheetLoader.load(in, StyleSheetLoaderTest.class.getClassLoader()); 58 in.close(); 59 } 60 61 public void testCustom() { 62 Style bravoStyle = styleSheet.getStyle(TextComponent.class, "bravo"); 63 FillImage backgroundImage = (FillImage) bravoStyle.getProperty(TextComponent.PROPERTY_BACKGROUND_IMAGE); 64 assertNotNull(backgroundImage); 65 ImageReference imageReference = backgroundImage.getImage(); 66 assertNotNull(imageReference); 67 assertTrue(imageReference instanceof ResourceImageReference); 68 assertEquals("nextapp/echo2/test/componentxml/BackgroundImage.png", 69 ((ResourceImageReference) imageReference).getResource()); 70 assertEquals(FillImage.REPEAT_HORIZONTAL, backgroundImage.getRepeat()); 71 assertEquals(new Extent(50), backgroundImage.getHorizontalOffset()); 72 assertEquals(new Extent(-30, Extent.PERCENT), backgroundImage.getVerticalOffset()); 73 } 74 75 public void testSimple() { 76 Style alphaStyle = styleSheet.getStyle(TextComponent.class, "alpha"); 77 FillImage backgroundImage = (FillImage) alphaStyle.getProperty(TextComponent.PROPERTY_BACKGROUND_IMAGE); 78 assertNotNull(backgroundImage); 79 ImageReference imageReference = backgroundImage.getImage(); 80 assertNotNull(imageReference); 81 assertTrue(imageReference instanceof ResourceImageReference); 82 assertEquals("nextapp/echo2/test/componentxml/BackgroundImage.png", 83 ((ResourceImageReference) imageReference).getResource()); 84 } 85 } 86 | Popular Tags |