Skip to content

Instantly share code, notes, and snippets.

@lfryc
Last active January 2, 2016 16:48
Show Gist options
  • Save lfryc/8332075 to your computer and use it in GitHub Desktop.
Save lfryc/8332075 to your computer and use it in GitHub Desktop.
package org.richfaces.arquillian.extension;
import org.jboss.arquillian.core.spi.LoadableExtension;
import org.jboss.arquillian.test.spi.enricher.resource.ResourceProvider;
import org.richfaces.arquillian.browser.FailureScreenshot;
import org.richfaces.arquillian.browser.PrepareBrowserSession;
import org.richfaces.arquillian.browser.ScreenshotTaker;
import org.richfaces.arquillian.configuration.FundamentalTestConfiguratorObserver;
import org.richfaces.arquillian.container.installation.ContainerInitializationObserver;
import org.richfaces.arquillian.container.installation.ContainerInstaller;
import org.richfaces.arquillian.page.source.SourceChecker;
import org.richfaces.arquillian.page.source.SourceCheckerProvider;
import org.richfaces.arquillian.verification.VerifyDeploymentTestability;
;
public class RichFacesArquillianExtension implements LoadableExtension {
@Override
public void register(ExtensionBuilder builder) {
builder.service(SourceChecker.class, SourceChecker.class);
builder.service(ResourceProvider.class, SourceCheckerProvider.class);
builder.observer(FundamentalTestConfiguratorObserver.class);
builder.observer(ContainerInitializationObserver.class);
builder.observer(ContainerInstaller.class);
builder.observer(PrepareBrowserSession.class);
builder.observer(FailureScreenshot.class);
builder.observer(ScreenshotTaker.class);
builder.observer(VerifyDeploymentTestability.class);
// add this line to rewrite default service
builder.override(DefaultURLMapping.class, MyURLMapping.class);
}
}
/**
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.arquillian.warp.impl.client.proxy;
import java.io.IOException;
import java.net.InetAddress;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import org.jboss.arquillian.warp.impl.utils.URLUtils;
public class MyURLMapping implements URLMapping {
private static final int BASE = 18080;
private int sequenceNumber = 0;
private Map<URL, URL> map = new HashMap<URL, URL>();
public synchronized URL getProxyURL(URL url) {
URL base = URLUtils.getUrlBase(url);
if (map.containsKey(base)) {
return map.get(base);
}
int proxyPort = generatePort();
URL proxyUrl = newProxyUrlWithPort(base, proxyPort);
map.put(base, proxyUrl);
return proxyUrl;
}
private int generatePort() {
return BASE + sequenceNumber++;
}
private URL newProxyUrlWithPort(URL url, int port) {
try {
String localHost = "localhost";
return new URL(url.getProtocol(), localHost, port, url.getFile());
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment