001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.test.theme.tmp;
023:
024: import junit.framework.TestCase;
025: import org.jboss.portal.common.util.CLResourceLoader;
026: import org.jboss.portal.common.util.LoaderResource;
027: import org.jboss.portal.theme.PortalTheme;
028: import org.jboss.portal.theme.RuntimeContext;
029: import org.jboss.portal.theme.ThemeException;
030: import org.jboss.portal.theme.ThemeService;
031: import org.jboss.portal.theme.deployment.jboss.PortalThemeMetaDataFactory;
032: import org.jboss.portal.theme.impl.ThemeServiceImpl;
033: import org.jboss.portal.theme.metadata.PortalThemeMetaData;
034: import org.jboss.xb.binding.Unmarshaller;
035: import org.jboss.xb.binding.UnmarshallerFactory;
036: import org.xml.sax.SAXException;
037:
038: import javax.xml.parsers.ParserConfigurationException;
039: import java.io.IOException;
040: import java.util.Iterator;
041: import java.util.List;
042:
043: /**
044: * @author <a href="mailto:mholzner@novell.com">Martin Holzner</a>
045: * @author <a href="mailto:roy@jboss.org">Roy Russo</a>
046: * @version $Revision: 8784 $
047: */
048: public class TestThemeServiceImpl extends TestCase {
049: private ThemeService themeService;
050: private RuntimeContext runtimeContext;
051: List themes;
052:
053: protected void setUp() throws Exception {
054: themeService = new ThemeServiceImpl();
055:
056: runtimeContext = TestHelper.createRuntimeContext();
057: LoaderResource res = new CLResourceLoader()
058: .getResource("xml/portal-themes.xml");
059: Unmarshaller unmarshaller = UnmarshallerFactory.newInstance()
060: .newUnmarshaller();
061:
062: themes = (List) unmarshaller.unmarshal(res.asInputStream(),
063: new PortalThemeMetaDataFactory(), null);
064: for (Iterator i = themes.iterator(); i.hasNext();) {
065: PortalThemeMetaData themeMD = (PortalThemeMetaData) i
066: .next();
067: themeService.addTheme(runtimeContext, themeMD);
068: }
069: }
070:
071: protected void tearDown() throws Exception {
072: themeService = null;
073: }
074:
075: public void testCreateTheme() throws IOException,
076: ParserConfigurationException, SAXException {
077: try {
078: assertTrue(themeService.getThemes().size() == 5);
079:
080: PortalTheme theme = themeService.getTheme("industrial",
081: false);
082: assertTrue(theme.getThemeInfo().getName().equals(
083: "industrial"));
084: theme = themeService.getTheme("Nphalanx", false);
085: assertTrue(theme.getThemeInfo().getName()
086: .equals("Nphalanx"));
087: theme = themeService.getTheme("mission-critical", false);
088: assertTrue(theme.getThemeInfo().getName().equals(
089: "mission-critical"));
090: theme = themeService.getTheme("Maple", false);
091: assertTrue(theme.getThemeInfo().getName().equals("Maple"));
092: theme = themeService.getTheme("renaissance", false);
093: assertTrue(theme.getThemeInfo().getName().equals(
094: "renaissance"));
095: } catch (Exception e) {
096: assertTrue("unexpected exception occured", false);
097: }
098: }
099:
100: public void testGetThemeInfos() {
101: PortalTheme theme = themeService.getTheme("industrial", false);
102: assertEquals(theme.getThemeInfo().getName(), "industrial");
103: assertTrue(theme.getThemeInfo().getScripts().size() == 0);
104: assertTrue(theme.getThemeInfo().getLinks().size() == 2);
105:
106: theme = themeService.getTheme("Nphalanx", false);
107: assertEquals(theme.getThemeInfo().getName(), "Nphalanx");
108: assertTrue(theme.getThemeInfo().getScripts().size() == 0);
109: assertTrue(theme.getThemeInfo().getLinks().size() == 1);
110: }
111:
112: public void testRemoveTheme() throws ThemeException {
113: assertNotNull(themeService.getTheme("industrial", false));
114: themeService.removeTheme(themeService.getTheme("industrial",
115: false));
116: assertNull(themeService.getTheme("industrial", false));
117: }
118: }
|