public ProxyConfig getProxyConfig() { return from(from).to(to); }
@Test public void should_batch_proxy_from_server_with_context_server() throws Exception { server = httpServer(port(), context("/proxy")); server.get(by(uri("/target/1"))).response("target_1"); server.get(by(uri("/target/2"))).response("target_2"); server.proxy(from("/proxy").to(remoteUrl("/proxy/target"))); running(server, new Runnable() { @Override public void run() throws Exception { assertThat(helper.get(remoteUrl("/proxy/proxy/1")), is("target_1")); assertThat(helper.get(remoteUrl("/proxy/proxy/2")), is("target_2")); } }); }
public final ProxyConfig getProxyConfig() { return from(from).to(to); }
@Test public void should_batch_proxy_from_server() throws Exception { server.get(by(uri("/target/1"))).response("target_1"); server.get(by(uri("/target/2"))).response("target_2"); server.proxy(from("/proxy").to(remoteUrl("/target"))); running(server, new Runnable() { @Override public void run() throws Exception { assertThat(helper.get(remoteUrl("/proxy/1")), is("target_1")); assertThat(helper.get(remoteUrl("/proxy/2")), is("target_2")); } }); }
@Test public void should_proxy_a_batch_of_urls() throws Exception { server.get(by(uri("/target/1"))).response("target_1"); server.get(by(uri("/target/2"))).response("target_2"); server.get(match(uri("/proxy/.*"))).response(proxy(from("/proxy").to(remoteUrl("/target")))); running(server, new Runnable() { @Override public void run() throws Exception { assertThat(helper.get(remoteUrl("/proxy/1")), is("target_1")); assertThat(helper.get(remoteUrl("/proxy/2")), is("target_2")); } }); }
@Test public void should_proxy_a_batch_of_urls_with_failover_from_server() throws Exception { server.proxy(from("/proxy").to(remoteUrl("/target")), failover("src/test/resources/failover.response")); running(server, new Runnable() { @Override public void run() throws Exception { assertThat(helper.postContent(remoteUrl("/proxy/1"), "proxy"), is("proxy")); } }); }
@Test public void should_proxy_a_batch_of_urls_with_failover() throws Exception { server.request(match(uri("/proxy/.*"))).response(proxy(from("/proxy").to(remoteUrl("/target")), failover("src/test/resources/failover.response"))); running(server, new Runnable() { @Override public void run() throws Exception { assertThat(helper.postContent(remoteUrl("/proxy/1"), "proxy"), is("proxy")); } }); }
@Test(expected = HttpResponseException.class) public void should_not_proxy_url_for_unmatching_url_for_batch_proxy_from_server() throws Exception { server.proxy(from("/proxy").to(remoteUrl("/target"))); running(server, new Runnable() { @Override public void run() throws Exception { helper.get(remoteUrl("/proxy1/1")); } }); }
@Override @SuppressWarnings("unchecked") public ResponseHandler apply(final MocoConfig config) { if (config.isFor(MocoConfig.URI_ID)) { String newLocalBase = (String) config.apply(proxyConfig.localBase()); return new ProxyBatchResponseHandler(from(newLocalBase).to(proxyConfig.remoteBase()), failover()); } return this; } }