当前位置: 首页>>代码示例>>Java>>正文


Java RecordedRequest.getPath方法代码示例

本文整理汇总了Java中okhttp3.mockwebserver.RecordedRequest.getPath方法的典型用法代码示例。如果您正苦于以下问题:Java RecordedRequest.getPath方法的具体用法?Java RecordedRequest.getPath怎么用?Java RecordedRequest.getPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在okhttp3.mockwebserver.RecordedRequest的用法示例。


在下文中一共展示了RecordedRequest.getPath方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dispatch

import okhttp3.mockwebserver.RecordedRequest; //导入方法依赖的package包/类
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
    switch (request.getPath()) {
        case "/person/5":
            return new MockResponse().setResponseCode(200)
                    .setBody("{\"name\": \"A\",\"age\": 11}");
        case "/country":
            return new MockResponse().setResponseCode(200)
                    .setBody("{\"name\":\"中国\",\"" +
                            "province\":[{\"name\":\"黑龙江\",\"cities\":{\"city\":[\"哈尔滨\",\"大庆\"]}}," +
                            "{\"name\":\"广东\",\"cities\":{\"city\":[\"广州\",\"深圳\",\"珠海\"]}}," +
                            "{\"name\":\"台湾\",\"cities\":{\"city\":[\"台北\",\"高雄\"]}}," +
                            "{\"name\":\"新疆\",\"cities\":{\"city\":[\"乌鲁木齐\"]}}]}");
        default:
            return new MockResponse().setResponseCode(404);
    }
}
 
开发者ID:ZYRzyr,项目名称:FastJsonConverter,代码行数:18,代码来源:FastJsonConverterFactoryTest.java

示例2: matchesMethodAndPath

import okhttp3.mockwebserver.RecordedRequest; //导入方法依赖的package包/类
private boolean matchesMethodAndPath(RecordedRequest item, Description mismatchDescription) {
    if (!item.getMethod().equalsIgnoreCase(first)) {
        mismatchDescription.appendText("method was ").appendValue(item.getMethod());
        return false;
    }
    String path = item.getPath();
    boolean hasQuery = path.indexOf("?") > 0;
    if (hasQuery) {
        path = path.substring(0, path.indexOf("?"));
    }
    if (!path.equals(second)) {
        mismatchDescription.appendText("path was ").appendValue(path);
        return false;
    }

    return true;
}
 
开发者ID:auth0,项目名称:Guardian.java,代码行数:18,代码来源:RecordedRequestMatcher.java

示例3: matchesQueryParameter

import okhttp3.mockwebserver.RecordedRequest; //导入方法依赖的package包/类
private boolean matchesQueryParameter(RecordedRequest item, Description mismatchDescription) {
    String path = item.getPath();
    boolean hasQuery = path.indexOf("?") > 0;
    if (!hasQuery) {
        mismatchDescription.appendText(" query was empty");
        return false;
    }

    String query = path.substring(path.indexOf("?") + 1, path.length());
    String[] parameters = query.split("&");
    for (String p : parameters) {
        if (p.equals(String.format("%s=%s", first, second))) {
            return true;
        }
    }
    mismatchDescription.appendValueList("Query parameters were {", ", ", "}.", parameters);
    return false;
}
 
开发者ID:auth0,项目名称:Guardian.java,代码行数:19,代码来源:RecordedRequestMatcher.java

示例4: assertPathsHaveBeenRequested

import okhttp3.mockwebserver.RecordedRequest; //导入方法依赖的package包/类
private void assertPathsHaveBeenRequested(MockWebServer webServer, String... paths) throws InterruptedException {
    final List<String> expectedPaths = new ArrayList<>(paths.length);
    Collections.addAll(expectedPaths, paths);

    RecordedRequest request;

    while ((request = webServer.takeRequest(waitingTime, TimeUnit.MILLISECONDS)) != null) {
        if (!expectedPaths.remove(request.getPath())) {
            throw new AssertionError("Unknown path requested: " + request.getPath());
        }
    }

    if (!expectedPaths.isEmpty()) {
        throw new AssertionError("Expected paths not requested: " + expectedPaths);
    }
}
 
