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));
}
Aggregations