diff --git a/test/pom.xml b/test/pom.xml index a372aea880..b44001f8bb 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -151,7 +151,7 @@ THE SOFTWARE. org.jvnet.hudson htmlunit - 2.2-hudson-11 + 2.6-hudson-1 @@ -210,7 +210,7 @@ THE SOFTWARE. - + ${project.basedir}/../core/src/build-script ${project.basedir}/src/build-script/unitTest.groovy diff --git a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java index 92d272e2b8..6757c7b56b 100644 --- a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java +++ b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java @@ -23,6 +23,8 @@ */ package org.jvnet.hudson.test; +import com.gargoylesoftware.htmlunit.DefaultCssErrorHandler; +import com.gargoylesoftware.htmlunit.javascript.host.xml.XMLHttpRequest; import hudson.CloseProofOutputStream; import hudson.FilePath; import hudson.Functions; @@ -106,6 +108,9 @@ import javax.servlet.ServletContextEvent; import junit.framework.TestCase; +import net.sourceforge.htmlunit.corejs.javascript.Context; +import net.sourceforge.htmlunit.corejs.javascript.ContextFactory; +import net.sourceforge.htmlunit.corejs.javascript.ContextFactory.Listener; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.io.FileUtils; import org.apache.commons.beanutils.PropertyUtils; @@ -121,6 +126,7 @@ import org.kohsuke.stapler.MetaClassLoader; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; import org.kohsuke.stapler.Stapler; +import org.mortbay.jetty.MimeTypes; import org.mortbay.jetty.Server; import org.mortbay.jetty.bio.SocketConnector; import org.mortbay.jetty.security.HashUserRealm; @@ -128,10 +134,7 @@ import org.mortbay.jetty.security.UserRealm; import org.mortbay.jetty.webapp.Configuration; import org.mortbay.jetty.webapp.WebAppContext; import org.mortbay.jetty.webapp.WebXmlConfiguration; -import org.mozilla.javascript.Context; -import org.mozilla.javascript.ContextFactory; import org.mozilla.javascript.tools.debugger.Dim; -import org.mozilla.javascript.ContextFactory.Listener; import org.w3c.css.sac.CSSException; import org.w3c.css.sac.CSSParseException; import org.w3c.css.sac.ErrorHandler; @@ -149,7 +152,6 @@ import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlInput; import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine; import com.gargoylesoftware.htmlunit.javascript.host.Stylesheet; -import com.gargoylesoftware.htmlunit.javascript.host.XMLHttpRequest; /** * Base class for all Hudson test cases. @@ -303,7 +305,7 @@ public abstract class HudsonTestCase extends TestCase implements RootAction { @Override protected void runTest() throws Throwable { System.out.println("=== Starting "+ getClass().getSimpleName() + "." + getName()); - new JavaScriptEngine(null); // ensure that ContextFactory is initialized +// new JavaScriptEngine(null); // ensure that ContextFactory is initialized ContextFactory.getGlobal().addListener(rhinoContextListener); try { @@ -347,6 +349,7 @@ public abstract class HudsonTestCase extends TestCase implements RootAction { context.setClassLoader(getClass().getClassLoader()); context.setConfigurations(new Configuration[]{new WebXmlConfiguration(),new NoListenerConfiguration()}); server.setHandler(context); + context.setMimeTypes(MIME_TYPES); SocketConnector connector = new SocketConnector(); server.addConnector(connector); @@ -566,7 +569,9 @@ public abstract class HudsonTestCase extends TestCase implements RootAction { // this can be too late, depending on when this method is invoked. Functions.DEBUG_YUI = true; - return org.mozilla.javascript.tools.debugger.Main.mainEmbedded("Rhino debugger: "+getName()); + // TODO: port this back later +// return net.sourceforge.htmlunit.corejs.javascript.tools.debugger.Main.mainEmbedded("Rhino debugger: "+getName()); + return null; } /** @@ -1021,6 +1026,29 @@ public abstract class HudsonTestCase extends TestCase implements RootAction { return true; } }); + + setCssErrorHandler(new ErrorHandler() { + final ErrorHandler defaultHandler = new DefaultCssErrorHandler(); + + public void warning(CSSParseException exception) throws CSSException { + if (!ignore(exception)) + defaultHandler.warning(exception); + } + + public void error(CSSParseException exception) throws CSSException { + if (!ignore(exception)) + defaultHandler.error(exception); + } + + public void fatalError(CSSParseException exception) throws CSSException { + if (!ignore(exception)) + defaultHandler.fatalError(exception); + } + + private boolean ignore(CSSParseException e) { + return e.getURI().contains("/yui/"); + } + }); } /** @@ -1195,29 +1223,6 @@ public abstract class HudsonTestCase extends TestCase implements RootAction { } } - // we don't care CSS errors in YUI - final ErrorHandler defaultHandler = Stylesheet.CSS_ERROR_HANDLER; - Stylesheet.CSS_ERROR_HANDLER = new ErrorHandler() { - public void warning(CSSParseException exception) throws CSSException { - if(!ignore(exception)) - defaultHandler.warning(exception); - } - - public void error(CSSParseException exception) throws CSSException { - if(!ignore(exception)) - defaultHandler.error(exception); - } - - public void fatalError(CSSParseException exception) throws CSSException { - if(!ignore(exception)) - defaultHandler.fatalError(exception); - } - - private boolean ignore(CSSParseException e) { - return e.getURI().contains("/yui/"); - } - }; - // suppress INFO output from Spring, which is verbose Logger.getLogger("org.springframework").setLevel(Level.WARNING); @@ -1243,4 +1248,9 @@ public abstract class HudsonTestCase extends TestCase implements RootAction { * Specify this to a TCP/IP port number to have slaves started with the debugger. */ public static int SLAVE_DEBUG_PORT = Integer.getInteger(HudsonTestCase.class.getName()+".slaveDebugPort",-1); + + public static final MimeTypes MIME_TYPES = new MimeTypes(); + static { + MIME_TYPES.addMimeMapping("js","application/javascript"); + } } diff --git a/test/src/main/java/org/jvnet/hudson/test/rhino/CallStackFrame.java b/test/src/main/java/org/jvnet/hudson/test/rhino/CallStackFrame.java index 9a51981f33..c36c1d7eab 100644 --- a/test/src/main/java/org/jvnet/hudson/test/rhino/CallStackFrame.java +++ b/test/src/main/java/org/jvnet/hudson/test/rhino/CallStackFrame.java @@ -23,10 +23,10 @@ */ package org.jvnet.hudson.test.rhino; -import org.mozilla.javascript.Context; -import org.mozilla.javascript.Scriptable; -import org.mozilla.javascript.debug.DebugFrame; -import org.mozilla.javascript.debug.DebuggableScript; +import net.sourceforge.htmlunit.corejs.javascript.Context; +import net.sourceforge.htmlunit.corejs.javascript.Scriptable; +import net.sourceforge.htmlunit.corejs.javascript.debug.DebugFrame; +import net.sourceforge.htmlunit.corejs.javascript.debug.DebuggableScript; import java.util.SortedMap; import java.util.TreeMap; diff --git a/test/src/main/java/org/jvnet/hudson/test/rhino/JavaScriptDebugger.java b/test/src/main/java/org/jvnet/hudson/test/rhino/JavaScriptDebugger.java index 8ab2b71ceb..85774021be 100644 --- a/test/src/main/java/org/jvnet/hudson/test/rhino/JavaScriptDebugger.java +++ b/test/src/main/java/org/jvnet/hudson/test/rhino/JavaScriptDebugger.java @@ -23,10 +23,10 @@ */ package org.jvnet.hudson.test.rhino; -import org.mozilla.javascript.debug.Debugger; -import org.mozilla.javascript.debug.DebuggableScript; -import org.mozilla.javascript.debug.DebugFrame; -import org.mozilla.javascript.Context; +import net.sourceforge.htmlunit.corejs.javascript.Context; +import net.sourceforge.htmlunit.corejs.javascript.debug.DebugFrame; +import net.sourceforge.htmlunit.corejs.javascript.debug.DebuggableScript; +import net.sourceforge.htmlunit.corejs.javascript.debug.Debugger; import org.jvnet.hudson.test.HudsonTestCase; import java.util.List; diff --git a/test/src/test/java/hudson/model/QueueTest.java b/test/src/test/java/hudson/model/QueueTest.java index e824211e67..9f79987e16 100644 --- a/test/src/test/java/hudson/model/QueueTest.java +++ b/test/src/test/java/hudson/model/QueueTest.java @@ -218,7 +218,7 @@ public class QueueTest extends HudsonTestCase { // View for build should group duplicates WebClient wc = new WebClient(); - String buildPage = wc.getPage(build, "").asText(); + String buildPage = wc.getPage(build, "").asText().replace('\n',' '); assertTrue("Build page should combine duplicates and show counts: " + buildPage, buildPage.contains("Started by user anonymous (2 times) " + "Started by an SCM change (3 times) " diff --git a/test/src/test/java/lib/hudson/ListScmBrowsersTest.java b/test/src/test/java/lib/hudson/ListScmBrowsersTest.java index b7ae9c00f9..bfe773eb96 100644 --- a/test/src/test/java/lib/hudson/ListScmBrowsersTest.java +++ b/test/src/test/java/lib/hudson/ListScmBrowsersTest.java @@ -35,7 +35,7 @@ public class ListScmBrowsersTest extends HudsonTestCase { for (HtmlSelect select : selects) { Set title = new HashSet(); for(HtmlOption o : select.getOptions()) { - assertTrue("Duplicate entry: "+o.asText(),title.add(o.asText())); + assertTrue("Duplicate entry: "+o.getText(),title.add(o.getText())); } } }