• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MockLowLevelHttpRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.api.client.testing.http.MockLowLevelHttpRequest的典型用法代码示例。如果您正苦于以下问题:Java MockLowLevelHttpRequest类的具体用法?Java MockLowLevelHttpRequest怎么用?Java MockLowLevelHttpRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MockLowLevelHttpRequest类属于com.google.api.client.testing.http包,在下文中一共展示了MockLowLevelHttpRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: buildRequest

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
    return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
            String rawPath = url;
            Map<String, String> params = new HashMap<>();

            int pathEndPos = url.indexOf('?');
            if (pathEndPos != -1) {
                rawPath = url.substring(0, pathEndPos);
                RestUtils.decodeQueryString(url, pathEndPos + 1, params);
            }

            Handler handler = handlers.retrieve(method + " " + rawPath, params);
            if (handler != null) {
                return handler.execute(rawPath, params, this);
            }
            return newMockError(RestStatus.INTERNAL_SERVER_ERROR, "Unable to handle request [method=" + method + ", url=" + url + "]");
        }
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:MockHttpTransport.java


示例2: configureMock

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
protected static HttpTransport configureMock() {
    return new MockHttpTransport() {
        @Override
        public LowLevelHttpRequest buildRequest(String method, final String url) throws IOException {
            return new MockLowLevelHttpRequest() {
                @Override
                public LowLevelHttpResponse execute() throws IOException {
                    MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
                    response.setStatusCode(200);
                    response.setContentType(Json.MEDIA_TYPE);
                    if (url.startsWith(GCE_METADATA_URL)) {
                        logger.info("--> Simulate GCE Auth/Metadata response for [{}]", url);
                        response.setContent(readGoogleInternalJsonResponse(url));
                    } else {
                        logger.info("--> Simulate GCE API response for [{}]", url);
                        response.setContent(readGoogleApiJsonResponse(url));
                    }

                    return response;
                }
            };
        }
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:GceMockUtils.java


示例3: buildRequest

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
  callCount ++;

  if (!HttpMethods.GET.equals(method) || !expectedUrl.equals(url)) {
    // Throw RuntimeException to fail the test.
    throw new RuntimeException();
  }

  return new MockLowLevelHttpRequest() {
    @Override
    public LowLevelHttpResponse execute() throws IOException {
      MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
      response.setStatusCode(HttpStatusCodes.STATUS_CODE_OK);
      response.setContentType(Json.MEDIA_TYPE);
      response.setContent(jsonResponse);
      return response;
    }
  };
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:21,代码来源:DefautKeyUriSupplierTest.java


示例4: buildRequest

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
  return new MockLowLevelHttpRequest() {
    @Override
    public LowLevelHttpResponse execute() throws IOException {
      if (ioException != null) {
        throw ioException;
      }
      MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
      response.setStatusCode(HttpStatus.SC_ACCEPTED);
      response.setContentType(Json.MEDIA_TYPE);
      response.setContent(content);
      return response;
    }
  };
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:17,代码来源:DefaultJwksSupplierTest.java


示例5: mockClient

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
/**
 * Return a Client that is mocked to return the given HTTP response.
 *
 * @param httpResponse The full HTTP response data
 * @return The Client instance
 */
public Client mockClient(final String httpResponse) {
  Client client = new Client();

  HttpTransport transport = new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          return mockResponse(response, httpResponse);
        }
      };
    }
  };

  client.setTransport(transport);

  return client;
}
 
开发者ID:dnsimple,项目名称:dnsimple-java,代码行数:27,代码来源:DnsimpleTestBase.java


示例6: constructHttpRequest

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
private HttpRequest constructHttpRequest(final String content) throws IOException {
  HttpTransport transport = new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse result = new MockLowLevelHttpResponse();
          result.setContentType("application/json");
          result.setContent(content);
          return result;
        }
      };
    }
  };
  return transport.createRequestFactory().buildGetRequest(new GenericUrl("https://google.com"))
      .setParser(new JsonObjectParser(new JacksonFactory()));
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:19,代码来源:GoogleAuthTest.java


