Author: hoang_to
Date: 2011-06-29 00:55:29 -0400 (Wed, 29 Jun 2011)
New Revision: 6773
Added:
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/resources/conf/skin-service-configuration.xml
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/
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/
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/skin/Stylesheet.css
Log:
Add first JUnit tests to SkinService
Added:
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
(rev 0)
+++
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/java/org/exoplatform/portal/resource/MockServletContext.java 2011-06-29
04:55:29 UTC (rev 6773)
@@ -0,0 +1,167 @@
+/*
+ * 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 java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Set;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+/**
+ * @author <a href="hoang281283(a)gmail.com">Minh Hoang TO</a>
+ * @date 6/29/11
+ */
+public class MockServletContext implements ServletContext
+{
+
+ private String contextName;
+
+ private ClassLoader loader;
+
+ public MockServletContext(String contextName, ClassLoader loader)
+ {
+ this.contextName = contextName;
+ this.loader = loader;
+ }
+
+ public String getContextPath()
+ {
+ return contextName;
+ }
+
+ public ServletContext getContext(String s)
+ {
+ return null;
+ }
+
+ public int getMajorVersion()
+ {
+ return 0;
+ }
+
+ public int getMinorVersion()
+ {
+ return 0;
+ }
+
+ public String getMimeType(String s)
+ {
+ return null;
+ }
+
+ public Set getResourcePaths(String s)
+ {
+ return null;
+ }
+
+ public URL getResource(String s) throws MalformedURLException
+ {
+ return loader.getResource(s);
+ }
+
+ public InputStream getResourceAsStream(String s)
+ {
+ return loader.getResourceAsStream(s);
+ }
+
+ public RequestDispatcher getRequestDispatcher(String s)
+ {
+ return null;
+ }
+
+ public RequestDispatcher getNamedDispatcher(String s)
+ {
+ return null;
+ }
+
+ public Servlet getServlet(String s) throws ServletException
+ {
+ return null;
+ }
+
+ public Enumeration getServlets()
+ {
+ return null;
+ }
+
+ public Enumeration getServletNames()
+ {
+ return null;
+ }
+
+ public void log(String s)
+ {
+ }
+
+ public void log(Exception e, String s)
+ {
+ }
+
+ public void log(String s, Throwable throwable)
+ {
+ }
+
+ public String getRealPath(String s)
+ {
+ return null;
+ }
+
+ public String getServerInfo()
+ {
+ return null;
+ }
+
+ public String getInitParameter(String s)
+ {
+ return null;
+ }
+
+ public Enumeration getInitParameterNames()
+ {
+ return null;
+ }
+
+ public Object getAttribute(String s)
+ {
+ return null;
+ }
+
+ public Enumeration getAttributeNames()
+ {
+ return null;
+ }
+
+ public void setAttribute(String s, Object o)
+ {
+ }
+
+ public void removeAttribute(String s)
+ {
+ }
+
+ public String getServletContextName()
+ {
+ return contextName;
+ }
+}
Added:
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
(rev 0)
+++
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/java/org/exoplatform/portal/resource/TestSkinService.java 2011-06-29
04:55:29 UTC (rev 6773)
@@ -0,0 +1,136 @@
+/*
+ * 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.xml.DocumentSource;
+import org.exoplatform.component.test.AbstractKernelTest;
+import org.exoplatform.component.test.ConfigurationUnit;
+import org.exoplatform.component.test.ConfiguredBy;
+import org.exoplatform.component.test.ContainerScope;
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.portal.resource.config.xml.SkinConfigParser;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Collection;
+import javax.servlet.ServletContext;
+
+/**
+ * @author <a href="hoang281283(a)gmail.com">Minh Hoang TO</a>
+ * @date 6/29/11
+ */
+@ConfiguredBy(
+ {
+ @ConfigurationUnit(scope = ContainerScope.PORTAL, path =
"conf/skin-service-configuration.xml")
+ }
+)
+public class TestSkinService extends AbstractKernelTest
+{
+ private PortalContainer portalContainer;
+
+ private SkinService skinService;
+
+ private ServletContext mockServletContext;
+
+ private volatile boolean initSkinService = true;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ if(initSkinService)
+ {
+ initSkinService = false;
+
+ portalContainer = getContainer();
+ skinService =
(SkinService)portalContainer.getComponentInstanceOfType(SkinService.class);
+ mockServletContext = new MockServletContext("mockwebapp",
portalContainer.getPortalClassLoader());
+ skinService.registerContext(mockServletContext);
+
+ processSkinConfiguration("mockwebapp/gatein-resources.xml");
+ }
+ }
+
+ private void processSkinConfiguration(String configResource) throws Exception
+ {
+ URL url = mockServletContext.getResource(configResource);
+ SkinConfigParser.processConfigResource(DocumentSource.create(url), skinService,
mockServletContext);
+ }
+
+ public void testInitService()
+ {
+ assertNotNull(portalContainer);
+ assertEquals("portal", portalContainer.getName());
+ assertNotNull(skinService);
+ }
+
+ public void testInitSkinModules()
+ {
+ assertNotNull(skinService.getAvailableSkinNames());
+ assertTrue(skinService.getAvailableSkinNames().contains("TestSkin"));
+ }
+
+ public void testInitThemes()
+ {
+
+ }
+
+ public void testDeployedSkinModules()
+ {
+ assertNotNull(skinService.getAvailableSkinNames());
+ assertTrue(skinService.getAvailableSkinNames().contains("TestSkin"));
+
+ Collection<SkinConfig> skinConfigs =
skinService.getPortalSkins("TestSkin");
+ assertNotNull(skinConfigs);
+
+ SkinConfig portalSkin = null;
+ for(SkinConfig config : skinConfigs)
+ {
+ if("TestSkin".equals(config.getName()))
+ {
+ portalSkin = config;
+ break;
+ }
+ }
+ assertNotNull(portalSkin);
+ assertEquals(mockServletContext.getContextPath() +
"/skin/Stylesheet.css", portalSkin.getCSSPath());
+
+ SkinConfig firstPortletSkin =
skinService.getSkin("mockwebapp/FirstPortlet", "TestSkin");
+ assertNotNull(firstPortletSkin);
+ assertEquals(mockServletContext.getContextPath() +
"/skin/FirstPortlet/Stylesheet.css", firstPortletSkin.getCSSPath());
+ }
+
+ public void testDeployedThemes()
+ {
+
+ }
+
+ public void testRenderCSS()
+ {
+
+ }
+
+ public void testRenderCSSConcurrently()
+ {
+
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ }
+}
Added:
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/conf/skin-service-configuration.xml
===================================================================
---
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/conf/skin-service-configuration.xml
(rev 0)
+++
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/conf/skin-service-configuration.xml 2011-06-29
04:55:29 UTC (rev 6773)
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ 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.
+
+-->
+
+<configuration
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd
http://www.exoplaform.org/xml/ns/kernel_1_1.xsd"
+
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd">
+
+ <component>
+
<key>org.exoplatform.portal.resource.compressor.ResourceCompressor</key>
+
<type>org.exoplatform.portal.resource.compressor.impl.ResourceCompressorService</type>
+ <component-plugins>
+ <component-plugin>
+ <name>MockCompressorPlugin</name>
+ <set-method>registerCompressorPlugin</set-method>
+
<type>org.exoplatform.portal.resource.compressor.MockCompressorPlugin</type>
+ <init-params>
+ <value-param>
+ <name>plugin.priority</name>
+ <value>5</value>
+ </value-param>
+ </init-params>
+ </component-plugin>
+
+ <component-plugin>
+ <name>JSMinCompressorPlugin</name>
+ <set-method>registerCompressorPlugin</set-method>
+
<type>org.exoplatform.portal.resource.compressor.impl.JSMinCompressorPlugin</type>
+ <init-params>
+ <value-param>
+ <name>plugin.priority</name>
+ <value>9</value>
+ </value-param>
+ </init-params>
+ </component-plugin>
+
+ <component-plugin>
+ <name>YUICSSCompressorPlugin</name>
+ <set-method>registerCompressorPlugin</set-method>
+
<type>org.exoplatform.portal.resource.compressor.css.YUICSSCompressorPlugin</type>
+ <init-params>
+ <value-param>
+ <name>plugin.priority</name>
+ <value>1</value>
+ </value-param>
+ <value-param>
+ <name>line.break.position</name>
+ <value>100</value>
+ </value-param>
+ </init-params>
+ </component-plugin>
+ </component-plugins>
+ </component>
+
+ <component>
+ <key>org.exoplatform.portal.resource.SkinService</key>
+ <type>org.exoplatform.portal.resource.SkinService</type>
+ </component>
+</configuration>
Added:
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
(rev 0)
+++
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/gatein-resources.xml 2011-06-29
04:55:29 UTC (rev 6773)
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<gatein-resources
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_resources_1_1
http://www.gatein.org/xml/ns/gatein_resources_1_1"
+
xmlns="http://www.gatein.org/xml/ns/gatein_resources_1_1">
+
+ <portal-skin>
+ <skin-name>TestSkin</skin-name>
+ <css-path>/skin/Stylesheet.css</css-path>
+ </portal-skin>
+
+ <portlet-skin>
+ <application-name>mockwebapp</application-name>
+ <portlet-name>FirstPortlet</portlet-name>
+ <skin-name>TestSkin</skin-name>
+ <css-path>/skin/FirstPortlet/Stylesheet.css</css-path>
+ </portlet-skin>
+
+ <!-- Simple window style -->
+ <window-style>
+ <style-name>Simple</style-name>
+ <style-theme>
+ <theme-name>SimpleBlue</theme-name>
+ </style-theme>
+ <style-theme>
+ <theme-name>SimpleViolet</theme-name>
+ </style-theme>
+ <style-theme>
+ <theme-name>SimpleOrange</theme-name>
+ </style-theme>
+ <style-theme>
+ <theme-name>SimplePink</theme-name>
+ </style-theme>
+ <style-theme>
+ <theme-name>SimpleGreen</theme-name>
+ </style-theme>
+ </window-style>
+
+ <!-- RoundConer window style -->
+ <window-style>
+ <style-name>RoundConer</style-name>
+ <style-theme>
+ <theme-name>RoundConerBlue</theme-name>
+ </style-theme>
+ <style-theme>
+ <theme-name>RoundConerViolet</theme-name>
+ </style-theme>
+ <style-theme>
+ <theme-name>RoundConerOrange</theme-name>
+ </style-theme>
+ <style-theme>
+ <theme-name>RoundConerPink</theme-name>
+ </style-theme>
+ <style-theme>
+ <theme-name>RoundConerGreen</theme-name>
+ </style-theme>
+ </window-style>
+
+ <!-- Shadow window style -->
+ <window-style>
+ <style-name>Shadow</style-name>
+ <style-theme>
+ <theme-name>ShadowBlue</theme-name>
+ </style-theme>
+ <style-theme>
+ <theme-name>ShadowViolet</theme-name>
+ </style-theme>
+ <style-theme>
+ <theme-name>ShadowOrange</theme-name>
+ </style-theme>
+ <style-theme>
+ <theme-name>ShadowPink</theme-name>
+ </style-theme>
+ <style-theme>
+ <theme-name>ShadowGreen</theme-name>
+ </style-theme>
+ </window-style>
+
+ <!-- MacStyle window style -->
+ <window-style>
+ <style-name>MacStyle</style-name>
+ <style-theme>
+ <theme-name>MacTheme</theme-name>
+ </style-theme>
+ <style-theme>
+ <theme-name>MacGray</theme-name>
+ </style-theme>
+ <style-theme>
+ <theme-name>MacGreenSteel</theme-name>
+ </style-theme>
+ </window-style>
+
+ <!-- VistaStyle window style -->
+ <window-style>
+ <style-name>VistaStyle</style-name>
+ <style-theme>
+ <theme-name>VistaTheme</theme-name>
+ </style-theme>
+ </window-style>
+
+</gatein-resources>
Added:
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
(rev 0)
+++
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/resources/mockwebapp/skin/Stylesheet.css 2011-06-29
04:55:29 UTC (rev 6773)
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+@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);