[jboss-cvs] jboss-seam/examples/blog/src/test ...
Peter Muir
peter at bleepbleep.org.uk
Sun Oct 7 19:31:47 EDT 2007
User: pmuir
Date: 07/10/07 19:31:47
Modified: examples/blog/src/test BlogTest.java
Log:
Add some theme tests
Revision Changes Path
1.21 +102 -0 jboss-seam/examples/blog/src/test/BlogTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: BlogTest.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/blog/src/test/BlogTest.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- BlogTest.java 27 Jun 2007 01:56:45 -0000 1.20
+++ BlogTest.java 7 Oct 2007 23:31:47 -0000 1.21
@@ -1,12 +1,18 @@
package test;
import java.util.List;
+import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+import javax.faces.model.SelectItem;
import javax.persistence.EntityManager;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.mock.SeamTest;
import org.jboss.seam.security.Identity;
+import org.jboss.seam.theme.Theme;
+import org.jboss.seam.theme.ThemeSelector;
import org.testng.annotations.Test;
import actions.BlogService;
@@ -178,4 +184,100 @@
}.run();
}
+ @Test
+ public void testSelectTheme() throws Exception
+ {
+ String id = new NonFacesRequest("/index.xhtml")
+ {
+
+ @Override
+ protected void renderResponse() throws Exception
+ {
+ List<SelectItem> themes = (List<SelectItem>) getValue("#{themeSelector.themes}");
+ assert themes.size() == 3;
+ assert themes.get(0).getLabel().equals("default");
+ assert themes.get(0).getLabel().equals("default");
+ assert "default".equals(getValue("#{themeSelector.theme}"));
+ assert "../screen.css".equals(getValue("#{theme.css}"));
+ assert "template.xhtml".equals(getValue("#{theme.template}"));
+ assert "foo".equals(getValue("#{theme.foo}"));
+ }
+
+ }.run();
+
+ new FacesRequest("/index.xhtml", id)
+ {
+ @Override
+ protected void updateModelValues() throws Exception {
+ setValue("#{themeSelector.theme}", "accessible");
+ }
+
+ @Override
+ protected void invokeApplication() throws Exception {
+ invokeAction("#{themeSelector.select}");
+ }
+
+ @Override
+ protected void renderResponse() throws Exception
+ {
+ assert "accessible".equals(getValue("#{themeSelector.theme}"));
+ assert "../accessible.css".equals(getValue("#{theme.css}"));
+ assert "template.xhtml".equals(getValue("#{theme.template}"));
+ }
+ }.run();
+
+ new FacesRequest("/index.xhtml", id)
+ {
+
+ @Override
+ protected void invokeApplication() throws Exception {
+ invokeAction("#{themeSelector.selectTheme('printable')}");
+ }
+
+ @Override
+ protected void renderResponse() throws Exception
+ {
+ assert "printable".equals(getValue("#{themeSelector.theme}"));
+ assert "../printable.css".equals(getValue("#{theme.css}"));
+ assert "print.xhtml".equals(getValue("#{theme.template}"));
+ Map<String, String> theme = Theme.instance();
+ assert theme.entrySet().size() == 2;
+ }
+ }.run();
+
+ new FacesRequest("/index.xhtml", id)
+ {
+ @Override
+ protected void updateModelValues() throws Exception {
+ setValue("#{themeSelector.theme}", "foo");
+ }
+
+ @Override
+ protected void invokeApplication() throws Exception {
+ invokeAction("#{themeSelector.select}");
+ }
+
+ @Override
+ protected void renderResponse() throws Exception
+ {
+ assert "foo".equals(getValue("#{themeSelector.theme}"));
+ Map<String, String> theme = Theme.instance();
+ ResourceBundle themeResources = ThemeSelector.instance().getThemeResourceBundle();
+ assert !themeResources.getKeys().hasMoreElements();
+ assert theme.entrySet().size() == 0;
+ boolean exception = false;
+ try
+ {
+ themeResources.getObject("bar");
+ }
+ catch (MissingResourceException e)
+ {
+ exception = true;
+ }
+ assert exception;
+ assert theme.get("bar").equals("bar");
+ }
+ }.run();
+ }
+
}
More information about the jboss-cvs-commits
mailing list