if (SKIP_INJVM_PROXY) {
return; //inJvm Proxy test skipped.
}
assertTrue(SocketDestHelper.isSocketRestrictionFlagActive());
RestTemplate restTemplate = new RestTemplate();
// When called directly without a proxy, expect an exception to be thrown due to byteman rules
assertNetworkCallFails(restTemplate, new HttpComponentsClientHttpRequestFactory());
// Repeat that with different request factory used in the code as this exercises different byteman rules
assertNetworkCallFails(restTemplate, new SimpleClientHttpRequestFactory());
// And with the actual one used by RestUtil, without a proxy configured
assertNetworkCallFails(restTemplate, new RestUtil().createRequestFactory(null, false));
// Test with the in-JVM proxy configured
HttpProxyConfiguration localProxy = new HttpProxyConfiguration("127.0.0.1", inJvmProxyPort);
ClientHttpRequestFactory requestFactory = new RestUtil().createRequestFactory(localProxy, CCNG_API_SSL);
restTemplate.setRequestFactory(requestFactory);
restTemplate.execute(CCNG_API_URL + "/info", HttpMethod.GET, null, null);
// then executes fine, and the jetty proxy indeed received one request
assertEquals("expected network calls to make it through the inJvmProxy.", 1, nbInJvmProxyRcvReqs.get());
nbInJvmProxyRcvReqs.set(0); //reset for next test