1 20 package org.apache.cactus.extension.jetty; 21 22 import java.net.URL ; 23 24 import org.apache.cactus.internal.configuration.Configuration; 25 import org.apache.cactus.internal.configuration.FilterConfiguration; 26 import org.apache.cactus.internal.configuration.ServletConfiguration; 27 28 import com.mockobjects.dynamic.Mock; 29 30 import junit.framework.TestCase; 31 32 40 public class TestJettyTestSetup extends TestCase 41 { 42 45 private Mock mockConfiguration; 46 47 50 private Configuration configuration; 51 52 55 private Mock mockServletConfiguration; 56 57 60 private ServletConfiguration servletConfiguration; 61 62 65 private Mock mockFilterConfiguration; 66 67 70 private FilterConfiguration filterConfiguration; 71 72 76 private static final String CONTEXT_URL = 77 "http://localhost:" + System.getProperty("cactus.port", "8080"); 78 79 82 private JettyTestSetup jettyTestSetup; 83 84 88 public class SampleTestCase extends TestCase 89 { 90 } 91 92 95 protected void setUp() throws Exception 96 { 97 mockConfiguration = new Mock(Configuration.class); 98 configuration = (Configuration) mockConfiguration.proxy(); 99 100 mockServletConfiguration = new Mock(ServletConfiguration.class); 101 servletConfiguration = 102 (ServletConfiguration) mockServletConfiguration.proxy(); 103 mockFilterConfiguration = new Mock(FilterConfiguration.class); 104 filterConfiguration = 105 (FilterConfiguration) mockFilterConfiguration.proxy(); 106 107 mockConfiguration.matchAndReturn("getContextURL", CONTEXT_URL); 108 mockServletConfiguration.matchAndReturn("getDefaultRedirectorName", 109 "ServletRedirector"); 110 111 URL testURL = new URL (CONTEXT_URL + "/" 112 + servletConfiguration.getDefaultRedirectorName()); 113 114 mockServletConfiguration.matchAndReturn("getDefaultRedirectorURL", 115 testURL.getPath()); 116 117 jettyTestSetup = new JettyTestSetup(new SampleTestCase(), 118 configuration, servletConfiguration, filterConfiguration); 119 120 if (jettyTestSetup.isAvailable( 122 jettyTestSetup.testConnectivity(testURL))) 123 { 124 fail("No server serving the [" + testURL.getPath() 125 + "] URL should be started."); 126 } 127 } 128 129 132 protected void tearDown() throws Exception 133 { 134 jettyTestSetup.tearDown(); 136 137 mockConfiguration.verify(); 138 mockServletConfiguration.verify(); 139 mockFilterConfiguration.verify(); 140 } 141 142 148 public void testSetUpWhenServerNotAlreadyStarted() throws Exception 149 { 150 jettyTestSetup.setUp(); 151 assertTrue(jettyTestSetup.isRunning()); 152 } 153 154 160 public void testSetUpWhenServerIsAlreadyStarted() throws Exception 161 { 162 jettyTestSetup.setUp(); 163 164 jettyTestSetup.setUp(); 168 169 jettyTestSetup.setForceShutdown(true); 171 } 172 } 173 | Popular Tags |