开发者ID:mozilla-mobile,项目名称:firefox-tv,代码行数:17,代码来源:WebViewDataTest.java

示例5: dispatch

import okhttp3.mockwebserver.RecordedRequest; //导入方法依赖的package包/类
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
    String path = request.getPath();

    JsonObject body = gson.fromJson(new InputStreamReader(request.getBody().inputStream()), JsonObject.class);
    JsonObject response = new JsonObject();

    if (path.equals("/authenticate")) {
        return this.authenticate(request, body);
    }

    if (path.equals("/refresh")) {
        return this.refresh(request, body);
    }

    if (path.equals("/validate")) {
        return this.validate(request, body);
    }

    if (path.equals("/signout")) {
        return this.signout(request, body);
    }

    if (path.equals("/invalidate")) {
        return this.invalidate(request, body);
    }

    response.addProperty("error", "Not Found");
    response.addProperty("errorMessage", "The server has not found anything matching the request URI");

    return new MockResponse()
            .setResponseCode(404)
            .setBody(gson.toJson(response));
}
 
开发者ID:MPLauncher,项目名称:Yggdrasil,代码行数:35,代码来源:YggdrasilDispatcher.java

示例6: getResponse

import okhttp3.mockwebserver.RecordedRequest; //导入方法依赖的package包/类
private MockResponse getResponse(RecordedRequest request) {
	String path = request.getPath();
	if (!request.getPath().startsWith("/")) path = "/" + path;

	callTimes.add(System.currentTimeMillis());

	HttpUrl url = HttpUrl.parse("http://localhost" + path);

	String apiKey = url.queryParameter("api_key");
	if (!Objects.equals(Constants.API_KEY, apiKey)) {
		return new MockResponse().setBody("\n" +
			"<html>\n" +
			"<head><title>403 Forbidden</title></head>\n" +
			"<body bgcolor=\"white\">\n" +
			"<center><h1>403 Forbidden</h1></center>\n" +
			"<hr><center>openresty/1.9.3.2</center>\n" +
			"</body>\n" +
			"</html>\n" +
			"<!-- a padding to disable MSIE and Chrome friendly error page -->\n" +
			"<!-- a padding to disable MSIE and Chrome friendly error page -->\n" +
			"<!-- a padding to disable MSIE and Chrome friendly error page -->\n" +
			"<!-- a padding to disable MSIE and Chrome friendly error page -->\n" +
			"<!-- a padding to disable MSIE and Chrome friendly error page -->\n" +
			"<!-- a padding to disable MSIE and Chrome friendly error page -->\n")
			.setResponseCode(403);
	}

	path = getPath(request, url);
	InputStream jsonStream = getClass().getClassLoader().getResourceAsStream(path);

	if (jsonStream == null) {
		return null;
	}

	Uninterruptibles.sleepUninterruptibly(delay, TimeUnit.MILLISECONDS);

	return Constants.GSON.fromJson(new InputStreamReader(jsonStream), MockResponse.class);
}
 
开发者ID:LogicalOverflow,项目名称:java-champion-gg-wrapper,代码行数:39,代码来源:MockDispatcher.java

示例7: getScenario

import okhttp3.mockwebserver.RecordedRequest; //导入方法依赖的package包/类
private String getScenario(RecordedRequest request) {
    String scenario = "";

    String path = request.getPath();
    String requestedMethod = request.getMethod().toLowerCase(Locale.US);

    scenario += requestedMethod + path.replace("/", "_") + ".json";
    return scenario;
}
 
开发者ID:ragdroid,项目名称:mockstar,代码行数:10,代码来源:LocalResponseDispatcher.java

示例8: getUrl

import okhttp3.mockwebserver.RecordedRequest; //导入方法依赖的package包/类
private HttpUrl getUrl(RecordedRequest request) {
	String path = request.getPath();
	if (!request.getPath().startsWith("/")) path = "/" + path;
	return HttpUrl.parse("http://localhost" + path);
}
 
开发者ID:LogicalOverflow,项目名称:java-champion-gg-wrapper,代码行数:6,代码来源:MockDispatcher.java

示例9: test_calculate_whatif

