Search in sources :

Example 1 with HttpTestUtil

use of com.thoughtworks.go.server.util.HttpTestUtil in project gocd by gocd.

the class UrlRewriterIntegrationTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    ServletHelper.init();
    httpUtil = new HttpTestUtil(new HttpTestUtil.ContextCustomizer() {

        public void customize(WebAppContext ctx) throws Exception {
            wac = mock(WebApplicationContext.class);
            ctx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
            URL resource = getClass().getClassLoader().getResource("WEB-INF/urlrewrite.xml");
            if (resource == null) {
                throw new RuntimeException("Cannot load WEB-INF/urlrewrite.xml");
            }
            ctx.setBaseResource(Resource.newResource(new File(resource.getFile()).getParent()));
            ctx.addFilter(UrlRewriteFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)).setInitParameter("confPath", "/urlrewrite.xml");
            ctx.addServlet(HttpTestUtil.EchoServlet.class, "/*");
        }
    });
    httpUtil.httpConnector(HTTP);
    httpUtil.httpsConnector(HTTPS);
    when(wac.getBean("serverConfigService")).thenReturn(new BaseUrlProvider() {

        public boolean hasAnyUrlConfigured() {
            return useConfiguredUrls;
        }

        public String siteUrlFor(String url, boolean forceSsl) throws URISyntaxException {
            ServerSiteUrlConfig siteUrl = forceSsl ? new ServerSiteUrlConfig("https://127.2.2.2:" + 9071) : new ServerSiteUrlConfig("http://127.2.2.2:" + 5197);
            return siteUrl.siteUrlFor(url);
        }
    });
    httpUtil.start();
    originalSslPort = System.getProperty(SystemEnvironment.CRUISE_SERVER_SSL_PORT);
    System.setProperty(SystemEnvironment.CRUISE_SERVER_SSL_PORT, String.valueOf(9071));
}
Also used : URISyntaxException(java.net.URISyntaxException) URL(java.net.URL) WebApplicationContext(org.springframework.web.context.WebApplicationContext) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) HttpTestUtil(com.thoughtworks.go.server.util.HttpTestUtil) UrlRewriteFilter(org.tuckey.web.filters.urlrewrite.UrlRewriteFilter) File(java.io.File) ServerSiteUrlConfig(com.thoughtworks.go.domain.ServerSiteUrlConfig) BeforeClass(org.junit.BeforeClass)

Aggregations

ServerSiteUrlConfig (com.thoughtworks.go.domain.ServerSiteUrlConfig)1 HttpTestUtil (com.thoughtworks.go.server.util.HttpTestUtil)1 File (java.io.File)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)1 BeforeClass (org.junit.BeforeClass)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1 UrlRewriteFilter (org.tuckey.web.filters.urlrewrite.UrlRewriteFilter)1