Author: nbelaevski
Date: 2008-04-25 15:39:22 -0400 (Fri, 25 Apr 2008)
New Revision: 8201
Added:
trunk/framework/test/src/test/resources/META-INF/skins/dynabase1.skin.properties
trunk/framework/test/src/test/resources/META-INF/skins/dynabase2.skin.properties
trunk/framework/test/src/test/resources/META-INF/skins/dynatest.skin.properties
trunk/framework/test/src/test/resources/META-INF/skins/dynatest_base.skin.properties
trunk/framework/test/src/test/resources/META-INF/skins/style_base.skin.properties
Modified:
trunk/framework/test/pom.xml
trunk/framework/test/src/test/java/org/richfaces/skin/SkinTestCase.java
trunk/framework/test/src/test/resources/META-INF/skins/style.skin.properties
Log:
Skins implementation refeactored again, several issues fixed, tests added
Modified: trunk/framework/test/pom.xml
===================================================================
--- trunk/framework/test/pom.xml 2008-04-25 19:11:42 UTC (rev 8200)
+++ trunk/framework/test/pom.xml 2008-04-25 19:39:22 UTC (rev 8201)
@@ -70,19 +70,4 @@
<version>1.6R7</version>
</dependency>
</dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <excludes>
- <exclude>**/SkinTestCase.java</exclude>
- </excludes>
- </configuration>
- </plugin>
-
- </plugins>
-
- </build>
</project>
\ No newline at end of file
Modified: trunk/framework/test/src/test/java/org/richfaces/skin/SkinTestCase.java
===================================================================
--- trunk/framework/test/src/test/java/org/richfaces/skin/SkinTestCase.java 2008-04-25
19:11:42 UTC (rev 8200)
+++ trunk/framework/test/src/test/java/org/richfaces/skin/SkinTestCase.java 2008-04-25
19:39:22 UTC (rev 8201)
@@ -26,301 +26,215 @@
import java.util.Properties;
import javax.faces.FacesException;
-import javax.faces.FactoryFinder;
-import javax.faces.application.Application;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.el.ValueBinding;
-import junit.framework.TestCase;
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
-import org.easymock.MockControl;
-import org.easymock.classextension.MockClassControl;
-
/**
* Test for Skin/skin factory methods.
* @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
* @version $Revision: 1.1.2.1 $ $Date: 2007/01/10 14:28:13 $
*
*/
-public class SkinTestCase extends TestCase {
- private MockControl contextControl;
- private FacesContext mockContext;
+public class SkinTestCase extends AbstractAjax4JsfTestCase {
- private MockControl externalContextControl;
- private ExternalContext mockExternalContext;
-
- private TestApplicationFactory appFactory;
-
- private MockControl bindingControl;
- private ValueBinding mockBinding;
- private MockControl bindingSkinControl;
- private ValueBinding mockSkinBinding;
+ public SkinTestCase(String name) {
+ super(name);
+ }
- public SkinTestCase(String name) {
- super(name);
- }
+ public void setUp() throws Exception {
+ super.setUp();
+ }
- protected void setUp() throws Exception {
- contextControl = MockClassControl.createControl(FacesContext.class);
- mockContext = (FacesContext) contextControl.getMock();
- externalContextControl = MockClassControl.createControl(ExternalContext.class);
- mockExternalContext = (ExternalContext) externalContextControl.getMock();
- bindingControl = MockClassControl.createNiceControl(ValueBinding.class);
- mockBinding = (ValueBinding) bindingControl.getMock();
- bindingSkinControl = MockClassControl.createNiceControl(ValueBinding.class);
- mockSkinBinding = (ValueBinding) bindingSkinControl.getMock();
- FactoryFinder.releaseFactories();
- FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
TestApplicationFactory.class.getName());
- appFactory = (TestApplicationFactory)
FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
- super.setUp();
- }
+ public void tearDown() throws Exception {
+ SkinFactory.reset();
+ super.tearDown();
+ }
- protected void tearDown() throws Exception {
- FactoryFinder.releaseFactories();
- SkinFactory.reset();
- super.tearDown();
- }
+ /*
+ * Test method for 'org.richfaces.skin.SkinFactory.getInstance()'
+ */
+ public void testGetInstance() {
+ SkinFactory factory = SkinFactory.getInstance();
+ SkinFactory factory1 = SkinFactory.getInstance();
+ assertSame(factory,factory1);
+ }
- /*
- * Test method for 'org.richfaces.skin.SkinFactory.getInstance()'
- */
- public void testGetInstance() {
- SkinFactory factory = SkinFactory.getInstance();
- SkinFactory factory1 = SkinFactory.getInstance();
- assertSame(factory,factory1);
+ private void addParameters(Object[][] strings) {
+ Map<Object,Object> baseMap = new HashMap<Object, Object>();
+ for (Object[] objects : strings) {
+ baseMap.put(objects[0], objects[1]);
}
- /*
- * Test method for 'org.richfaces.skin.SkinFactory.getSkin(FacesContext)'
- */
- public void testGetSkin() {
- SkinFactory factory = SkinFactory.getInstance();
- // setup context mock
- mockContext.getExternalContext();
- contextControl.setReturnValue(mockExternalContext);
- contextControl.replay();
- // setup External context mock
- mockExternalContext.getInitParameter(SkinFactory.SKIN_PARAMETER);
- externalContextControl.setReturnValue("test");
- externalContextControl.replay();
- // setup Application mock
- Application app = appFactory.getApplication();
- app.createValueBinding("#{test.bean}");
- appFactory.getApplicationControl().setReturnValue(mockBinding);
- appFactory.getApplicationControl().replay();
- // setup Value binding mock.
- mockBinding.getValue(mockContext);
- bindingControl.setReturnValue("test.value");
- mockBinding.getValue(mockContext);
- bindingControl.setReturnValue("test.value1");
- bindingControl.setDefaultReturnValue("test.value");
- bindingControl.replay();
- // test call
- Skin skin = factory.getSkin(mockContext);
- // calls control
- contextControl.verify();
- externalContextControl.verify();
- appFactory.getApplicationControl().verify();
- assertNotNull("Null skin!",skin);
- // test properties
- assertEquals("string",skin.getParameter(mockContext,"string.property"));
- assertEquals("base.string",skin.getParameter(mockContext,"base.property"));
- assertEquals("test.value",skin.getParameter(mockContext,"bind.property"));
-// assertEquals("HTML_BASIC",skin.getRenderKitId(mockContext));
- }
+ externalContext.getRequestMap().put("test", baseMap);
+ }
- /*
- * Test method for 'org.richfaces.skin.SkinFactory.getSkin(FacesContext)'
- */
- public void testSkinReferences() {
- SkinFactory factory = SkinFactory.getInstance();
- // setup context mock
- mockContext.getExternalContext();
- contextControl.setReturnValue(mockExternalContext);
- contextControl.replay();
- // setup External context mock
- mockExternalContext.getInitParameter(SkinFactory.SKIN_PARAMETER);
- externalContextControl.setReturnValue("test");
- externalContextControl.replay();
- // setup Application mock
- Application app = appFactory.getApplication();
- app.createValueBinding("#{test.bean}");
- appFactory.getApplicationControl().setReturnValue(mockBinding);
- appFactory.getApplicationControl().replay();
- // setup Value binding mock.
- mockBinding.getValue(mockContext);
- bindingControl.setReturnValue("test.value");
- mockBinding.getValue(mockContext);
- bindingControl.setReturnValue("test.value1");
- bindingControl.setDefaultReturnValue("test.value");
- bindingControl.replay();
- // test call
- Skin skin = factory.getSkin(mockContext);
- // calls control
- contextControl.verify();
- externalContextControl.verify();
- appFactory.getApplicationControl().verify();
- assertNotNull("Null skin!",skin);
- assertEquals("default",skin.getParameter(mockContext,"c"));
- assertEquals("yyy",skin.getParameter(mockContext,"y"));
- }
+ /*
+ * Test method for 'org.richfaces.skin.SkinFactory.getSkin(FacesContext)'
+ */
+ public void testGetSkin() {
+ servletContext.addInitParameter(SkinFactory.SKIN_PARAMETER, "test");
- /*
- * Test method for 'org.richfaces.skin.SkinFactory.getSkin(FacesContext)'
- */
- public void testCyclicSkinReferences() {
- SkinFactory factory = SkinFactory.getInstance();
- // setup context mock
- mockContext.getExternalContext();
- contextControl.setReturnValue(mockExternalContext);
- contextControl.replay();
- // setup External context mock
- mockExternalContext.getInitParameter(SkinFactory.SKIN_PARAMETER);
- externalContextControl.setReturnValue("cyclic");
- externalContextControl.replay();
- // test call
- try {
- Skin skin = factory.getSkin(mockContext);
- } catch(FacesException e){
- return;
- }
- assertTrue(false);
- }
+ addParameters(new Object[][]{new Object[] {"bean", "test.value"}});
- /*
- * Test method for 'org.richfaces.skin.SkinFactory.getSkin(FacesContext)'
- */
- public void testBadSkinReferences() {
- SkinFactory factory = SkinFactory.getInstance();
- // setup context mock
- mockContext.getExternalContext();
- contextControl.setReturnValue(mockExternalContext);
- contextControl.replay();
- // setup External context mock
- mockExternalContext.getInitParameter(SkinFactory.SKIN_PARAMETER);
- externalContextControl.setReturnValue("noref");
- externalContextControl.replay();
- // test call
- try {
- Skin skin = factory.getSkin(mockContext);
- } catch(FacesException e){
- return;
- }
- assertTrue(false);
- }
- /*
- * Test method for 'org.richfaces.skin.SkinFactory.getSkin(FacesContext)'
- */
- public void testGetBindedSkin() {
- SkinFactory factory = SkinFactory.getInstance();
- // setup context mock
- mockContext.getExternalContext();
- contextControl.setReturnValue(mockExternalContext);
- mockContext.getApplication();
- contextControl.setReturnValue(appFactory.getApplication());
- contextControl.replay();
- // setup External context mock
- mockExternalContext.getInitParameter(SkinFactory.SKIN_PARAMETER);
- externalContextControl.setReturnValue("#{test.skin}");
- externalContextControl.replay();
- // setup Application mock
- Application app = appFactory.getApplication();
- app.createValueBinding("#{test.skin}");
- appFactory.getApplicationControl().setReturnValue(mockSkinBinding);
- app.createValueBinding("#{test.bean}");
- appFactory.getApplicationControl().setReturnValue(mockBinding);
- appFactory.getApplicationControl().replay();
- // setup Value binding mock.
- mockBinding.getValue(mockContext);
- bindingControl.setReturnValue("binded.test.value");
- bindingControl.replay();
- // skin EL binding.
- mockSkinBinding.getValue(mockContext);
- bindingSkinControl.setDefaultReturnValue("bindedtest");
- bindingSkinControl.replay();
- // test call
- Skin skin = factory.getSkin(mockContext);
- assertNotNull("Null skin!",skin);
- // test properties
- assertEquals("bindedstring",skin.getParameter(mockContext,"string.property"));
-// assertEquals("base.string",skin.getParameter(mockContext,"base.property"));
- assertEquals("binded.test.value",skin.getParameter(mockContext,"bind.property"));
- assertEquals("TEST",skin.getRenderKitId(mockContext));
+ SkinFactory factory = SkinFactory.getInstance();
+ // test call
+ Skin skin = factory.getSkin(facesContext);
+ assertNotNull("Null skin!",skin);
+ // test properties
+ assertEquals("string",skin.getParameter(facesContext,
"string.property"));
+ assertEquals("base.string",skin.getParameter(facesContext,
"base.property"));
+ assertEquals("test.value",skin.getParameter(facesContext,
"bind.property"));
+ // assertEquals("HTML_BASIC",skin.getRenderKitId(mockContext));
+ }
-
- // calls control
-// contextControl.verify();
-// externalContextControl.verify();
-// appFactory.getApplicationControl().verify();
-// bindingControl.verify();
-// bindingSkinControl.verify();
-}
-
- public void testSkinHash() {
- SkinFactory factory = SkinFactory.getInstance();
- // setup context mock
- mockContext.getExternalContext();
- contextControl.setDefaultReturnValue(mockExternalContext);
- mockContext.getApplication();
- contextControl.setReturnValue(appFactory.getApplication());
- contextControl.replay();
- // setup External context mock
- mockExternalContext.getInitParameter(SkinFactory.SKIN_PARAMETER);
- externalContextControl.setReturnValue("#{test.skin}");
- Map params = new HashMap();
- mockExternalContext.getRequestMap();
- externalContextControl.setDefaultReturnValue(params);
- externalContextControl.replay();
- // setup Application mock
- Application app = appFactory.getApplication();
- app.createValueBinding("#{test.skin}");
- appFactory.getApplicationControl().setReturnValue(mockSkinBinding);
- app.createValueBinding("#{test.bean}");
- appFactory.getApplicationControl().setReturnValue(mockBinding);
- appFactory.getApplicationControl().replay();
- // setup Value binding mock.
- mockBinding.getValue(mockContext);
- bindingControl.setDefaultReturnValue("binded.test.value");
- bindingControl.replay();
- // skin EL binding.
- mockSkinBinding.getValue(mockContext);
- bindingSkinControl.setDefaultReturnValue("bindedtest");
- bindingSkinControl.replay();
- // test call
- Skin skin = factory.getSkin(mockContext);
- assertNotNull("Null skin!",skin);
- // test properties
- int hash = skin.hashCode(mockContext);
- assertTrue(params.containsKey(BasicSkinImpl.REQUEST_HASH_CODES_MAP_PARAMETER));
- assertEquals(hash,skin.hashCode(mockContext));
- params.clear();
- assertEquals(hash,skin.hashCode(mockContext));
- // setup Value binding mock for different value - hash must differ.
- params.clear();
- bindingControl.reset();
- mockBinding.getValue(mockContext);
- bindingControl.setDefaultReturnValue("other.test.value");
- bindingControl.replay();
- assertFalse( hash==skin.hashCode(mockContext) );
+ /*
+ * Test method for 'org.richfaces.skin.SkinFactory.getSkin(FacesContext)'
+ */
+ public void testSkinReferences() {
+ SkinFactory factory = SkinFactory.getInstance();
+ servletContext.addInitParameter(SkinFactory.SKIN_PARAMETER, "test");
+ // test call
+ Skin skin = factory.getSkin(facesContext);
+ assertNotNull("Null skin!",skin);
+ assertEquals("default",skin.getParameter(facesContext, "c"));
+ assertEquals("yyy",skin.getParameter(facesContext, "y"));
+ }
+
+ /*
+ * Test method for 'org.richfaces.skin.SkinFactory.getSkin(FacesContext)'
+ */
+ public void testSkinReferences1() {
+ SkinFactory factory = SkinFactory.getInstance();
+ servletContext.addInitParameter(SkinFactory.SKIN_PARAMETER, "style");
+ servletContext.addInitParameter(SkinFactory.BASE_SKIN_PARAMETER,
"style_base");
+
+ // test call
+ Skin skin = factory.getSkin(facesContext);
+ assertNotNull("Null skin!",skin);
+ assertEquals("#F5F0E7",skin.getParameter(facesContext,
"intermediateTextColor"));
+ assertEquals("10px",skin.getParameter(facesContext,
"intermediateTextSize"));
+ assertEquals("#F5F0E7",skin.getParameter(facesContext,
"generalTextColor"));
+
+ assertEquals("white.textcolor",skin.getParameter(facesContext,
"additionalTextColor"));
+ }
+
+ public void testBaseSkin() {
+ SkinFactory factory = SkinFactory.getInstance();
+ servletContext.addInitParameter(SkinFactory.SKIN_PARAMETER, "dynatest");
+ servletContext.addInitParameter(SkinFactory.BASE_SKIN_PARAMETER,
"dynatest_base");
+ addParameters(new Object[][]{new Object[] {"bean", "dynabase1"}});
+
+ Skin skin = factory.getSkin(facesContext);
+ assertEquals("default", skin.getParameter(facesContext,
"default"));
+ assertEquals("itself", skin.getParameter(facesContext,
"selfValue"));
+ assertEquals("#AAA", skin.getParameter(facesContext,
"customFormColor"));
+
+ Map map = (Map) externalContext.getRequestMap().get("test");
+ map.put("bean", "dynabase2");
+
+ assertEquals("xxx", skin.getParameter(facesContext, "default"));
+ assertEquals("itself", skin.getParameter(facesContext,
"selfValue"));
+ assertEquals("#AAA", skin.getParameter(facesContext,
"customFormColor"));
+ }
+
+ /*
+ * Test method for 'org.richfaces.skin.SkinFactory.getSkin(FacesContext)'
+ */
+ public void testCyclicSkinReferences() {
+ SkinFactory factory = SkinFactory.getInstance();
+ servletContext.addInitParameter(SkinFactory.SKIN_PARAMETER, "cyclic");
+
+ try {
+ Skin skin = factory.getSkin(facesContext);
+ skin.getParameter(facesContext, "x");
+ fail();
+ } catch(FacesException e){
+ //it's ok
}
- /*
- * Test method for 'org.richfaces.skin.SkinFactory.getDefaultProperties()'
- */
- public void testGetDefaultProperties() {
- SkinFactoryImpl factory = (SkinFactoryImpl) SkinFactory.getInstance();
- Properties defaultProps = factory.getDefaultSkinProperties();
-// assertEquals("HTML_BASIC",defaultProps.getProperty("render.kit"));
- // Second default config
- assertEquals("default",defaultProps.getProperty("a"));
- }
+ }
- /*
- * Test method for 'org.richfaces.skin.SkinFactory.getSkinName(FacesContext)'
- */
- public void testGetSkinName() {
+ /*
+ * Test method for 'org.richfaces.skin.SkinFactory.getSkin(FacesContext)'
+ */
+ public void testBadSkinReferences() {
+ SkinFactory factory = SkinFactory.getInstance();
+ servletContext.addInitParameter(SkinFactory.SKIN_PARAMETER, "noref");
+ // test call
+ try {
+ Skin skin = factory.getSkin(facesContext);
+ skin.getParameter(facesContext, "x");
+ fail();
+ } catch(FacesException e){
+ //it's ok
}
+ }
+ /*
+ * Test method for 'org.richfaces.skin.SkinFactory.getSkin(FacesContext)'
+ */
+ public void testGetBindedSkin() {
+ SkinFactory factory = SkinFactory.getInstance();
+ servletContext.addInitParameter(SkinFactory.SKIN_PARAMETER, "#{test.skin}");
+ addParameters(new Object[][] {
+ new Object[] {"skin", "bindedtest"},
+ new Object[] {"bean", "binded.test.value"}
+ });
+
+ // test call
+ Skin skin = factory.getSkin(facesContext);
+ assertNotNull("Null skin!",skin);
+ // test properties
+ assertEquals("bindedstring",skin.getParameter(facesContext,
"string.property"));
+ // assertEquals("base.string",skin.getParameter(mockContext,"base.property"));
+ assertEquals("binded.test.value",skin.getParameter(facesContext,
"bind.property"));
+ assertEquals("TEST",skin.getRenderKitId(facesContext));
+ }
+
+ public void testSkinHash() {
+ SkinFactory factory = SkinFactory.getInstance();
+ servletContext.addInitParameter(SkinFactory.SKIN_PARAMETER, "#{test.skin}");
+
+ addParameters(new Object[][] {
+ new Object[] {"skin", "bindedtest"},
+ new Object[] {"bean", "binded.test.value"}
+ });
+
+ Skin skin = factory.getSkin(facesContext);
+ Map<String, Object> requestMap =
facesContext.getExternalContext().getRequestMap();
+
+ // test properties
+ int hash = skin.hashCode(facesContext);
+ assertTrue(requestMap.containsKey(BasicSkinImpl.REQUEST_HASH_CODES_MAP_PARAMETER));
+ assertEquals(hash,skin.hashCode(facesContext));
+ requestMap.remove(BasicSkinImpl.REQUEST_HASH_CODES_MAP_PARAMETER);
+ assertEquals(hash,skin.hashCode(facesContext));
+ // setup Value binding mock for different value - hash must differ.
+ requestMap.remove(BasicSkinImpl.REQUEST_HASH_CODES_MAP_PARAMETER);
+
+ Map map = (Map) requestMap.get("test");
+ map.put("bean", "other.test.value");
+
+ assertFalse( hash==skin.hashCode(facesContext) );
+
+ }
+ /*
+ * Test method for 'org.richfaces.skin.SkinFactory.getDefaultProperties()'
+ */
+ public void testGetDefaultProperties() {
+ SkinFactoryImpl factory = (SkinFactoryImpl) SkinFactory.getInstance();
+ Properties defaultProps = factory.getDefaultSkinProperties();
+ // assertEquals("HTML_BASIC",defaultProps.getProperty("render.kit"));
+ // Second default config
+ assertEquals("default",defaultProps.getProperty("a"));
+ }
+
+ /*
+ * Test method for
'org.richfaces.skin.SkinFactory.getSkinName(FacesContext)'
+ */
+ public void testGetSkinName() {
+
+ }
+
}
Added: trunk/framework/test/src/test/resources/META-INF/skins/dynabase1.skin.properties
===================================================================
--- trunk/framework/test/src/test/resources/META-INF/skins/dynabase1.skin.properties
(rev 0)
+++
trunk/framework/test/src/test/resources/META-INF/skins/dynabase1.skin.properties 2008-04-25
19:39:22 UTC (rev 8201)
@@ -0,0 +1,2 @@
+default=&a
+selfBase=&selfValue
\ No newline at end of file
Added: trunk/framework/test/src/test/resources/META-INF/skins/dynabase2.skin.properties
===================================================================
--- trunk/framework/test/src/test/resources/META-INF/skins/dynabase2.skin.properties
(rev 0)
+++
trunk/framework/test/src/test/resources/META-INF/skins/dynabase2.skin.properties 2008-04-25
19:39:22 UTC (rev 8201)
@@ -0,0 +1,2 @@
+default=&x
+selfBase=&selfValue
\ No newline at end of file
Added: trunk/framework/test/src/test/resources/META-INF/skins/dynatest.skin.properties
===================================================================
--- trunk/framework/test/src/test/resources/META-INF/skins/dynatest.skin.properties
(rev 0)
+++
trunk/framework/test/src/test/resources/META-INF/skins/dynatest.skin.properties 2008-04-25
19:39:22 UTC (rev 8201)
@@ -0,0 +1,5 @@
+baseSkin=#{test.bean}
+
+self=&selfBase
+
+selfValue=itself
\ No newline at end of file
Added:
trunk/framework/test/src/test/resources/META-INF/skins/dynatest_base.skin.properties
===================================================================
--- trunk/framework/test/src/test/resources/META-INF/skins/dynatest_base.skin.properties
(rev 0)
+++
trunk/framework/test/src/test/resources/META-INF/skins/dynatest_base.skin.properties 2008-04-25
19:39:22 UTC (rev 8201)
@@ -0,0 +1 @@
+customFormColor=#AAA
Modified: trunk/framework/test/src/test/resources/META-INF/skins/style.skin.properties
===================================================================
---
trunk/framework/test/src/test/resources/META-INF/skins/style.skin.properties 2008-04-25
19:11:42 UTC (rev 8200)
+++
trunk/framework/test/src/test/resources/META-INF/skins/style.skin.properties 2008-04-25
19:39:22 UTC (rev 8201)
@@ -1,3 +1,8 @@
generalStyleSheet=resource\://skin/style.xcss
intermediateTextColor=&customFormColor
-generalTextColor=&intermediateTextColor
\ No newline at end of file
+intermediateTextSize=&intermediateTextSizeBase
+
+generalTextColor=&intermediateTextColor
+
+additionalTextColor=&additionalBaseTextColor
+textColor=white.textcolor
Added: trunk/framework/test/src/test/resources/META-INF/skins/style_base.skin.properties
===================================================================
--- trunk/framework/test/src/test/resources/META-INF/skins/style_base.skin.properties
(rev 0)
+++
trunk/framework/test/src/test/resources/META-INF/skins/style_base.skin.properties 2008-04-25
19:39:22 UTC (rev 8201)
@@ -0,0 +1,4 @@
+intermediateTextColor=green.intermediate
+intermediateTextSizeBase=10px
+additionalBaseTextColor=&textColor
+defaultBaseTextColor=&customFormColor
\ No newline at end of file