You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/07/01 22:38:30 UTC
svn commit: r959774 - in /myfaces/test/trunk: test12/
test12/src/main/java/org/apache/myfaces/test/base/
test12/src/main/java/org/apache/myfaces/test/base/junit4/
test12/src/main/java/org/apache/myfaces/test/htmlunit/junit4/
test12/src/test/java/org/ap...
Author: lu4242
Date: Thu Jul 1 20:38:30 2010
New Revision: 959774
URL: http://svn.apache.org/viewvc?rev=959774&view=rev
Log:
MYFACESTEST-14 Update myfaces-test to use JUnit 4.x
Added:
myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/base/junit4/
myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java
myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java
myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/htmlunit/junit4/
myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/htmlunit/junit4/AbstractHtmlUnitTestCase.java
myfaces/test/trunk/test12/src/test/java/org/apache/myfaces/test/mock/MockBean.java
- copied, changed from r955828, myfaces/test/trunk/test12/src/test/java/org/apache/myfaces/test/mock/TestMockBean.java
Removed:
myfaces/test/trunk/test12/src/test/java/org/apache/myfaces/test/mock/TestMockBean.java
Modified:
myfaces/test/trunk/test12/pom.xml
myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/base/AbstractJsfTestCase.java
myfaces/test/trunk/test12/src/test/java/org/apache/myfaces/test/mock/MockObjectsTestCase.java
myfaces/test/trunk/test20/pom.xml
Modified: myfaces/test/trunk/test12/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/pom.xml?rev=959774&r1=959773&r2=959774&view=diff
==============================================================================
--- myfaces/test/trunk/test12/pom.xml (original)
+++ myfaces/test/trunk/test12/pom.xml Thu Jul 1 20:38:30 2010
@@ -67,7 +67,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.1</version>
+ <version>4.5</version>
<scope>compile</scope>
</dependency>
@@ -97,6 +97,13 @@
<build>
<plugins>
<plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
@@ -112,7 +119,7 @@
<!-- Allow building with JDK 1.4 as well as JDK 1.5,
the 1.4 profile caters only to JSF 1.1 -->
<profiles>
-
+ <!--
<profile>
<id>myfaces-test-jdk14</id>
<activation>
@@ -162,6 +169,7 @@
</plugins>
</build>
</profile>
+ -->
<profile>
<id>myfaces-test-jdk15</id>
Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/base/AbstractJsfTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/base/AbstractJsfTestCase.java?rev=959774&r1=959773&r2=959774&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/base/AbstractJsfTestCase.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/base/AbstractJsfTestCase.java Thu Jul 1 20:38:30 2010
@@ -108,6 +108,11 @@ public abstract class AbstractJsfTestCas
setFactories();
+ setUpJSFObjects();
+ }
+
+ protected void setUpJSFObjects() throws Exception
+ {
setUpExternalContext();
setUpLifecycle();
setUpFacesContext();
Added: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java?rev=959774&view=auto
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java (added)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java Thu Jul 1 20:38:30 2010
@@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.myfaces.test.base.junit4;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.FacesContextFactory;
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.lifecycle.LifecycleFactory;
+import javax.faces.render.RenderKit;
+import javax.faces.render.RenderKitFactory;
+
+import org.apache.myfaces.test.mock.MockExternalContext;
+import org.apache.myfaces.test.mock.MockFacesContext;
+import org.apache.myfaces.test.mock.MockFacesContextFactory;
+import org.apache.myfaces.test.mock.MockHttpServletRequest;
+import org.apache.myfaces.test.mock.MockHttpServletResponse;
+import org.apache.myfaces.test.mock.MockHttpSession;
+import org.apache.myfaces.test.mock.MockRenderKit;
+import org.apache.myfaces.test.mock.MockServletConfig;
+import org.apache.myfaces.test.mock.MockServletContext;
+import org.apache.myfaces.test.mock.lifecycle.MockLifecycle;
+import org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory;
+import org.junit.After;
+import org.junit.Before;
+
+/**
+ * <p>Abstract JUnit 4.5 test case base class, which sets up the JavaServer Faces
+ * mock object environment for a particular simulated request. The following
+ * protected variables are initialized in the <code>setUp()</code> method, and
+ * cleaned up in the <code>tearDown()</code> method:</p>
+ * <ul>
+ * <li><code>application</code> (<code>MockApplication</code>)</li>
+ * <li><code>config</code> (<code>MockServletConfig</code>)</li>
+ * <li><code>externalContext</code> (<code>MockExternalContext</code>)</li>
+ * <li><code>facesContext</code> (<code>MockFacesContext</code>)</li>
+ * <li><code>lifecycle</code> (<code>MockLifecycle</code>)</li>
+ * <li><code>request</code> (<code>MockHttpServletRequest</code></li>
+ * <li><code>response</code> (<code>MockHttpServletResponse</code>)</li>
+ * <li><code>servletContext</code> (<code>MockServletContext</code>)</li>
+ * <li><code>session</code> (<code>MockHttpSession</code>)</li>
+ * </ul>
+ *
+ * <p>In addition, appropriate factory classes will have been registered with
+ * <code>javax.faces.FactoryFinder</code> for <code>Application</code> and
+ * <code>RenderKit</code> instances. The created <code>FacesContext</code>
+ * instance will also have been registered in the apppriate thread local
+ * variable, to simulate what a servlet container would do.</p>
+ *
+ * <p><strong>WARNING</strong> - If you choose to subclass this class, be sure
+ * your <code>setUp()</code> and <code>tearDown()</code> methods call
+ * <code>super.setUp()</code> and <code>super.tearDown()</code> respectively,
+ * and that you implement your own <code>suite()</code> method that exposes
+ * the test methods for your test case.</p>
+ */
+
+public abstract class AbstractJsfConfigurableMockTestCase {
+
+
+ // ------------------------------------------------------------ Constructors
+
+
+ /**
+ * <p>Construct a new instance of this test case.</p>
+ *
+ * @param name Name of this test case
+ */
+ public AbstractJsfConfigurableMockTestCase()
+ {
+ }
+
+
+ // ---------------------------------------------------- Overall Test Methods
+
+
+ /**
+ * <p>Set up instance variables required by this test case.</p>
+ */
+ @Before
+ public void setUp() throws Exception {
+
+ // Set up a new thread context class loader
+ threadContextClassLoader = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(new URLClassLoader(new URL[0],
+ this.getClass().getClassLoader()));
+
+ // Set up Servlet API Objects
+ setUpServletObjects();
+
+ // Set up JSF API Objects
+ FactoryFinder.releaseFactories();
+
+ setFactories();
+
+ setUpJSFObjects();
+ }
+
+ protected void setUpJSFObjects() throws Exception
+ {
+ setUpExternalContext();
+ setUpLifecycle();
+ setUpFacesContext();
+ setUpView();
+ setUpApplication();
+ setUpRenderKit();
+ }
+
+ protected void setUpServletObjects() throws Exception
+ {
+ servletContext = new MockServletContext();
+ config = new MockServletConfig(servletContext);
+ session = new MockHttpSession();
+ session.setServletContext(servletContext);
+ request = new MockHttpServletRequest(session);
+ request.setServletContext(servletContext);
+ response = new MockHttpServletResponse();
+ }
+
+ protected void setFactories() throws Exception
+ {
+ FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
+ "org.apache.myfaces.test.mock.MockApplicationFactory");
+ FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
+ "org.apache.myfaces.test.mock.MockFacesContextFactory");
+ FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY,
+ "org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
+ FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
+ "org.apache.myfaces.test.mock.MockRenderKitFactory");
+ }
+
+ protected void setUpExternalContext() throws Exception
+ {
+ externalContext =
+ new MockExternalContext(servletContext, request, response);
+ }
+
+ protected void setUpLifecycle() throws Exception
+ {
+ lifecycleFactory = (MockLifecycleFactory)
+ FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+ lifecycle = (MockLifecycle)
+ lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
+ }
+
+ protected void setUpFacesContext() throws Exception
+ {
+ facesContextFactory = (MockFacesContextFactory)
+ FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
+ facesContext = (MockFacesContext)
+ facesContextFactory.getFacesContext(servletContext,
+ request,
+ response,
+ lifecycle);
+ externalContext = (MockExternalContext) facesContext.getExternalContext();
+ }
+
+ protected void setUpView() throws Exception
+ {
+ UIViewRoot root = new UIViewRoot();
+ root.setViewId("/viewId");
+ root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
+ facesContext.setViewRoot(root);
+ }
+
+ protected void setUpApplication() throws Exception
+ {
+ ApplicationFactory applicationFactory = (ApplicationFactory)
+ FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+ application = applicationFactory.getApplication();
+ ((MockFacesContext)facesContext).setApplication(application);
+ }
+
+ protected void setUpRenderKit() throws Exception
+ {
+ RenderKitFactory renderKitFactory = (RenderKitFactory)
+ FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ renderKit = new MockRenderKit();
+ renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, renderKit);
+ }
+
+ /**
+ * <p>Tear down instance variables required by this test case.</p>
+ */
+ @After
+ public void tearDown() throws Exception {
+
+ application = null;
+ config = null;
+ externalContext = null;
+ facesContext.release();
+ facesContext = null;
+ lifecycle = null;
+ lifecycleFactory = null;
+ renderKit = null;
+ request = null;
+ response = null;
+ servletContext = null;
+ session = null;
+ FactoryFinder.releaseFactories();
+
+ Thread.currentThread().setContextClassLoader(threadContextClassLoader);
+ threadContextClassLoader = null;
+
+ }
+
+
+ // ------------------------------------------------------ Instance Variables
+
+
+ // Mock object instances for our tests
+ protected Application application = null;
+ protected MockServletConfig config = null;
+ protected ExternalContext externalContext = null;
+ protected FacesContext facesContext = null;
+ protected FacesContextFactory facesContextFactory = null;
+ protected Lifecycle lifecycle = null;
+ protected LifecycleFactory lifecycleFactory = null;
+ protected RenderKit renderKit = null;
+ protected MockHttpServletRequest request = null;
+ protected MockHttpServletResponse response = null;
+ protected MockServletContext servletContext = null;
+ protected MockHttpSession session = null;
+
+ // Thread context class loader saved and restored after each test
+ private ClassLoader threadContextClassLoader = null;
+
+}
Added: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java?rev=959774&view=auto
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java (added)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java Thu Jul 1 20:38:30 2010
@@ -0,0 +1,244 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.myfaces.test.base.junit4;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.component.UIViewRoot;
+import javax.faces.lifecycle.LifecycleFactory;
+import javax.faces.render.RenderKitFactory;
+
+import org.apache.myfaces.test.mock.MockApplication;
+import org.apache.myfaces.test.mock.MockExternalContext;
+import org.apache.myfaces.test.mock.MockFacesContext;
+import org.apache.myfaces.test.mock.MockFacesContextFactory;
+import org.apache.myfaces.test.mock.MockHttpServletRequest;
+import org.apache.myfaces.test.mock.MockHttpServletResponse;
+import org.apache.myfaces.test.mock.MockHttpSession;
+import org.apache.myfaces.test.mock.MockRenderKit;
+import org.apache.myfaces.test.mock.MockServletConfig;
+import org.apache.myfaces.test.mock.MockServletContext;
+import org.apache.myfaces.test.mock.lifecycle.MockLifecycle;
+import org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory;
+import org.junit.After;
+import org.junit.Before;
+
+/**
+ * <p>Abstract JUnit 4.5 test case base class, which sets up the JavaServer Faces
+ * mock object environment for a particular simulated request. The following
+ * protected variables are initialized in the <code>setUp()</code> method, and
+ * cleaned up in the <code>tearDown()</code> method:</p>
+ * <ul>
+ * <li><code>application</code> (<code>MockApplication</code>)</li>
+ * <li><code>config</code> (<code>MockServletConfig</code>)</li>
+ * <li><code>externalContext</code> (<code>MockExternalContext</code>)</li>
+ * <li><code>facesContext</code> (<code>MockFacesContext</code>)</li>
+ * <li><code>lifecycle</code> (<code>MockLifecycle</code>)</li>
+ * <li><code>request</code> (<code>MockHttpServletRequest</code></li>
+ * <li><code>response</code> (<code>MockHttpServletResponse</code>)</li>
+ * <li><code>servletContext</code> (<code>MockServletContext</code>)</li>
+ * <li><code>session</code> (<code>MockHttpSession</code>)</li>
+ * </ul>
+ *
+ * <p>In addition, appropriate factory classes will have been registered with
+ * <code>javax.faces.FactoryFinder</code> for <code>Application</code> and
+ * <code>RenderKit</code> instances. The created <code>FacesContext</code>
+ * instance will also have been registered in the apppriate thread local
+ * variable, to simulate what a servlet container would do.</p>
+ *
+ * <p><strong>WARNING</strong> - If you choose to subclass this class, be sure
+ * your <code>setUp()</code> and <code>tearDown()</code> methods call
+ * <code>super.setUp()</code> and <code>super.tearDown()</code> respectively,
+ * and that you implement your own <code>suite()</code> method that exposes
+ * the test methods for your test case.</p>
+ */
+
+public abstract class AbstractJsfTestCase {
+
+
+ // ------------------------------------------------------------ Constructors
+
+
+ /**
+ * <p>Construct a new instance of this test case.</p>
+ *
+ * @param name Name of this test case
+ */
+ public AbstractJsfTestCase()
+ {
+ }
+
+
+ // ---------------------------------------------------- Overall Test Methods
+
+
+ /**
+ * <p>Set up instance variables required by this test case.</p>
+ */
+ @Before
+ public void setUp() throws Exception {
+
+ // Set up a new thread context class loader
+ threadContextClassLoader = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(new URLClassLoader(new URL[0],
+ this.getClass().getClassLoader()));
+
+ // Set up Servlet API Objects
+ setUpServletObjects();
+
+ // Set up JSF API Objects
+ FactoryFinder.releaseFactories();
+
+ setFactories();
+
+ setUpJSFObjects();
+ }
+
+ protected void setUpJSFObjects() throws Exception
+ {
+ setUpExternalContext();
+ setUpLifecycle();
+ setUpFacesContext();
+ setUpView();
+ setUpApplication();
+ setUpRenderKit();
+ }
+
+ protected void setUpServletObjects() throws Exception
+ {
+ servletContext = new MockServletContext();
+ config = new MockServletConfig(servletContext);
+ session = new MockHttpSession();
+ session.setServletContext(servletContext);
+ request = new MockHttpServletRequest(session);
+ request.setServletContext(servletContext);
+ response = new MockHttpServletResponse();
+ }
+
+ protected void setFactories() throws Exception
+ {
+ FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
+ "org.apache.myfaces.test.mock.MockApplicationFactory");
+ FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
+ "org.apache.myfaces.test.mock.MockFacesContextFactory");
+ FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY,
+ "org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
+ FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
+ "org.apache.myfaces.test.mock.MockRenderKitFactory");
+ }
+
+ protected void setUpExternalContext() throws Exception
+ {
+ externalContext =
+ new MockExternalContext(servletContext, request, response);
+ }
+
+ protected void setUpLifecycle() throws Exception
+ {
+ lifecycleFactory = (MockLifecycleFactory)
+ FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+ lifecycle = (MockLifecycle)
+ lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
+ }
+
+ protected void setUpFacesContext() throws Exception
+ {
+ facesContextFactory = (MockFacesContextFactory)
+ FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
+ facesContext = (MockFacesContext)
+ facesContextFactory.getFacesContext(servletContext,
+ request,
+ response,
+ lifecycle);
+ externalContext = (MockExternalContext) facesContext.getExternalContext();
+ }
+
+ protected void setUpView() throws Exception
+ {
+ UIViewRoot root = new UIViewRoot();
+ root.setViewId("/viewId");
+ root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
+ facesContext.setViewRoot(root);
+ }
+
+ protected void setUpApplication() throws Exception
+ {
+ ApplicationFactory applicationFactory = (ApplicationFactory)
+ FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+ application = (MockApplication) applicationFactory.getApplication();
+ facesContext.setApplication(application);
+ }
+
+ protected void setUpRenderKit() throws Exception
+ {
+ RenderKitFactory renderKitFactory = (RenderKitFactory)
+ FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ renderKit = new MockRenderKit();
+ renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, renderKit);
+ }
+
+ /**
+ * <p>Tear down instance variables required by this test case.</p>
+ */
+ @After
+ public void tearDown() throws Exception {
+
+ application = null;
+ config = null;
+ externalContext = null;
+ facesContext.release();
+ facesContext = null;
+ lifecycle = null;
+ lifecycleFactory = null;
+ renderKit = null;
+ request = null;
+ response = null;
+ servletContext = null;
+ session = null;
+ FactoryFinder.releaseFactories();
+
+ Thread.currentThread().setContextClassLoader(threadContextClassLoader);
+ threadContextClassLoader = null;
+
+ }
+
+
+ // ------------------------------------------------------ Instance Variables
+
+
+ // Mock object instances for our tests
+ protected MockApplication application = null;
+ protected MockServletConfig config = null;
+ protected MockExternalContext externalContext = null;
+ protected MockFacesContext facesContext = null;
+ protected MockFacesContextFactory facesContextFactory = null;
+ protected MockLifecycle lifecycle = null;
+ protected MockLifecycleFactory lifecycleFactory = null;
+ protected MockRenderKit renderKit = null;
+ protected MockHttpServletRequest request = null;
+ protected MockHttpServletResponse response = null;
+ protected MockServletContext servletContext = null;
+ protected MockHttpSession session = null;
+
+ // Thread context class loader saved and restored after each test
+ private ClassLoader threadContextClassLoader = null;
+
+}
Added: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/htmlunit/junit4/AbstractHtmlUnitTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/htmlunit/junit4/AbstractHtmlUnitTestCase.java?rev=959774&view=auto
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/htmlunit/junit4/AbstractHtmlUnitTestCase.java (added)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/htmlunit/junit4/AbstractHtmlUnitTestCase.java Thu Jul 1 20:38:30 2010
@@ -0,0 +1,320 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.myfaces.test.htmlunit.junit4;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Iterator;
+
+import org.junit.After;
+import org.junit.Before;
+
+import com.gargoylesoftware.htmlunit.ElementNotFoundException;
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
+import com.gargoylesoftware.htmlunit.html.HtmlBody;
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlHead;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
+
+
+
+/**
+ * <p>Abstract base class for system integration tests based on HtmlUnit.
+ * These tests will expect a system property named <code>url</code> to be
+ * present, which will define the URL (including the context path, but
+ * without a trailing slash) of the application to be tested.</p>
+ */
+
+public abstract class AbstractHtmlUnitTestCase {
+
+
+ // ------------------------------------------------------------ Constructors
+
+
+ /**
+ * <p>Construct a new instance of this test case.</p>
+ *
+ * @param name Name of the new test case
+ */
+ public AbstractHtmlUnitTestCase()
+ {
+ }
+
+
+ // ------------------------------------------------------ Instance Variables
+
+
+ /**
+ * <p>The most recently retrieved page from the server.</p>
+ */
+ protected HtmlPage page = null;
+
+
+ /**
+ * <p>The calculated URL for the installed "systest" web application.
+ * This value is based on a system property named <code>url</code>,
+ * which must be defined as part of the command line that executes
+ * each test case.</p>
+ */
+ protected URL url = null;
+
+
+ /**
+ * <p>The web client for this test case.</p>
+ */
+ protected WebClient webClient = null;
+
+
+ // ------------------------------------------------------ Test Setup Methods
+
+
+ /**
+ * <p>Set up the instance variables required for this test case.</p>
+ *
+ * @exception Exception if an error occurs
+ */
+ @Before
+ protected void setUp() throws Exception {
+
+ // Calculate the URL for the installed "systest" web application
+ String url = System.getProperty("url");
+ this.url = new URL(url + "/");
+
+ // Initialize HtmlUnit constructs for this test case
+ webClient = new WebClient();
+
+ }
+
+ /**
+ * <p>Tear down instance variables required by this test case.</p>
+ */
+ @After
+ protected void tearDown() throws Exception {
+
+ page = null;
+ url = null;
+ webClient = null;
+
+ }
+
+
+
+ // ------------------------------------------------------- Protected Methods
+
+
+ /**
+ * <p>Return the body element for the most recently retrieved page.
+ * If there is no such element, return <code>null</code>.</p>
+ *
+ * @exception Exception if an error occurs
+ */
+ protected HtmlBody body() throws Exception {
+
+ Iterator elements = page.getAllHtmlChildElements();
+ while (elements.hasNext()) {
+ HtmlElement element = (HtmlElement) elements.next();
+ if (element instanceof HtmlBody) {
+ return ((HtmlBody) element);
+ }
+ }
+ return (null);
+
+ }
+
+
+ /**
+ * <p>Return the HTML element with the specified <code>id</code> from the
+ * most recently retrieved page. If there is no such element, return
+ * <code>null</code>.</p>
+ *
+ * @param id Identifier of the requested element.
+ *
+ * @exception Exception if an error occurs
+ */
+ protected HtmlElement element(String id) throws Exception {
+
+ try {
+ return (page.getHtmlElementById(id));
+ } catch (ElementNotFoundException e) {
+ return (null);
+ }
+
+ }
+
+
+ /**
+ * <p>Return the form with the specified <code>id</code> from the most
+ * recently retrieved page. If there is no such form, return
+ * <code>null</code>.<p>
+ *
+ * @param id Identifier of the requested form.
+ *
+ * @exception Exception if an error occurs
+ */
+ protected HtmlForm form(String id) throws Exception {
+
+ Iterator forms = page.getForms().iterator();
+ while (forms.hasNext()) {
+ HtmlForm form = (HtmlForm) forms.next();
+ if (id.equals(form.getAttributeValue("id"))) {
+ return (form);
+ }
+ }
+ return (null);
+
+ }
+
+
+ /**
+ * <p>Return the head element for the most recently retrieved page.
+ * If there is no such element, return <code>null</code>.</p>
+ *
+ * @exception Exception if an error occurs
+ */
+ protected HtmlHead head() throws Exception {
+
+ Iterator elements = page.getAllHtmlChildElements();
+ while (elements.hasNext()) {
+ HtmlElement element = (HtmlElement) elements.next();
+ if (element instanceof HtmlHead) {
+ return ((HtmlHead) element);
+ }
+ }
+ return (null);
+
+ }
+
+
+ /**
+ * <p>Click the specified hyperlink, and retrieve the subsequent page,
+ * saving a reference so that other utility methods may be used to
+ * retrieve information from it.</p>
+ *
+ * @param anchor Anchor component to click
+ *
+ * @exception IOException if an input/output error occurs
+ */
+ protected HtmlPage link(HtmlAnchor anchor) throws IOException {
+
+ HtmlPage page = (HtmlPage) anchor.click();
+ this.page = page;
+ return page;
+
+ }
+
+
+ /**
+ * <p>Return the currently stored page reference.</p>
+ */
+ protected HtmlPage page() {
+
+ return this.page;
+
+ }
+
+
+ /**
+ * <p>Retrieve and return the page at the specified context relative path.
+ * Save a reference to this page so that other utility methods may be used
+ * to retrieve information from it.</p>
+ *
+ * @param path Context relative path
+ *
+ * @exception IllegalArgumentException if the context relative path
+ * does not begin with a '/' character
+ * @exception Exception if a different error occurs
+ */
+ protected HtmlPage page(String path) throws Exception {
+
+ HtmlPage page = (HtmlPage) webClient.getPage(url(path));
+ this.page = page;
+ return (page);
+
+ }
+
+
+ /**
+ * <p>Reset the stored page reference to the specified value. This is
+ * useful for scenarios testing resubmit of the same page (simulating the
+ * user pressing the back button and then submitting again).</p>
+ *
+ * @param page Previously saved page to which to reset
+ */
+ protected void reset(HtmlPage page) {
+
+ this.page = page;
+
+ }
+
+
+ /**
+ * <p>Submit the current page, using the specified component, and retrieve
+ * the subsequent page, saving a reference so that other utility methods
+ * may be used to retrieve information from it.</p>
+ *
+ * @param submit Submit button component to click
+ *
+ * @exception IOException if an input/output error occurs
+ */
+ protected HtmlPage submit(HtmlSubmitInput submit) throws IOException {
+
+ HtmlPage page = (HtmlPage) submit.click();
+ this.page = page;
+ return page;
+
+ }
+
+
+ /**
+ * <p>Return the page title from the most recently retrieved page.
+ * Any leading and trailing whitespace will be trimmed.</p>
+ *
+ * @exception Exception if an error occurs
+ */
+ protected String title() throws Exception {
+
+ return (page.getTitleText().trim());
+
+ }
+
+
+ /**
+ * <p>Calculate and return an absolute URL for the specified context
+ * relative path, which must begin with a '/' character.</p>
+ *
+ * @param path Context relative path
+ *
+ * @exception IllegalArgumentException if the context relative path
+ * does not begin with a '/' character
+ * @exception Exception if a different error ocurs
+ */
+ protected URL url(String path) throws Exception {
+
+ if (path.charAt(0) != '/') {
+ throw new IllegalArgumentException("Context path '" + path
+ + "' does not start with '/'");
+ }
+ return new URL(url, path.substring(1));
+
+ }
+
+
+}
Copied: myfaces/test/trunk/test12/src/test/java/org/apache/myfaces/test/mock/MockBean.java (from r955828, myfaces/test/trunk/test12/src/test/java/org/apache/myfaces/test/mock/TestMockBean.java)
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/test/java/org/apache/myfaces/test/mock/MockBean.java?p2=myfaces/test/trunk/test12/src/test/java/org/apache/myfaces/test/mock/MockBean.java&p1=myfaces/test/trunk/test12/src/test/java/org/apache/myfaces/test/mock/TestMockBean.java&r1=955828&r2=959774&rev=959774&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/test/java/org/apache/myfaces/test/mock/TestMockBean.java (original)
+++ myfaces/test/trunk/test12/src/test/java/org/apache/myfaces/test/mock/MockBean.java Thu Jul 1 20:38:30 2010
@@ -24,7 +24,7 @@ import java.io.Serializable;
*
* $Id$
*/
-public class TestMockBean implements Serializable {
+public class MockBean implements Serializable {
private static final long serialVersionUID = 8879968751506858610L;
private String command;
Modified: myfaces/test/trunk/test12/src/test/java/org/apache/myfaces/test/mock/MockObjectsTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/test/java/org/apache/myfaces/test/mock/MockObjectsTestCase.java?rev=959774&r1=959773&r2=959774&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/test/java/org/apache/myfaces/test/mock/MockObjectsTestCase.java (original)
+++ myfaces/test/trunk/test12/src/test/java/org/apache/myfaces/test/mock/MockObjectsTestCase.java Thu Jul 1 20:38:30 2010
@@ -57,7 +57,7 @@ public class MockObjectsTestCase extends
session.setAttribute("sameKey", "sameKeySesValue");
request.setAttribute("reqScopeName", "reqScopeValue");
request.setAttribute("sameKey", "sameKeyReqValue");
- request.setAttribute("test", new TestMockBean());
+ request.setAttribute("test", new MockBean());
}
@@ -103,7 +103,7 @@ public class MockObjectsTestCase extends
public void testMethodBindingInvokePositive() throws Exception {
- TestMockBean bean = (TestMockBean) request.getAttribute("test");
+ MockBean bean = (MockBean) request.getAttribute("test");
MethodBinding mb = null;
Class argsString[] = new Class[] { String.class };
Class argsNone[] = new Class[0];
Modified: myfaces/test/trunk/test20/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test20/pom.xml?rev=959774&r1=959773&r2=959774&view=diff
==============================================================================
--- myfaces/test/trunk/test20/pom.xml (original)
+++ myfaces/test/trunk/test20/pom.xml Thu Jul 1 20:38:30 2010
@@ -67,7 +67,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.1</version>
+ <version>4.5</version>
<scope>compile</scope>
</dependency>