Author: hoang_to
Date: 2011-06-29 06:23:05 -0400 (Wed, 29 Jun 2011)
New Revision: 6775
Added:
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/java/org/exoplatform/portal/resource/MockResourceRenderer.java
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/skin/portal/
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/skin/portal/TestSkin/
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/skin/portal/TestSkin/Stylesheet.css
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/skin/portlet/
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/skin/portlet/Stylesheet.css
Modified:
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/java/org/exoplatform/portal/resource/MockServletContext.java
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/java/org/exoplatform/portal/resource/TestSkinService.java
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/java/org/exoplatform/portal/resource/TestSkipCommentReader.java
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/gatein-resources.xml
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/skin/Stylesheet.css
Log:
Update JUnit tests for SkinService
Added:
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/java/org/exoplatform/portal/resource/MockResourceRenderer.java
===================================================================
---
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/java/org/exoplatform/portal/resource/MockResourceRenderer.java
(rev 0)
+++
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/java/org/exoplatform/portal/resource/MockResourceRenderer.java 2011-06-29
10:23:05 UTC (rev 6775)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2011 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.portal.resource;
+
+import org.exoplatform.commons.utils.BinaryOutput;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.charset.Charset;
+
+/**
+ * A simple ResourceRenderer used in JUnit tests of SkinService
+ *
+ * @author <a href="hoang281283(a)gmail.com">Minh Hoang TO</a>
+ * @date 6/29/11
+ */
+public class MockResourceRenderer implements ResourceRenderer
+{
+
+ private final BinaryOutput output;
+
+ private final static Charset UTF_8 = Charset.forName("UTF-8");
+
+ public MockResourceRenderer(final OutputStream out)
+ {
+ this.output = new BinaryOutput()
+ {
+ public Charset getCharset()
+ {
+ return UTF_8;
+ }
+
+ public void write(byte b) throws IOException
+ {
+ out.write(b);
+ }
+
+ public void write(byte[] bytes) throws IOException
+ {
+ out.write(bytes);
+ }
+
+ public void write(byte[] bytes, int off, int len) throws IOException
+ {
+ out.write(bytes, off, len);
+ }
+ };
+ }
+
+ public BinaryOutput getOutput() throws IOException
+ {
+ return output;
+ }
+
+ public void setExpiration(long seconds)
+ {
+ }
+}
Modified:
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/java/org/exoplatform/portal/resource/MockServletContext.java
===================================================================
---
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/java/org/exoplatform/portal/resource/MockServletContext.java 2011-06-29
05:50:58 UTC (rev 6774)
+++
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/java/org/exoplatform/portal/resource/MockServletContext.java 2011-06-29
10:23:05 UTC (rev 6775)
@@ -47,7 +47,7 @@
public String getContextPath()
{
- return contextName;
+ return "/" + contextName;
}
public ServletContext getContext(String s)
@@ -77,12 +77,12 @@
public URL getResource(String s) throws MalformedURLException
{
- return loader.getResource(s);
+ return loader.getResource(contextName + s);
}
public InputStream getResourceAsStream(String s)
{
- return loader.getResourceAsStream(s);
+ return loader.getResourceAsStream(contextName + s);
}
public RequestDispatcher getRequestDispatcher(String s)
Modified:
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/java/org/exoplatform/portal/resource/TestSkinService.java
===================================================================
---
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/java/org/exoplatform/portal/resource/TestSkinService.java 2011-06-29
05:50:58 UTC (rev 6774)
+++
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/java/org/exoplatform/portal/resource/TestSkinService.java 2011-06-29
10:23:05 UTC (rev 6775)
@@ -25,9 +25,13 @@
import org.exoplatform.component.test.ContainerScope;
import org.exoplatform.container.PortalContainer;
import org.exoplatform.portal.resource.config.xml.SkinConfigParser;
+import java.io.ByteArrayOutputStream;
import java.io.InputStream;
+import java.lang.reflect.Method;
import java.net.URL;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
import javax.servlet.ServletContext;
/**
@@ -49,6 +53,9 @@
private volatile boolean initSkinService = true;
+ /** A cache of Method in SkinService, served for reflect invocation **/
+ private Map<String, Method> methodsOfSkinService = new HashMap<String,
Method>();
+
@Override
protected void setUp() throws Exception
{
@@ -61,7 +68,7 @@
mockServletContext = new MockServletContext("mockwebapp",
portalContainer.getPortalClassLoader());
skinService.registerContext(mockServletContext);
- processSkinConfiguration("mockwebapp/gatein-resources.xml");
+ processSkinConfiguration("/gatein-resources.xml");
}
}
@@ -111,7 +118,7 @@
SkinConfig firstPortletSkin =
skinService.getSkin("mockwebapp/FirstPortlet", "TestSkin");
assertNotNull(firstPortletSkin);
- assertEquals(mockServletContext.getContextPath() +
"/skin/FirstPortlet/Stylesheet.css", firstPortletSkin.getCSSPath());
+ assertEquals(mockServletContext.getContextPath() +
"/skin/portlet/FirstPortlet/Stylesheet.css", firstPortletSkin.getCSSPath());
}
public void testDeployedThemes()
@@ -119,16 +126,94 @@
}
- public void testRenderCSS()
+ public void testRenderLT_CSS() throws Exception
{
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ResourceRenderer renderer = new MockResourceRenderer(out);
+ skinService.renderCSS(renderer, "/mockwebapp/skin/Stylesheet-lt.css");
+
+ //TODO: Check the array of bytes in out
}
- public void testRenderCSSConcurrently()
+ public void testRenderRT_CSS() throws Exception
{
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ResourceRenderer renderer = new MockResourceRenderer(out);
+ skinService.renderCSS(renderer, "/mockwebapp/skin/Stylesheet-rt.css");
+
+ //TODO: Check the array of bytes in out
}
+ public void testBackground() throws Exception
+ {
+ }
+
+ public void testServiceCache() throws Exception
+ {
+ }
+
+ public void testSkinPriority() throws Exception
+ {
+ }
+
+ public void testUndeploySkinConfig() throws Exception
+ {
+ //TODO: Fork the work of GateInSkinConfigRemoval here
+ }
+
+ /**
+ * Designed to invoke reflectively private methods of SkinService. That facilitate
+ * writting JUnit tests
+ *
+ * @param methodName
+ * @param arguments
+ */
+ private void invokeMethodOfSkinService(String methodName, Object... arguments)
+ {
+ StringBuilder methodSignature = new StringBuilder(methodName);
+ Class<?>[] paramTypes = new Class<?>[arguments.length];
+ for(int i =0; i < arguments.length; i++)
+ {
+ paramTypes[i] = arguments[i].getClass();
+ methodSignature.append("_");
+ methodSignature.append(paramTypes[i].getName());
+ }
+ //First we look at the cache
+ Method method = methodsOfSkinService.get(methodSignature.toString());
+
+ //Find method by reflection
+ if(method == null)
+ {
+ try
+ {
+ method = skinService.getClass().getDeclaredMethod(methodName, paramTypes);
+ if(method != null)
+ {
+ method.setAccessible(true);
+ methodsOfSkinService.put(methodSignature.toString(), method);
+ }
+ else
+ {
+ return;
+ }
+ }
+ catch (NoSuchMethodException ex)
+ {
+ }
+ }
+
+ try
+ {
+ method.invoke(skinService, arguments);
+ }
+ catch(Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
@Override
protected void tearDown() throws Exception
{
Modified:
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/java/org/exoplatform/portal/resource/TestSkipCommentReader.java
===================================================================
---
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/java/org/exoplatform/portal/resource/TestSkipCommentReader.java 2011-06-29
05:50:58 UTC (rev 6774)
+++
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/java/org/exoplatform/portal/resource/TestSkipCommentReader.java 2011-06-29
10:23:05 UTC (rev 6775)
@@ -62,6 +62,7 @@
public void testFirstCSSFile() throws IOException
{
initiateReader("skin/test_1.css");
+ skipCommentReader.setCommentBlockHandler(new
CommentBlockHandler.OrientationCommentBlockHandler());
for(int i =0; i < 30; i++)
{
Modified:
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/gatein-resources.xml
===================================================================
---
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/gatein-resources.xml 2011-06-29
05:50:58 UTC (rev 6774)
+++
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/gatein-resources.xml 2011-06-29
10:23:05 UTC (rev 6775)
@@ -33,7 +33,7 @@
<application-name>mockwebapp</application-name>
<portlet-name>FirstPortlet</portlet-name>
<skin-name>TestSkin</skin-name>
- <css-path>/skin/FirstPortlet/Stylesheet.css</css-path>
+ <css-path>/skin/portlet/FirstPortlet/Stylesheet.css</css-path>
</portlet-skin>
<!-- Simple window style -->
Modified:
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/skin/Stylesheet.css
===================================================================
---
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/skin/Stylesheet.css 2011-06-29
05:50:58 UTC (rev 6774)
+++
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/skin/Stylesheet.css 2011-06-29
10:23:05 UTC (rev 6775)
@@ -16,7 +16,15 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
*/
-@import url(DefaultSkin/portal/webui/component/UIPortalApplicationSkin.css);
-@import url(DefaultSkin/webui/component/Stylesheet.css);
-@import url(PortletThemes/Stylesheet.css);
-@import url(Portlet/Stylesheet.css);
+.LeftBlock {
+ float: left; /* orientation=lt */
+ float: right; /* orientation=rt */
+}
+/* blah blah */
+aaaaaa
+@import url(portal/TestSkin/Stylesheet.css); /* blah blah */
+bbbbbb
+.RightBlock {
+ float: right; /* orientation=lt */
+ float: left; /* orientation=rt */
+}
\ No newline at end of file
Added:
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/skin/portal/TestSkin/Stylesheet.css
===================================================================
---
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/skin/portal/TestSkin/Stylesheet.css
(rev 0)
+++
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/skin/portal/TestSkin/Stylesheet.css 2011-06-29
10:23:05 UTC (rev 6775)
@@ -0,0 +1,21 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+.LeftBlock {
+ float: left; /* orientation=lt */ float: right; /* orientation=rt */
+}
\ No newline at end of file
Added:
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/skin/portlet/Stylesheet.css
===================================================================
---
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/skin/portlet/Stylesheet.css
(rev 0)
+++
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/skin/portlet/Stylesheet.css 2011-06-29
10:23:05 UTC (rev 6775)
@@ -0,0 +1,27 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+.LeftBlock {
+ float: left; /* orientation=lt */
+ float: right; /* orientation=rt */
+}
+/* blah blah */
+.RightBlock {
+ float: right; /* orientation=lt */
+ float: left; /* orientation=rt */
+}
\ No newline at end of file