當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。