@Test
 public void testGetTransportTypeOfDefault() throws Exception {
   HttpTransportFactory.HttpTransportType type = HttpTransportFactory.getTransportTypeOf(null);
   assertEquals(HttpTransportType.JAVA_NET, type);
   type = HttpTransportFactory.getTransportTypeOf("");
   assertEquals(HttpTransportType.JAVA_NET, type);
 }
 @Test
 public void testGetTransportTypeOf() throws Exception {
   HttpTransportFactory.HttpTransportType type =
       HttpTransportFactory.getTransportTypeOf("JAVA_NET");
   assertEquals(HttpTransportFactory.HttpTransportType.JAVA_NET, type);
   type = HttpTransportFactory.getTransportTypeOf("APACHE");
   assertEquals(HttpTransportType.APACHE, type);
 }
 @Test
 public void testParseProxyAddressNoPort() throws Exception {
   expectedException.expect(IllegalArgumentException.class);
   expectedException.expectMessage("Proxy address 'foo-host' has no port.");
   String address = "foo-host";
   HttpTransportFactory.parseProxyAddress(address);
 }
 @Test
 public void testParseProxyAddressHttps() throws Exception {
   String address = "https://foo-host:1234";
   URI expectedUri = getURI("https", "foo-host", 1234);
   URI uri = HttpTransportFactory.parseProxyAddress(address);
   assertEquals(expectedUri, uri);
 }
 @Test
 public void testParseProxyAddressWithPath() throws Exception {
   expectedException.expect(IllegalArgumentException.class);
   expectedException.expectMessage("Invalid proxy address 'foo-host:1234/some/path'.");
   String address = "foo-host:1234/some/path";
   HttpTransportFactory.parseProxyAddress(address);
 }
 @Test
 public void testParseProxyAddressInvalidSyntax() throws Exception {
   expectedException.expect(IllegalArgumentException.class);
   expectedException.expectMessage("Invalid proxy address 'foo-host-with-illegal-char^:1234'.");
   String address = "foo-host-with-illegal-char^:1234";
   HttpTransportFactory.parseProxyAddress(address);
 }
 @Test
 public void testParseProxyAddressInvalidScheme() throws Exception {
   expectedException.expect(IllegalArgumentException.class);
   expectedException.expectMessage(
       "HTTP proxy address 'socks5://foo-host:1234' has invalid scheme 'socks5'.");
   String address = "socks5://foo-host:1234";
   HttpTransportFactory.parseProxyAddress(address);
 }
 @Test
 public void testGetTransportTypeOfException() throws Exception {
   expectedException.expect(IllegalArgumentException.class);
   expectedException.expectMessage(
       "Invalid HttpTransport type 'com.google.api.client.http.apache.ApacheHttpTransport'."
           + " Must be one of [APACHE, JAVA_NET].");
   HttpTransportFactory.getTransportTypeOf(
       "com.google.api.client.http.apache.ApacheHttpTransport");
 }
示例#9
0
 /**
  * Returns a request initializer responsible for initializing requests according to service
  * options.
  */
 public HttpRequestInitializer httpRequestInitializer() {
   HttpTransport httpTransport = httpTransportFactory.create();
   final HttpRequestInitializer baseRequestInitializer =
       authCredentials().httpRequestInitializer(httpTransport, scopes());
   return new HttpRequestInitializer() {
     @Override
     public void initialize(HttpRequest httpRequest) throws IOException {
       baseRequestInitializer.initialize(httpRequest);
       if (connectTimeout >= 0) {
         httpRequest.setConnectTimeout(connectTimeout);
       }
       if (readTimeout >= 0) {
         httpRequest.setReadTimeout(readTimeout);
       }
     }
   };
 }