示例7: getContent

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Override
protected byte[] getContent(String method, String url, MockLowLevelHttpRequest request)
    throws IOException {
  if (url.equals("https://api.github.com/repos/google/example/issues/" + prNumber)) {
    return mockIssue(Integer.toString(prNumber), defaultPresentLabels).getBytes();
  } else if (url.startsWith(
      "https://api.github.com/repos/google/example/pulls/" + prNumber)) {
    return ("{\n"
        + "  \"id\": 1,\n"
        + "  \"number\": " + prNumber + ",\n"
        + "  \"state\": \"open\",\n"
        + "  \"title\": \"test summary\",\n"
        + "  \"body\": \"test summary\n\nMore text\",\n"
        + "  \"head\": {\n"
        + "    \"label\": \"googletestuser:example-branch\",\n"
        + "    \"ref\": \"example-branch\"\n"
        + "   },\n"
        + "  \"base\": {\n"
        + "    \"label\": \"google:master\",\n"
        + "    \"ref\": \"master\"\n"
        + "   }\n"
        + "}").getBytes(UTF_8);
  }
  fail(method + " " + url);
  throw new IllegalStateException();
}
 
开发者ID:google,项目名称:copybara,代码行数:27,代码来源:GithubPrOriginTest.java


示例8: setUp

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);

  // A mock transport that lets us mock the API responses.
  MockHttpTransport transport =
      new MockHttpTransport.Builder()
          .setLowLevelHttpRequest(
              new MockLowLevelHttpRequest() {
                @Override
                public LowLevelHttpResponse execute() throws IOException {
                  return response;
                }
              })
          .build();

  // A sample BigQuery API client that uses default JsonFactory and RetryHttpInitializer.
  bigquery =
      new Bigquery.Builder(
              transport, Transport.getJsonFactory(), new RetryHttpRequestInitializer())
          .build();
}
 
开发者ID:apache,项目名称:beam,代码行数:23,代码来源:BigQueryServicesImplTest.java


示例9: createMockTransport

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
private MockHttpTransport createMockTransport (final ByteSource iirdeaResponse) {
  return new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      mockRequest = new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          response.setContentType(PLAIN_TEXT_UTF_8.toString());
          response.setContent(iirdeaResponse.read());
          return response;
        }
      };
      mockRequest.setUrl(url);
      return mockRequest;
    }
  };
}
 
开发者ID:google,项目名称:nomulus,代码行数:20,代码来源:IcannHttpReporterTest.java


示例10: makeResponseException

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
/** Returns a valid GoogleJsonResponseException for the given status code and error message.  */
private GoogleJsonResponseException makeResponseException(
    final int statusCode,
    final String message) throws Exception {
  HttpTransport transport = new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(statusCode);
          response.setContentType(Json.MEDIA_TYPE);
          response.setContent(String.format(
              "{\"error\":{\"code\":%d,\"message\":\"%s\",\"domain\":\"global\","
              + "\"reason\":\"duplicate\"}}",
              statusCode,
              message));
          return response;
        }};
    }};
  HttpRequest request = transport.createRequestFactory()
      .buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL)
      .setThrowExceptionOnExecuteError(false);
  return GoogleJsonResponseException.from(new JacksonFactory(), request.execute());
}
 
开发者ID:google,项目名称:nomulus,代码行数:27,代码来源:DirectoryGroupsConnectionTest.java


示例11: sendFirebaseMessage_create

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Test
public void sendFirebaseMessage_create() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          return response;
        }
      };
    }
  });
  FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;

  firebaseChannel.sendFirebaseMessage("my_key", new Game());

  verify(mockHttpTransport, times(1)).buildRequest(
      "PATCH", FIREBASE_DB_URL + "/channels/my_key.json");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:25,代码来源:FirebaseChannelTest.java


示例12: sendFirebaseMessage_delete

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Test
public void sendFirebaseMessage_delete() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          return response;
        }
      };
    }
  });
  FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;

  firebaseChannel.sendFirebaseMessage("my_key", null);

  verify(mockHttpTransport, times(1)).buildRequest(
      "DELETE", FIREBASE_DB_URL + "/channels/my_key.json");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:25,代码来源:FirebaseChannelTest.java


