Author: bdaw
Date: 2007-04-04 06:32:31 -0400 (Wed, 04 Apr 2007)
New Revision: 6913
Added:
trunk/widget/src/main/org/jboss/portal/test/
trunk/widget/src/main/org/jboss/portal/test/widget/
trunk/widget/src/main/org/jboss/portal/test/widget/google/
trunk/widget/src/main/org/jboss/portal/test/widget/google/PreferencesTestCase.java
trunk/widget/src/resources/test/
trunk/widget/src/resources/test/google/
trunk/widget/src/resources/test/google/gadget1.xml
trunk/widget/src/resources/test/google/gadget2.xml
Modified:
trunk/widget/build.xml
trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetBuilder.java
Log:
- startup for widgets tests
- tiny bugfix
Modified: trunk/widget/build.xml
===================================================================
--- trunk/widget/build.xml 2007-04-03 15:21:57 UTC (rev 6912)
+++ trunk/widget/build.xml 2007-04-04 10:32:31 UTC (rev 6913)
@@ -91,6 +91,7 @@
<path refid="jbossas/core.libs.classpath"/>
<path refid="jboss/backport.concurrent.classpath"/>
<path refid="apache.log4j.classpath"/>
+ <path refid="junit.junit.classpath"/>
</path>
<!-- Configure modules -->
@@ -220,4 +221,64 @@
<delete
file="${jboss.home}/server/${portal.deploy.dir}/widget.war"/>
</target>
+ <target name="package-tests" depends="init, output">
+ <!--Empty for now-->
+ <!--<jar jarfile="${build.lib}/portal-widget-test-lib.jar">
+ <fileset dir="${build.classes}"
includes="org/jboss/portal/test/**"/>
+ <fileset dir="${build.resources}/portal-widget-test-jar"/>
+ </jar>-->
+
+ </target>
+
+ <target name="tests" depends="init, package-tests">
+ <property name="proto-libs"
value="${project.root}/proto-libs"/>
+ <execute-tests>
+<!--
+
+ <x-sysproperty>
+ <jvmarg value="-Xdebug"/>
+ <jvmarg
value="-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y"/>
+ </x-sysproperty>
+-->
+
+
+ <x-test>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.widget.google.PreferencesTestCase"/>
+ </x-test>
+ <x-classpath>
+ <pathelement location="${build.lib}/widget-lib.jar"/>
+ <pathelement location="${build.resources}/test"/>
+ <pathelement location="${build.resources}"/>
+
+ <!--temp-->
+ <!--<pathelement
location="/home/bdaw/Workshop/libs/mysql-connector-java-5.0.4/mysql-connector-java-5.0.4-bin.jar"/>-->
+
+
+ <path refid="beanshell.beanshell.classpath"/>
+ <path refid="apache.commons.classpath"/>
+ <path refid="sun.opends.classpath"/>
+ <path refid="dom4j.dom4j.classpath"/>
+ <path refid="jboss.microcontainer.classpath"/>
+ <path refid="jboss.jbossxb.classpath"/>
+ <path refid="apache.xerces.classpath"/>
+ <path refid="oswego.concurrent.classpath"/>
+ <path refid="apache.logging.classpath"/>
+ <path refid="apache.log4j.classpath"/>
+ <path refid="hibernate.hibernate.classpath"/>
+ <path refid="antlr.antlr.classpath"/>
+ <path refid="asm.asm.classpath"/>
+ <path refid="apache.collections.classpath"/>
+ <path refid="jbossas/core.libs.classpath"/>
+ <path refid="junit.junit.classpath"/>
+ <path refid="apache.logging.classpath"/>
+ <path refid="cglib.cglib.classpath"/>
+ <path refid="jboss.portal-test.classpath"/>
+ <path refid="jboss.portal-common.classpath"/>
+ <path refid="jboss.portal-jems.classpath"/>
+ <path refid="sleepycat.sleepycat.classpath"/>
+ <path refid="sun.jaf.classpath"/>
+ </x-classpath>
+ </execute-tests>
+ </target>
+
</project>
Added: trunk/widget/src/main/org/jboss/portal/test/widget/google/PreferencesTestCase.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/test/widget/google/PreferencesTestCase.java
(rev 0)
+++
trunk/widget/src/main/org/jboss/portal/test/widget/google/PreferencesTestCase.java 2007-04-04
10:32:31 UTC (rev 6913)
@@ -0,0 +1,159 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.jboss.portal.test.widget.google;
+
+import junit.framework.TestCase;
+import org.jboss.portal.widget.google.provider.GGWidgetBuilder;
+import org.jboss.portal.widget.google.GGWidget;
+import org.jboss.portal.widget.google.GGPreferencesInfo;
+import org.jboss.portal.widget.google.GGPreferenceInfo;
+import org.jboss.portal.widget.google.type.DataType;
+import org.jboss.portal.widget.google.type.EnumType;
+import org.jboss.portal.common.util.Tools;
+
+import java.net.URL;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot
com">Boleslaw Dawidowicz</a>
+ * @version $Revision: 0.1 $
+ */
+public class PreferencesTestCase extends TestCase
+{
+ public void testModulePrefs() throws Exception
+ {
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ URL url = tcl.getResource("google/gadget1.xml");
+
+ GGWidgetBuilder ggwb = constructBuilder(url);
+ GGWidget ggw = ggwb.create();
+
+ assertNotNull(ggw);
+ assertEquals("TestTitle",ggw.getTitle().getDefaultString());
+ assertEquals("TestDescription",ggw.getDescription().getDefaultString());
+ }
+
+ public void testUserPrefs() throws Exception
+ {
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ URL url = tcl.getResource("google/gadget2.xml");
+
+ GGWidgetBuilder ggwb = constructBuilder(url);
+ GGWidget ggw = ggwb.create();
+
+ assertNotNull(ggw);
+
+ GGPreferencesInfo prefs = ggw.getPreferencesInfo();
+
+ // String
+ GGPreferenceInfo pi = prefs.getPreferenceInfo("testString");
+ assertNotNull(pi);
+ assertEquals("testString", pi.getName());
+ assertEquals("Test String", pi.getDisplayName());
+ assertEquals("testStringDefaultValue", pi.getDefaultValue());
+ assertEquals(DataType.STRING, pi.getType().getOrdinal());
+
+ // Default
+ pi = prefs.getPreferenceInfo("testDefault");
+ assertNotNull(pi);
+ assertEquals("testDefault", pi.getName());
+ assertEquals("Test Default", pi.getDisplayName());
+ assertEquals("testDefaultValue", pi.getDefaultValue());
+ assertEquals(DataType.STRING, pi.getType().getOrdinal());
+
+ // Required
+ pi = prefs.getPreferenceInfo("testRequired");
+ assertNotNull(pi);
+ assertEquals("testRequired", pi.getName());
+ assertEquals("Test Required", pi.getDisplayName());
+ assertEquals("testRequiredDefaultValue", pi.getDefaultValue());
+ assertEquals(DataType.STRING, pi.getType().getOrdinal());
+ assertTrue(pi.isRequired());
+
+ // Enum
+ pi = prefs.getPreferenceInfo("testEnum");
+ assertNotNull(pi);
+ assertEquals("testEnum", pi.getName());
+ assertEquals("Test Enum", pi.getDisplayName());
+ //assertEquals("testDefaultValue", pi.getDefaultValue());
+ assertEquals(DataType.ENUM, pi.getType().getOrdinal());
+ EnumType enumer = (EnumType)pi.getType();
+ assertEquals(3, enumer.getSize());
+ assertEquals("1", enumer.getValue(0).getValue());
+ assertEquals("enumOne", enumer.getValue(0).getDisplayValue());
+ assertEquals("2", enumer.getValue(1).getValue());
+ assertEquals("enumTwo", enumer.getValue(1).getDisplayValue());
+ assertEquals("3", enumer.getValue(2).getValue());
+ assertEquals("enumThree", enumer.getValue(2).getDisplayValue());
+
+ // Bool
+ pi = prefs.getPreferenceInfo("testBool");
+ assertNotNull(pi);
+ assertEquals("testBool", pi.getName());
+ assertEquals("Test Bool", pi.getDisplayName());
+ assertEquals("testBoolDefaultValue", pi.getDefaultValue());
+ assertEquals(DataType.BOOL, pi.getType().getOrdinal());
+
+ // Hidden
+ pi = prefs.getPreferenceInfo("testHidden");
+ assertNotNull(pi);
+ assertEquals("testHidden", pi.getName());
+ assertEquals("Test Hidden", pi.getDisplayName());
+ assertEquals("testHiddenDefaultValue", pi.getDefaultValue());
+ assertEquals(DataType.HIDDEN, pi.getType().getOrdinal());
+
+ // List
+ pi = prefs.getPreferenceInfo("testList");
+ assertNotNull(pi);
+ assertEquals("testList", pi.getName());
+ assertEquals("Test List", pi.getDisplayName());
+ assertEquals("one|two|three|four|five", pi.getDefaultValue());
+ assertEquals(DataType.LIST, pi.getType().getOrdinal());
+
+
+
+
+
+ }
+
+ public GGWidgetBuilder constructBuilder(URL url) throws Exception
+ {
+ return new GGWidgetBuilder(url)
+ {
+ protected byte[] obtainWidget(URL url) throws Exception
+ {
+ File file = new File(url.getPath());
+ InputStream io = new FileInputStream(file);
+ byte[] bytes = Tools.getBytes(io);
+ io.close();
+ return bytes;
+ }
+ };
+ }
+
+
+
+
+}
Modified:
trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetBuilder.java
===================================================================
---
trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetBuilder.java 2007-04-03
15:21:57 UTC (rev 6912)
+++
trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetBuilder.java 2007-04-04
10:32:31 UTC (rev 6913)
@@ -52,7 +52,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-class GGWidgetBuilder implements ObjectLoader
+public class GGWidgetBuilder implements ObjectLoader
{
/** . */
@@ -92,7 +92,7 @@
{
DocumentBuilderFactory factory = XML.getDocumentBuilderFactory();
DocumentBuilder builder = factory.newDocumentBuilder();
- byte[] bytes = URLTools.performGET(url, 5000, 5000);
+ byte[] bytes = obtainWidget(url);
if (bytes == null)
{
throw new Exception("Cannot retrieve document " + url);
@@ -107,7 +107,7 @@
{
Element userPref = (Element)userPrefsEltIterator.next();
String nameAttr = userPref.getAttribute("name");
- String displayNameAttr = userPref.getAttribute("displayName");
+ String displayNameAttr = userPref.getAttribute("display_name");
String urlParamAttr = userPref.getAttribute("urlparam");
String dataTypeAttr = userPref.getAttribute("datatype");
String requiredAttr = userPref.getAttribute("required");
@@ -200,4 +200,9 @@
throw new Exception(); // Basic for now
}
}
+
+ protected byte[] obtainWidget(URL url) throws Exception
+ {
+ return URLTools.performGET(url, 5000, 5000);
+ }
}
Added: trunk/widget/src/resources/test/google/gadget1.xml
===================================================================
--- trunk/widget/src/resources/test/google/gadget1.xml (rev 0)
+++ trunk/widget/src/resources/test/google/gadget1.xml 2007-04-04 10:32:31 UTC (rev 6913)
@@ -0,0 +1,16 @@
+<Module>
+ <ModulePrefs title="TestTitle" height="500"
scaling="false" directory_title="TestDirectoryTitle"
+ author_location="TestAuthorLocation"
title_url="TestURL"
+ screenshot="TestScreenshot"
+ thumbnail="TestThumbnail"
+ description="TestDescription"
+ author="TestAuthor" author_email="TestAuthorEmail"
+ author_affiliation="TestAuthorAffiliation"/>
+ <UserPref>
+
+ </UserPref>
+ <UserPref>
+
+ </UserPref>
+ <Content/>
+</Module>
\ No newline at end of file
Added: trunk/widget/src/resources/test/google/gadget2.xml
===================================================================
--- trunk/widget/src/resources/test/google/gadget2.xml (rev 0)
+++ trunk/widget/src/resources/test/google/gadget2.xml 2007-04-04 10:32:31 UTC (rev 6913)
@@ -0,0 +1,46 @@
+<Module>
+ <ModulePrefs title="TestTitle" height="500"
scaling="false" directory_title="TestDirectoryTitle"
+ author_location="TestAuthorLocation"
title_url="TestURL"
+ screenshot="TestScreenshot"
+ thumbnail="TestThumbnail"
+ description="TestDescription"
+ author="TestAuthor" author_email="TestAuthorEmail"
+ author_affiliation="TestAuthorAffiliation"/>
+ <UserPref name="testString"
+ display_name="Test String"
+ datatype="string"
+ default_value="testStringDefaultValue"/>
+ <UserPref name="testDefault"
+ display_name="Test Default"
+ default_value="testDefaultValue"/>
+ <UserPref name="testRequired"
+ display_name="Test Required"
+ datatype="string"
+ required="true"
+ default_value="testRequiredDefaultValue"/>
+ <UserPref name="testEnum"
+ display_name="Test Enum"
+ datatype="enum"
+ default_value="2">
+ <EnumValue value="1" display_value="enumOne"/>
+ <EnumValue value="2" display_value="enumTwo"/>
+ <EnumValue value="3" display_value="enumThree"/>
+ </UserPref>
+ <UserPref name="testBool"
+ display_name="Test Bool"
+ datatype="bool"
+ default_value="testBoolDefaultValue"/>
+ <UserPref name="testHidden"
+ display_name="Test Hidden"
+ datatype="hidden"
+ default_value="testHiddenDefaultValue"/>
+ <UserPref name="testList"
+ display_name="Test List"
+ datatype="list"
+ default_value="one|two|three|four|five"/>
+ <UserPref name="testLocation"
+ display_name="Test Location"
+ datatype="location"
+ default_value="1 1"/>
+ <Content/>
+</Module>
\ No newline at end of file