1 22 package org.jboss.test.web.test; 23 24 import java.net.URL ; 26 28 import junit.framework.Test; 29 import junit.framework.TestSuite; 30 31 import org.jboss.test.JBossTestCase; 32 import org.jboss.test.JBossTestSetup; 33 import org.jboss.test.util.web.HttpUtils; 34 import org.apache.commons.httpclient.HttpClient; 35 import org.apache.commons.httpclient.HttpMethodBase; 36 import org.apache.commons.httpclient.methods.GetMethod; 37 38 49 public class JSFIntegrationUnitTestCase extends JBossTestCase 50 { 51 private String baseURL = HttpUtils.getBaseURL(); 52 private HttpClient client = new HttpClient(); 53 54 public JSFIntegrationUnitTestCase(String name) 55 { 56 super(name); 57 } 58 59 61 public void testJSFIntegrated() throws Exception 62 { 63 client.executeMethod(makeRequest()); 64 65 HttpMethodBase result = makeRequest(); 66 67 client.executeMethod(result); 69 70 String responseBody = result.getResponseBodyAsString(); 71 if (responseBody == null) { 72 throw new Exception ("Unable to get response from server."); 73 } 74 75 assertTrue(contains(responseBody, "@PostConstruct was called.")); 76 assertTrue(contains(responseBody, "@PreDestroy was called.")); 77 assertTrue(contains(responseBody, "Datasource was injected.")); 78 79 assertTrue(contains(responseBody, "number one")); 81 assertTrue(contains(responseBody, "number two")); 82 assertTrue(contains(responseBody, "number three")); 83 84 assertTrue(contains(responseBody, "JBoss Color selection is PURPLE")); 86 } 87 88 private boolean contains(String base, String target) { 89 return base.indexOf(target) != -1; 90 } 91 92 private GetMethod makeRequest() { 93 return new GetMethod(baseURL+"jbosstest-jsf/index.jsf"); 94 } 95 96 public static Test suite() throws Exception 97 { 98 TestSuite suite = new TestSuite(); 99 suite.addTest(new TestSuite(JSFIntegrationUnitTestCase.class)); 100 101 Test wrapper = new JBossTestSetup(suite) 103 { 104 protected void setUp() throws Exception 105 { 106 super.setUp(); 107 deploy("jbosstest-jsf.war"); 108 } 109 protected void tearDown() throws Exception 110 { 111 undeploy("jbosstest-jsf.war"); 112 super.tearDown(); 113 } 114 }; 115 return wrapper; 116 } 117 118 119 } 120 | Popular Tags |