示例13: firebasePut

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Test
public void firebasePut() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          return response;
        }
      };
    }
  });
  FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;
  Game game = new Game();

  firebaseChannel.firebasePut(FIREBASE_DB_URL + "/my/path", game);

  verify(mockHttpTransport, times(1)).buildRequest("PUT", FIREBASE_DB_URL + "/my/path");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:25,代码来源:FirebaseChannelTest.java


示例14: firebasePatch

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Test
public void firebasePatch() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          return response;
        }
      };
    }
  });
  FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;
  Game game = new Game();

  firebaseChannel.firebasePatch(FIREBASE_DB_URL + "/my/path", game);

  verify(mockHttpTransport, times(1)).buildRequest("PATCH", FIREBASE_DB_URL + "/my/path");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:25,代码来源:FirebaseChannelTest.java


示例15: firebasePost

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Test
public void firebasePost() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          return response;
        }
      };
    }
  });
  FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;
  Game game = new Game();

  firebaseChannel.firebasePost(FIREBASE_DB_URL + "/my/path", game);

  verify(mockHttpTransport, times(1)).buildRequest("POST", FIREBASE_DB_URL + "/my/path");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:25,代码来源:FirebaseChannelTest.java


示例16: firebaseGet

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Test
public void firebaseGet() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          return response;
        }
      };
    }
  });
  FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;

  firebaseChannel.firebaseGet(FIREBASE_DB_URL + "/my/path");

  verify(mockHttpTransport, times(1)).buildRequest("GET", FIREBASE_DB_URL + "/my/path");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:24,代码来源:FirebaseChannelTest.java


示例17: firebaseDelete

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Test
public void firebaseDelete() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          return response;
        }
      };
    }
  });
  FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;

  firebaseChannel.firebaseDelete(FIREBASE_DB_URL + "/my/path");

  verify(mockHttpTransport, times(1)).buildRequest("DELETE", FIREBASE_DB_URL + "/my/path");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:24,代码来源:FirebaseChannelTest.java


示例18: firebaseGet

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Test
public void firebaseGet() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport =
      spy(
          new MockHttpTransport() {
            @Override
            public LowLevelHttpRequest buildRequest(String method, String url)
                throws IOException {
              return new MockLowLevelHttpRequest() {
                @Override
                public LowLevelHttpResponse execute() throws IOException {
                  MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
                  response.setStatusCode(200);
                  return response;
                }
              };
            }
          });
  FirebaseChannel.getInstance().httpTransport = mockHttpTransport;

  firebaseChannel.firebaseGet(FIREBASE_DB_URL + "/my/path");

  verify(mockHttpTransport, times(1)).buildRequest("GET", FIREBASE_DB_URL + "/my/path");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:27,代码来源:FirebaseChannelTest.java


示例19: firebaseDelete

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Test
public void firebaseDelete() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport =
      spy(
          new MockHttpTransport() {
            @Override
            public LowLevelHttpRequest buildRequest(String method, String url)
                throws IOException {
              return new MockLowLevelHttpRequest() {
                @Override
                public LowLevelHttpResponse execute() throws IOException {
                  MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
                  response.setStatusCode(200);
                  return response;
                }
              };
            }
          });
  FirebaseChannel.getInstance().httpTransport = mockHttpTransport;

  firebaseChannel.firebaseDelete(FIREBASE_DB_URL + "/my/path");

  verify(mockHttpTransport, times(1)).buildRequest("DELETE", FIREBASE_DB_URL + "/my/path");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:27,代码来源:FirebaseChannelTest.java


示例20: setUp

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Before public void setUp() throws Exception {
  // Mock out the vision service for unit tests.
  JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
  HttpTransport transport = new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          response.setContentType(Json.MEDIA_TYPE);
          response.setContent("{\"responses\": [{\"textAnnotations\": []}]}");
          return response;
        }
      };
    }
  };
  Vision vision = new Vision(transport, jsonFactory, null);

  appUnderTest = new TextApp(vision, null /* index */);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:23,代码来源:TextAppTest.java



注:本文中的com.google.api.client.testing.http.MockLowLevelHttpRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java GetNewApplicationRequest类代码示例发布时间:2022-05-21
下一篇:
Java BmobUpdateAgent类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap