[jboss-cvs] jbosstest/src/main/org/jboss/test/web/test ...

Stan Silvert ssilvert at jboss.com
Wed Jul 19 17:28:44 EDT 2006


  User: ssilvert
  Date: 06/07/19 17:28:44

  Added:       src/main/org/jboss/test/web/test 
                        JSFIntegrationUnitTestCase.java
  Log:
  Updated JSF and JSTL version.  Added test for JSF and JSTL integration.
  
  Revision  Changes    Path
  1.2       +116 -0    jbosstest/src/main/org/jboss/test/web/test/JSFIntegrationUnitTestCase.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: JSFIntegrationUnitTestCase.java
  ===================================================================
  RCS file: JSFIntegrationUnitTestCase.java
  diff -N JSFIntegrationUnitTestCase.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ JSFIntegrationUnitTestCase.java	19 Jul 2006 21:28:44 -0000	1.2
  @@ -0,0 +1,116 @@
  +/*
  +* JBoss, Home of Professional Open Source
  +* Copyright 2006, JBoss Inc., 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.test.web.test;
  +
  +//import java.net.HttpURLConnection;
  +import java.net.URL;
  +//import javax.management.ObjectName;
  +
  +import junit.framework.Test;
  +import junit.framework.TestSuite;
  +
  +import org.jboss.test.JBossTestCase;
  +import org.jboss.test.JBossTestSetup;
  +import org.jboss.test.util.web.HttpUtils;
  +import org.apache.commons.httpclient.HttpClient;
  +import org.apache.commons.httpclient.HttpMethodBase;
  +import org.apache.commons.httpclient.methods.GetMethod;
  +
  +/** Tests of JSF integration into the JBoss server. This test
  + requires than a web container and JSF implementation be integrated 
  + into the JBoss server. The tests currently do NOT use the 
  + java.net.HttpURLConnection and associated http client and these do 
  + not return valid HTTP error codes so if a failure occurs it is best 
  + to connect the webserver using a browser to look for additional error
  + info. 
  + 
  + @author Stan.Silvert at jboss.org
  + @version $Revision: 1.2 $
  + */
  +public class JSFIntegrationUnitTestCase extends JBossTestCase
  +{
  +   private String baseURL = HttpUtils.getBaseURL(); 
  +   private HttpClient client = new HttpClient();
  +   
  +   public JSFIntegrationUnitTestCase(String name)
  +   {
  +      super(name);
  +   }
  +   
  +   /** Access the http://localhost/jbosstest-jsf/index.jsf.
  +    */
  +   public void testJSFIntegrated() throws Exception
  +   {
  +      client.executeMethod(makeRequest());
  +
  +      HttpMethodBase result = makeRequest();
  +
  +      // need to hit it twice with the same session for test to pass
  +      client.executeMethod(result);
  +
  +      String responseBody = result.getResponseBodyAsString();
  +      if (responseBody == null) {
  +         throw new Exception("Unable to get response from server.");
  +      }
  +
  +      assertTrue(contains(responseBody, "@PostConstruct was called."));
  +      assertTrue(contains(responseBody, "@PreDestroy was called."));
  +      assertTrue(contains(responseBody, "Datasource was injected."));
  +
  +      // Tests JSF/JSTL integration
  +      assertTrue(contains(responseBody, "number one"));
  +      assertTrue(contains(responseBody, "number two"));
  +      assertTrue(contains(responseBody, "number three"));
  +   }   
  +
  +   private boolean contains(String base, String target) {
  +      return base.indexOf(target) != -1;
  +   }
  +
  +   private GetMethod makeRequest() {
  +      return new GetMethod(baseURL+"jbosstest-jsf/index.jsf");
  +   }
  +
  +   public static Test suite() throws Exception
  +   {
  +      TestSuite suite = new TestSuite();
  +      suite.addTest(new TestSuite(JSFIntegrationUnitTestCase.class));
  +
  +      // Create an initializer for the test suite
  +      Test wrapper = new JBossTestSetup(suite)
  +      {
  +         protected void setUp() throws Exception
  +         {
  +            super.setUp();
  +            deploy("jbosstest-jsf.war");           
  +         }
  +         protected void tearDown() throws Exception
  +         {
  +            undeploy("jbosstest-jsf.war");
  +            super.tearDown();            
  +         }
  +      };
  +      return wrapper;
  +   }
  +   
  +
  +}
  
  
  



More information about the jboss-cvs-commits mailing list