diff options
author | Johannes Dahlström <johannesd@vaadin.com> | 2015-04-24 15:54:23 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-05-06 10:02:54 +0000 |
commit | 49ded4acd2682cc7dc888fb5d57b8afe47dc30d5 (patch) | |
tree | 1c92fe96e8064a7f57cd91206eec7a9be4b71315 /server/tests | |
parent | 0fcac7054158ec6dbd8e8707854ee2700be72439 (diff) | |
download | vaadin-framework-49ded4acd2682cc7dc888fb5d57b8afe47dc30d5.tar.gz vaadin-framework-49ded4acd2682cc7dc888fb5d57b8afe47dc30d5.zip |
Fix for declarative FontIcon support (#17275)
Change-Id: I5d61ed7003811f95bba4ded71937bb08742936c5
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java | 78 |
1 files changed, 77 insertions, 1 deletions
diff --git a/server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java b/server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java index 681b9d80a3..dcabd6c637 100644 --- a/server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java +++ b/server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java @@ -18,6 +18,7 @@ package com.vaadin.tests.design; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import java.io.File; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.Date; @@ -34,8 +35,12 @@ import com.vaadin.event.ShortcutAction.KeyCode; import com.vaadin.event.ShortcutAction.ModifierKey; import com.vaadin.server.ExternalResource; import com.vaadin.server.FileResource; +import com.vaadin.server.FontAwesome; +import com.vaadin.server.FontIcon; +import com.vaadin.server.GenericFontIcon; import com.vaadin.server.Resource; import com.vaadin.server.ThemeResource; +import com.vaadin.shared.ApplicationConstants; import com.vaadin.shared.util.SharedUtil; import com.vaadin.ui.declarative.DesignFormatter; @@ -265,6 +270,78 @@ public class DesignFormatterTest { } } + @Test + public void testResourceFormat() { + String httpUrl = "http://example.com/icon.png"; + String httpsUrl = "https://example.com/icon.png"; + String themePath = "icons/icon.png"; + String fontAwesomeUrl = "fonticon://FontAwesome/0xf0f9"; + String someOtherFontUrl = "fonticon://SomeOther/0xF0F9"; + String fileSystemPath = "c:\\app\\resources\\icon.png"; + + assertEquals(httpUrl, formatter.format(new ExternalResource(httpUrl))); + assertEquals(httpsUrl, formatter.format(new ExternalResource(httpsUrl))); + assertEquals(ApplicationConstants.THEME_PROTOCOL_PREFIX + themePath, + formatter.format(new ThemeResource(themePath))); + + assertEquals(fontAwesomeUrl, formatter.format(FontAwesome.AMBULANCE)); + assertEquals(someOtherFontUrl.toLowerCase(), + formatter.format(new GenericFontIcon("SomeOther", 0xf0f9)) + .toLowerCase()); + + assertEquals(fileSystemPath, + formatter.format(new FileResource(new File(fileSystemPath)))); + } + + @Test(expected = ConversionException.class) + public void testResourceParseException() { + String someRandomResourceUrl = "random://url"; + formatter.parse(someRandomResourceUrl, Resource.class); + } + + @Test(expected = ConversionException.class) + public void testResourceFormatException() { + formatter.format(new Resource() { // must use unknown resource type + @Override + public String getMIMEType() { + // TODO Auto-generated method stub + return null; + } + }); + } + + @Test + public void testResourceParse() { + String httpUrl = "http://example.com/icon.png"; + String httpsUrl = "https://example.com/icon.png"; + String themePath = "icons/icon.png"; + String fontAwesomeUrl = "fonticon://FontAwesome/0xf0f9"; + String someOtherFont = "fonticon://SomeOther/0xF0F9"; + String fontAwesomeUrlOld = "font://AMBULANCE"; + String fileSystemPath = "c:\\app\\resources\\icon.png"; + + assertEquals(new ExternalResource(httpUrl).getURL(), + formatter.parse(httpUrl, ExternalResource.class).getURL()); + assertEquals(new ExternalResource(httpsUrl).getURL(), + formatter.parse(httpsUrl, ExternalResource.class).getURL()); + assertEquals( + new ThemeResource(themePath), + formatter.parse(ApplicationConstants.THEME_PROTOCOL_PREFIX + + themePath, ThemeResource.class)); + assertEquals(FontAwesome.AMBULANCE, + formatter.parse(fontAwesomeUrlOld, FontAwesome.class)); + assertEquals(FontAwesome.AMBULANCE, + formatter.parse(fontAwesomeUrl, FontAwesome.class)); + assertEquals(new GenericFontIcon("SomeOther", 0xF0F9), + formatter.parse(someOtherFont, FontIcon.class)); + + assertEquals( + new FileResource(new File(fileSystemPath)).getSourceFile(), + formatter.parse(fileSystemPath, FileResource.class) + .getSourceFile()); + + } + /** * A static method to allow comparison two different actions. * @@ -294,5 +371,4 @@ public class DesignFormatterTest { } return false; } - } |