import okhttp3.mockwebserver.RecordedRequest; //导入方法依赖的package包/类
/**
 * This method handles two concurrent HTTP requests, and has to define the {@link MockWebServer} instance in a different way.
 * For any what-if scenario request, the sequence of HTTP requests should look like this:
 * * POST - /margin/v1/ccps/lch/calculations - base portfolios
 * * POST - /margin/v1/ccps/lch/calculations - delta portfolios
 * * (for each portfolio) GET - /margin/v1/ccps/lch/calculations/[calcID] - until the status is COMPLETED.
 * * (for each portfolio) DELETE - /margin/v1/ccps/lch/calculations/[calcID]
 */
public void test_calculate_whatif() throws Exception {
  Dispatcher webServerDispatcher = new Dispatcher() {
    boolean firstRequestSubmitted = false;
    boolean firstCalcRequested = false;
    boolean secondCalcRequested = false;

    @Override
    public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
      String requestPath = request.getPath();
      if (request.getMethod().equals("POST") && requestPath.equals("/margin/v3/ccps/lch/calculations")) {
        if (!firstRequestSubmitted) {
          firstRequestSubmitted = true;
          return new MockResponse()
              .setResponseCode(202)
              .setHeader("Location", server.url("/ccps/lch/calculations/789"))
              .setBody(RESPONSE_CALC_POST);
        } else {
          return new MockResponse()
              .setResponseCode(202)
              .setHeader("Location", server.url("/ccps/lch/calculations/790"))
              .setBody(RESPONSE_CALC_POST);
        }
      } else if (request.getMethod().equals("GET") && requestPath.equals("/margin/v3/ccps/lch/calculations/789")) {
        if (!firstCalcRequested) {
          firstCalcRequested = true;
          return new MockResponse()
              .setHeader("Content-Type", "application/json")
              .setBody(RESPONSE_CALC_GET_PENDING);
        } else {
          return new MockResponse()
              .setHeader("Content-Type", "application/json")
              .setBody(RESPONSE_CALC_GET_COMPLETE);
        }
      } else if (request.getMethod().equals("GET") && requestPath.equals("/margin/v3/ccps/lch/calculations/790")) {
        if (!secondCalcRequested) {
          secondCalcRequested = true;
          return new MockResponse()
              .setHeader("Content-Type", "application/json")
              .setBody(RESPONSE_CALC_GET_PENDING);
        } else {
          return new MockResponse()
              .setHeader("Content-Type", "application/json")
              .setBody(RESPONSE_CALC_WHATIF_GET_COMPLETE);
        }
      } else if (request.getMethod().equals("DELETE")) {
        return new MockResponse()
            .setBody(RESPONSE_DELETE);
      } else {

        return new MockResponse().setResponseCode(404);
      }
    }
  };
  server.setDispatcher(webServerDispatcher);

  // call server
  ServiceInvoker invoker = createInvoker();
  MarginClient client = MarginClient.of(invoker);

  PortfolioDataFile lchPortfolioFile = PortfolioDataFile.of(Paths.get(
      "src/test/resources/lch-trades.txt"));
  MarginCalcRequest.of(VAL_DATE, "GBP", Collections.singletonList(lchPortfolioFile));

  MarginWhatIfCalcResult result = client.calculateWhatIf(Ccp.LCH, REQUEST, Collections.singletonList(lchPortfolioFile)); //Using the same portfolio for delta as well
  assertEquals(result.getStatus(), MarginCalcResultStatus.COMPLETED);
  assertEquals(result.getType(), MarginCalcRequestType.STANDARD);
  assertEquals(result.getValuationDate(), VAL_DATE);

  assertEquals(result.getBaseSummary().getMargin(), 125.0); //Hard coded result, not relevant for portfolio
  assertEquals(result.getCombinedSummary().getMargin(), 135.0); //Hard coded result, not relevant for portfolio
  assertEquals(result.getDeltaSummary().getMargin(), 260.0);
}
 
开发者ID:OpenGamma,项目名称:JavaSDK,代码行数:81,代码来源:MarginClientTest.java


注:本文中的okhttp3.mockwebserver.RecordedRequest.getPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。